Class: LoopsRails::Events

Inherits:
ApiResource show all
Defined in:
lib/loops_rails/client/events.rb

Instance Method Summary collapse

Methods inherited from ApiResource

#initialize

Constructor Details

This class inherits a constructor from LoopsRails::ApiResource

Instance Method Details

#send(email: nil, user_id: nil, event_name:, event_properties: {}, mailing_lists: {}, contact_properties: {}) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/loops_rails/client/events.rb', line 3

def send(email: nil, user_id: nil, event_name:, event_properties: {}, mailing_lists: {}, contact_properties: {})
  raise ArgumentError, "Either email or user_id must be provided" if email.nil? && user_id.nil?

  payload = {
    email: email,
    userId: user_id,
    eventName: event_name,
    eventProperties: event_properties,
    mailingLists: mailing_lists,
    contactProperties: contact_properties
  }.compact.to_json

  response = @conn.post('events/send') do |req|
    req.body = payload
  end

  parse_response(response)
end