Class: Zavudev::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/zavudev/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["ZAVUDEV_API_KEY"], base_url: ENV["ZAVUDEV_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["ZAVUDEV_API_KEY"])

    Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: ENV["ZAVUDEV_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)


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/zavudev/client.rb', line 71

def initialize(
  api_key: ENV["ZAVUDEV_API_KEY"],
  base_url: ENV["ZAVUDEV_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.zavu.dev"

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"ZAVUDEV_API_KEY\"")
  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
  )

  @messages = Zavudev::Resources::Messages.new(client: self)
  @templates = Zavudev::Resources::Templates.new(client: self)
  @senders = Zavudev::Resources::Senders.new(client: self)
  @contacts = Zavudev::Resources::Contacts.new(client: self)
  @broadcasts = Zavudev::Resources::Broadcasts.new(client: self)
  @introspect = Zavudev::Resources::Introspect.new(client: self)
  @phone_numbers = Zavudev::Resources::PhoneNumbers.new(client: self)
  @addresses = Zavudev::Resources::Addresses.new(client: self)
  @regulatory_documents = Zavudev::Resources::RegulatoryDocuments.new(client: self)
end

Instance Attribute Details

#addressesZavudev::Resources::Addresses (readonly)



43
44
45
# File 'lib/zavudev/client.rb', line 43

def addresses
  @addresses
end

#api_keyString (readonly)

Returns:

  • (String)


19
20
21
# File 'lib/zavudev/client.rb', line 19

def api_key
  @api_key
end

#broadcastsZavudev::Resources::Broadcasts (readonly)



34
35
36
# File 'lib/zavudev/client.rb', line 34

def broadcasts
  @broadcasts
end

#contactsZavudev::Resources::Contacts (readonly)



31
32
33
# File 'lib/zavudev/client.rb', line 31

def contacts
  @contacts
end

#introspectZavudev::Resources::Introspect (readonly)



37
38
39
# File 'lib/zavudev/client.rb', line 37

def introspect
  @introspect
end

#messagesZavudev::Resources::Messages (readonly)



22
23
24
# File 'lib/zavudev/client.rb', line 22

def messages
  @messages
end

#phone_numbersZavudev::Resources::PhoneNumbers (readonly)



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

def phone_numbers
  @phone_numbers
end

#regulatory_documentsZavudev::Resources::RegulatoryDocuments (readonly)



46
47
48
# File 'lib/zavudev/client.rb', line 46

def regulatory_documents
  @regulatory_documents
end

#sendersZavudev::Resources::Senders (readonly)



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

def senders
  @senders
end

#templatesZavudev::Resources::Templates (readonly)



25
26
27
# File 'lib/zavudev/client.rb', line 25

def templates
  @templates
end