Class: Unitpost::Client
- Inherits:
-
Object
- Object
- Unitpost::Client
- Defined in:
- lib/unitpost/client.rb
Overview
The Unitpost client. Construct once, reuse everywhere.
require "unitpost"
unitpost = Unitpost::Client.new # reads UNITPOST_API_KEY
result = unitpost.email.send(from: ..., to: ..., subject: ..., html: ...)
if result.error
warn "#{result.error.code}: #{result.error.message}"
else
puts result.data["id"]
end
Instance Attribute Summary collapse
-
#api_keys ⇒ Object
readonly
Returns the value of attribute api_keys.
-
#brand_kits ⇒ Object
readonly
Returns the value of attribute brand_kits.
-
#contact_fields ⇒ Object
readonly
Returns the value of attribute contact_fields.
-
#contacts ⇒ Object
readonly
Returns the value of attribute contacts.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
-
#suppressions ⇒ Object
readonly
Returns the value of attribute suppressions.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
-
#webhooks ⇒ Object
readonly
Returns the value of attribute webhooks.
Instance Method Summary collapse
-
#initialize(api_key: nil, base_url: nil, timeout: 30, headers: {}, adapter: nil, stubs: nil, max_retries: 2, retry_base_delay: 0.5, max_retry_delay: 20.0, sleeper: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key: nil, base_url: nil, timeout: 30, headers: {}, adapter: nil, stubs: nil, max_retries: 2, retry_base_delay: 0.5, max_retry_delay: 20.0, sleeper: nil) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/unitpost/client.rb', line 22 def initialize(api_key: nil, base_url: nil, timeout: 30, headers: {}, adapter: nil, stubs: nil, max_retries: 2, retry_base_delay: 0.5, max_retry_delay: 20.0, sleeper: nil) http = HttpClient.new( api_key: api_key, base_url: base_url, timeout: timeout, headers: headers, adapter: adapter, stubs: stubs, max_retries: max_retries, retry_base_delay: retry_base_delay, max_retry_delay: max_retry_delay, sleeper: sleeper ) @email = Resources::Email.new(http) @contacts = Resources::Contacts.new(http) @contact_fields = Resources::ContactFields.new(http) @segments = Resources::Segments.new(http) @brand_kits = Resources::BrandKits.new(http) @webhooks = Resources::Webhooks.new(http) @api_keys = Resources::ApiKeys.new(http) @suppressions = Resources::Suppressions.new(http) # NOTE (pre-launch): `events` is intentionally absent while the # custom-events surface is behind the launch gate. @usage = Resources::Usage.new(http) end |
Instance Attribute Details
#api_keys ⇒ Object (readonly)
Returns the value of attribute api_keys.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def api_keys @api_keys end |
#brand_kits ⇒ Object (readonly)
Returns the value of attribute brand_kits.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def brand_kits @brand_kits end |
#contact_fields ⇒ Object (readonly)
Returns the value of attribute contact_fields.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def contact_fields @contact_fields end |
#contacts ⇒ Object (readonly)
Returns the value of attribute contacts.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def contacts @contacts end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def email @email end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def segments @segments end |
#suppressions ⇒ Object (readonly)
Returns the value of attribute suppressions.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def suppressions @suppressions end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def usage @usage end |
#webhooks ⇒ Object (readonly)
Returns the value of attribute webhooks.
18 19 20 |
# File 'lib/unitpost/client.rb', line 18 def webhooks @webhooks end |