Class: LucidIntercom::SendEvent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shop_attributes, credentials = LucidIntercom.credentials) ⇒ SendEvent

Returns a new instance of SendEvent.

Parameters:

  • shop_attributes (Hash)

    shop attributes in format returned by the Shopify API

  • credentials (LucidIntercom::Credentials) (defaults to: LucidIntercom.credentials)


16
17
18
19
# File 'lib/lucid_intercom/send_event.rb', line 16

def initialize(shop_attributes, credentials = LucidIntercom.credentials)
  @attributes = Attributes.new(shop_attributes, {}, credentials)
  @credentials = credentials
end

Instance Attribute Details

#attributesLucidIntercom::Attributes (readonly)



22
23
24
# File 'lib/lucid_intercom/send_event.rb', line 22

def attributes
  @attributes
end

#credentialsLucidIntercom::Credentials (readonly)



24
25
26
# File 'lib/lucid_intercom/send_event.rb', line 24

def credentials
  @credentials
end

Instance Method Details

#call(event_name, event_metadata) ⇒ Object

Send event for user identified by attributes.

Parameters:

  • event_name (String)
  • event_metadata (Hash)

Raises:



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lucid_intercom/send_event.rb', line 34

def call(event_name, )
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(req, data(event_name, ))
  end

  status = res.code.to_i

  if status >= 400 # rubocop:disable Style/GuardClause
    raise LucidIntercom::RequestError.new(status), 'invalid response code %s' % status
  end
end