Class: Workarea::Listrak::EmailApi

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/listrak/email_api.rb

Defined Under Namespace

Classes: Contacts, Events, Lists, Messages, TransactionalMessages

Instance Method Summary collapse

Constructor Details

#initialize(client_id:, client_secret:, open_timeout: nil, read_timeout: nil) ⇒ EmailApi

Returns a new instance of EmailApi.



4
5
6
7
8
9
# File 'app/services/workarea/listrak/email_api.rb', line 4

def initialize(client_id:, client_secret:, open_timeout: nil, read_timeout: nil)
  @client_id = client_id
  @client_secret = client_secret
  @open_timeout = open_timeout
  @read_timeout = read_timeout
end

Instance Method Details

#contactsObject



34
35
36
# File 'app/services/workarea/listrak/email_api.rb', line 34

def contacts
  Contacts.new self
end

#eventsObject



30
31
32
# File 'app/services/workarea/listrak/email_api.rb', line 30

def events
  Events.new self
end

#listsObject



38
39
40
# File 'app/services/workarea/listrak/email_api.rb', line 38

def lists
  Lists.new self
end

#messagesObject



42
43
44
# File 'app/services/workarea/listrak/email_api.rb', line 42

def messages
  Messages.new self
end

#request(http_request) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/workarea/listrak/email_api.rb', line 11

def request(http_request)
  token = Listrak::Oauth.token(client_id: client_id, client_secret: client_secret)

  http_request.add_field 'Authorization', "Bearer #{token}"
  http_request.add_field 'Content-Type', 'application/json'
  http_request['Accept'] = 'application/json'

  response = http.start do |conn|
    conn.request http_request
  end

  case response
  when ::Net::HTTPSuccess
    response
  else
    raise Listrak::HttpError, response
  end
end

#transactional_messagesObject



46
47
48
# File 'app/services/workarea/listrak/email_api.rb', line 46

def transactional_messages
  TransactionalMessages.new self
end