Class: Workarea::Listrak::EmailApi::Events

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Events

Returns a new instance of Events.



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

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#all(list_id) ⇒ Array<Workarea::Listrak::Models::Event>

Returns the collection of events associated with the specified list.

Parameters:

  • list_id (Integer)

    the list id to get the events from

Returns:

Raises:

  • (OauthError)

    raised if generating an Oauth token is unsucessful



18
19
20
21
22
23
# File 'app/services/workarea/listrak/email_api/events.rb', line 18

def all(list_id)
  request = Net::HTTP::Get.new("/email/v1/List/#{list_id}/Event")
  response = client.request request
  body = JSON.parse(response.body)
  body["data"].map { |event| Listrak::Models::Event.new event }
end

#create(list_id, event) ⇒ String

Creates a new event on the specified list.

Parameters:

Returns:

  • (String)

    resource id

Raises:

  • (OauthError)

    raised if generating an Oauth token is unsucessful



34
35
36
37
38
39
40
41
# File 'app/services/workarea/listrak/email_api/events.rb', line 34

def create(list_id, event)
  request = Net::HTTP::Post.new("/email/v1/List/#{list_id}/Event").tap do |post|
    post.body = event.to_json
  end
  response = client.request request
  body = JSON.parse(response.body)
  body["resourceId"]
end