Class: Anypost::Client
- Inherits:
-
Object
- Object
- Anypost::Client
- Defined in:
- lib/anypost/client.rb
Overview
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.anypost.com/v1"- DEFAULT_TIMEOUT =
30- DEFAULT_MAX_RETRIES =
2
Instance Attribute Summary collapse
-
#api_keys ⇒ Resources::ApiKeys
readonly
API-key operations (‘/api-keys`).
-
#domains ⇒ Resources::Domains
readonly
Sending-domain operations (‘/domains`).
-
#email ⇒ Resources::Email
readonly
Send operations (‘/email`, `/email/batch`).
-
#events ⇒ Resources::Events
readonly
Read access to the event stream (‘/events`).
-
#suppressions ⇒ Resources::Suppressions
readonly
Suppression-list operations (‘/suppressions`).
-
#templates ⇒ Resources::Templates
readonly
Template operations, including draft/publish.
-
#webhooks ⇒ Resources::Webhooks
readonly
Webhook operations, including test and rotation.
Instance Method Summary collapse
-
#initialize(api_key = nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, default_headers: {}, connection: nil, sleeper: nil, jitter: nil) ⇒ Client
constructor
A new instance of Client.
-
#whoami ⇒ Object
Identify the team and permission level behind the current API key.
Constructor Details
#initialize(api_key = nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, default_headers: {}, connection: nil, sleeper: nil, jitter: nil) ⇒ Client
Returns a new instance of Client.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/anypost/client.rb', line 37 def initialize(api_key = nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES, default_headers: {}, connection: nil, sleeper: nil, jitter: nil) key = api_key key = ENV["ANYPOST_API_KEY"] if key.nil? || key.empty? if key.nil? || key.empty? raise ArgumentError, "An Anypost API key is required. Pass it to the constructor or set ANYPOST_API_KEY." end http = HttpClient.new( api_key: key, base_url: base_url, timeout: timeout, max_retries: max_retries, default_headers: default_headers, connection: connection, sleeper: sleeper, jitter: jitter ) @email = Resources::Email.new(http) @domains = Resources::Domains.new(http) @api_keys = Resources::ApiKeys.new(http) @templates = Resources::Templates.new(http) @suppressions = Resources::Suppressions.new(http) @webhooks = Resources::Webhooks.new(http) @events = Resources::Events.new(http) @identity = Resources::Identity.new(http) end |
Instance Attribute Details
#api_keys ⇒ Resources::ApiKeys (readonly)
Returns API-key operations (‘/api-keys`).
26 27 28 |
# File 'lib/anypost/client.rb', line 26 def api_keys @api_keys end |
#domains ⇒ Resources::Domains (readonly)
Returns sending-domain operations (‘/domains`).
24 25 26 |
# File 'lib/anypost/client.rb', line 24 def domains @domains end |
#email ⇒ Resources::Email (readonly)
Returns send operations (‘/email`, `/email/batch`).
22 23 24 |
# File 'lib/anypost/client.rb', line 22 def email @email end |
#events ⇒ Resources::Events (readonly)
Returns read access to the event stream (‘/events`).
34 35 36 |
# File 'lib/anypost/client.rb', line 34 def events @events end |
#suppressions ⇒ Resources::Suppressions (readonly)
Returns suppression-list operations (‘/suppressions`).
30 31 32 |
# File 'lib/anypost/client.rb', line 30 def suppressions @suppressions end |
#templates ⇒ Resources::Templates (readonly)
Returns template operations, including draft/publish.
28 29 30 |
# File 'lib/anypost/client.rb', line 28 def templates @templates end |
#webhooks ⇒ Resources::Webhooks (readonly)
Returns webhook operations, including test and rotation.
32 33 34 |
# File 'lib/anypost/client.rb', line 32 def webhooks @webhooks end |
Instance Method Details
#whoami ⇒ Object
Identify the team and permission level behind the current API key.
68 69 70 |
# File 'lib/anypost/client.rb', line 68 def whoami @identity.whoami end |