Class: Postscale::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/postscale/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, base_url: nil, timeout: Configuration::DEFAULT_TIMEOUT, max_retries: Configuration::DEFAULT_MAX_RETRIES, headers: nil, transport: nil, sleeper: nil) ⇒ Client

Initialize a new Postscale API client.

client = Postscale::Client.new(api_key: "ps_live_...")
client = Postscale::Client.new(
  api_key:  "ps_test_...",
  base_url: "https://api.postscale.io",
  timeout:  30,
  retries:  3,
  debug:    false
)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/postscale/client.rb', line 18

def initialize(api_key: nil, base_url: nil, timeout: Configuration::DEFAULT_TIMEOUT, max_retries: Configuration::DEFAULT_MAX_RETRIES, headers: nil, transport: nil, sleeper: nil)
  resolved_api_key = api_key || ENV["POSTSCALE_API_KEY"]
  resolved_base_url = base_url || ENV["POSTSCALE_BASE_URL"] || Configuration::DEFAULT_BASE_URL

  @config = Configuration.new(
    api_key: resolved_api_key,
    base_url: resolved_base_url,
    timeout: timeout,
    max_retries: max_retries,
    headers: headers,
    transport: transport,
    sleeper: sleeper
  )
  @http = HttpClient.new(@config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/postscale/client.rb', line 5

def config
  @config
end

#httpObject (readonly)

Returns the value of attribute http.



5
6
7
# File 'lib/postscale/client.rb', line 5

def http
  @http
end

Instance Method Details

#aliasesObject



48
49
50
# File 'lib/postscale/client.rb', line 48

def aliases
  @aliases ||= Resources::Aliases.new(@http)
end

#dkimObject



44
45
46
# File 'lib/postscale/client.rb', line 44

def dkim
  @dkim ||= Resources::DKIM.new(@http)
end

#domainsObject



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

def domains
  @domains ||= Resources::Domains.new(@http)
end

#emailsObject

—– Resource accessors —–



36
37
38
# File 'lib/postscale/client.rb', line 36

def emails
  @emails ||= Resources::Emails.new(@http)
end

#inboundObject



52
53
54
# File 'lib/postscale/client.rb', line 52

def inbound
  @inbound ||= Resources::Inbound.new(@http)
end

#statsObject



56
57
58
# File 'lib/postscale/client.rb', line 56

def stats
  @stats ||= Resources::Stats.new(@http)
end

#suppressionsObject



64
65
66
# File 'lib/postscale/client.rb', line 64

def suppressions
  @suppressions ||= Resources::Suppressions.new(@http)
end

#templatesObject



72
73
74
# File 'lib/postscale/client.rb', line 72

def templates
  @templates ||= Resources::Templates.new(@http)
end

#trustObject



80
81
82
# File 'lib/postscale/client.rb', line 80

def trust
  @trust ||= Resources::Trust.new(@http)
end

#usageObject



76
77
78
# File 'lib/postscale/client.rb', line 76

def usage
  @usage ||= Resources::Usage.new(@http)
end

#warmingObject



60
61
62
# File 'lib/postscale/client.rb', line 60

def warming
  @warming ||= Resources::Warming.new(@http)
end

#webhooksObject



68
69
70
# File 'lib/postscale/client.rb', line 68

def webhooks
  @webhooks ||= Resources::Webhooks.new(@http)
end