Class: Unitpost::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_keysObject (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_kitsObject (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_fieldsObject (readonly)

Returns the value of attribute contact_fields.



18
19
20
# File 'lib/unitpost/client.rb', line 18

def contact_fields
  @contact_fields
end

#contactsObject (readonly)

Returns the value of attribute contacts.



18
19
20
# File 'lib/unitpost/client.rb', line 18

def contacts
  @contacts
end

#emailObject (readonly)

Returns the value of attribute email.



18
19
20
# File 'lib/unitpost/client.rb', line 18

def email
  @email
end

#segmentsObject (readonly)

Returns the value of attribute segments.



18
19
20
# File 'lib/unitpost/client.rb', line 18

def segments
  @segments
end

#suppressionsObject (readonly)

Returns the value of attribute suppressions.



18
19
20
# File 'lib/unitpost/client.rb', line 18

def suppressions
  @suppressions
end

#usageObject (readonly)

Returns the value of attribute usage.



18
19
20
# File 'lib/unitpost/client.rb', line 18

def usage
  @usage
end

#webhooksObject (readonly)

Returns the value of attribute webhooks.



18
19
20
# File 'lib/unitpost/client.rb', line 18

def webhooks
  @webhooks
end