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.emails.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
48
49
50
51
# 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
  )
  @emails = Resources::Emails.new(http)
  @contacts = Resources::Contacts.new(http)
  @contact_fields = Resources::ContactFields.new(http)
  @segments = Resources::Segments.new(http)
  @topics = Resources::Topics.new(http)
  @campaigns = Resources::Campaigns.new(http)
  @templates = Resources::Templates.new(http)
  @brand_kits = Resources::BrandKits.new(http)
  @domains = Resources::Domains.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

#campaignsObject (readonly)

Returns the value of attribute campaigns.



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

def campaigns
  @campaigns
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

#domainsObject (readonly)

Returns the value of attribute domains.



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

def domains
  @domains
end

#emailsObject (readonly)

Returns the value of attribute emails.



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

def emails
  @emails
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

#templatesObject (readonly)

Returns the value of attribute templates.



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

def templates
  @templates
end

#topicsObject (readonly)

Returns the value of attribute topics.



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

def topics
  @topics
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