Class: Moonbase::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/moonbase/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(api_key: ENV["MOONBASE_API_KEY"], base_url: ENV["MOONBASE_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client

Creates and returns a new client for interacting with the API.

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: ENV["MOONBASE_API_KEY"])

    Your Moonbase API key. Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: ENV["MOONBASE_BASE_URL"])

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/moonbase/client.rb', line 142

def initialize(
  api_key: ENV["MOONBASE_API_KEY"],
  base_url: ENV["MOONBASE_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
)
  base_url ||= "https://api.moonbase.ai/v0"

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"MOONBASE_API_KEY\"")
  end

  headers = {}
  custom_headers_env = ENV["MOONBASE_CUSTOM_HEADERS"]
  unless custom_headers_env.nil?
    parsed = {}
    custom_headers_env.split("\n").each do |line|
      colon = line.index(":")
      unless colon.nil?
        parsed[line[0...colon].strip] = line[(colon + 1)..].strip
      end
    end
    headers = parsed.merge(headers)
  end

  @api_key = api_key.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay,
    headers: headers
  )

  @funnels = Moonbase::Resources::Funnels.new(client: self)
  @collections = Moonbase::Resources::Collections.new(client: self)
  @views = Moonbase::Resources::Views.new(client: self)
  @inboxes = Moonbase::Resources::Inboxes.new(client: self)
  @inbox_conversations = Moonbase::Resources::InboxConversations.new(client: self)
  @inbox_messages = Moonbase::Resources::InboxMessages.new(client: self)
  @tagsets = Moonbase::Resources::Tagsets.new(client: self)
  @programs = Moonbase::Resources::Programs.new(client: self)
  @program_templates = Moonbase::Resources::ProgramTemplates.new(client: self)
  @program_messages = Moonbase::Resources::ProgramMessages.new(client: self)
  @forms = Moonbase::Resources::Forms.new(client: self)
  @unsubscribes = Moonbase::Resources::Unsubscribes.new(client: self)
  @activities = Moonbase::Resources::Activities.new(client: self)
  @calls = Moonbase::Resources::Calls.new(client: self)
  @files = Moonbase::Resources::Files.new(client: self)
  @meetings = Moonbase::Resources::Meetings.new(client: self)
  @notes = Moonbase::Resources::Notes.new(client: self)
  @webhook_endpoints = Moonbase::Resources::WebhookEndpoints.new(client: self)
  @agent_settings = Moonbase::Resources::AgentSettings.new(client: self)
end

Instance Attribute Details

#activitiesMoonbase::Resources::Activities (readonly)

View activities and capture calls



72
73
74
# File 'lib/moonbase/client.rb', line 72

def activities
  @activities
end

#agent_settingsMoonbase::Resources::AgentSettings (readonly)



94
95
96
# File 'lib/moonbase/client.rb', line 94

def agent_settings
  @agent_settings
end

#api_keyString (readonly)

Your Moonbase API key.

Returns:

  • (String)


20
21
22
# File 'lib/moonbase/client.rb', line 20

def api_key
  @api_key
end

#callsMoonbase::Resources::Calls (readonly)

View activities and capture calls



76
77
78
# File 'lib/moonbase/client.rb', line 76

def calls
  @calls
end

#collectionsMoonbase::Resources::Collections (readonly)

Manage your collections and items



28
29
30
# File 'lib/moonbase/client.rb', line 28

def collections
  @collections
end

#filesMoonbase::Resources::Files (readonly)

Manage your meetings, files, and notes



80
81
82
# File 'lib/moonbase/client.rb', line 80

def files
  @files
end

#formsMoonbase::Resources::Forms (readonly)

Manage your marketing campaigns and forms



64
65
66
# File 'lib/moonbase/client.rb', line 64

def forms
  @forms
end

#funnelsMoonbase::Resources::Funnels (readonly)

Manage your collections and items



24
25
26
# File 'lib/moonbase/client.rb', line 24

def funnels
  @funnels
end

#inbox_conversationsMoonbase::Resources::InboxConversations (readonly)

Manage your inboxes, conversations, and messages



40
41
42
# File 'lib/moonbase/client.rb', line 40

def inbox_conversations
  @inbox_conversations
end

#inbox_messagesMoonbase::Resources::InboxMessages (readonly)

Manage your inboxes, conversations, and messages



44
45
46
# File 'lib/moonbase/client.rb', line 44

def inbox_messages
  @inbox_messages
end

#inboxesMoonbase::Resources::Inboxes (readonly)

Manage your inboxes, conversations, and messages



36
37
38
# File 'lib/moonbase/client.rb', line 36

def inboxes
  @inboxes
end

#meetingsMoonbase::Resources::Meetings (readonly)

Manage your meetings, files, and notes



84
85
86
# File 'lib/moonbase/client.rb', line 84

def meetings
  @meetings
end

#notesMoonbase::Resources::Notes (readonly)

Manage your meetings, files, and notes



88
89
90
# File 'lib/moonbase/client.rb', line 88

def notes
  @notes
end

#program_messagesMoonbase::Resources::ProgramMessages (readonly)

Manage your marketing campaigns and forms



60
61
62
# File 'lib/moonbase/client.rb', line 60

def program_messages
  @program_messages
end

#program_templatesMoonbase::Resources::ProgramTemplates (readonly)

Manage your marketing campaigns and forms



56
57
58
# File 'lib/moonbase/client.rb', line 56

def program_templates
  @program_templates
end

#programsMoonbase::Resources::Programs (readonly)

Manage your marketing campaigns and forms



52
53
54
# File 'lib/moonbase/client.rb', line 52

def programs
  @programs
end

#tagsetsMoonbase::Resources::Tagsets (readonly)

Manage your meetings, files, and notes



48
49
50
# File 'lib/moonbase/client.rb', line 48

def tagsets
  @tagsets
end

#unsubscribesMoonbase::Resources::Unsubscribes (readonly)

Manage your marketing campaigns and forms



68
69
70
# File 'lib/moonbase/client.rb', line 68

def unsubscribes
  @unsubscribes
end

#viewsMoonbase::Resources::Views (readonly)

Manage your collections and items



32
33
34
# File 'lib/moonbase/client.rb', line 32

def views
  @views
end

#webhook_endpointsMoonbase::Resources::WebhookEndpoints (readonly)



91
92
93
# File 'lib/moonbase/client.rb', line 91

def webhook_endpoints
  @webhook_endpoints
end

Instance Method Details

#search(query:, request_options: {}) ⇒ Moonbase::Models::SearchResponse

Returns items and files that match the search query.

Parameters:

  • query (String)

    The search text to match against items and files.

  • request_options (Moonbase::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/moonbase/client.rb', line 107

def search(params)
  parsed, options = Moonbase::ClientSearchParams.dump_request(params)
  query = Moonbase::Internal::Util.encode_query_params(parsed)
  request(
    method: :post,
    path: "search",
    query: query,
    model: Moonbase::Models::SearchResponse,
    options: options
  )
end