Class: LucidIntercom::Event

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(post_request: Container[:post_request], update_user: Container[:update_user]) ⇒ Event

Returns a new instance of Event.

Parameters:

  • post_request (#call) (defaults to: Container[:post_request])
  • update_user (#call) (defaults to: Container[:update_user])


11
12
13
14
15
# File 'lib/lucid_intercom/event.rb', line 11

def initialize(post_request: Container[:post_request],
               update_user: Container[:update_user])
  @post_request = post_request
  @update_user = update_user
end

Class Method Details

.event(name) ⇒ Object

Set the event name for the subclass.

Examples:

event :changed_plan

Parameters:

  • name (String, #to_s)


66
67
68
69
70
# File 'lib/lucid_intercom/event.rb', line 66

def self.event(name)
  define_method(:name) { "#{LucidIntercom.config.app_prefix}_#{name}" }

  private :name
end

Instance Method Details

#notify(shopify_data_or_user, *args) ⇒ Object Also known as: call

Parameters:

  • shopify_data_or_user (Hash, UserAttributes)

    shop attributes as returned by the Shopify API

  • *args (Array<Object>)


21
22
23
24
25
26
27
28
# File 'lib/lucid_intercom/event.rb', line 21

def notify(shopify_data_or_user, *args)
  user = shopify_data_or_user
  user = UserAttributes.new(user, app_data(*args)) if user.is_a?(Hash)

  @post_request.('events', data(user, *args)).assert!

  @update_user.(user)
end