Class: BenchmarkEmail::Client

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

Constant Summary collapse

API_URL =
'https://clientapi.benchmarkemail.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token = nil) ⇒ Client

Returns a new instance of Client.

Raises:



13
14
15
16
# File 'lib/benchmark_email.rb', line 13

def initialize(access_token = nil)
  @access_token = access_token || ENV['BENCHMARK_EMAIL_API_TOKEN']
  raise EmptyTokenError if @access_token.nil? ||  @access_token.empty?
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



11
12
13
# File 'lib/benchmark_email.rb', line 11

def access_token
  @access_token
end

Instance Method Details

#get_contact_listsObject



18
19
20
21
22
23
24
25
26
# File 'lib/benchmark_email.rb', line 18

def get_contact_lists
  url = URI("#{API_URL}/Contact/")
  https = Net::HTTP.new(url.host, url.port)
  https.use_ssl = true
  request = Net::HTTP::Get.new(url)
  request["AuthToken"] = @access_token
  request["Content-Type"] = "application/json"
  JSON.parse(https.request(request).body)
end