Class: Mosaic::Lyris::Trigger

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaic/lyris/trigger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

callback_url, configuration, configuration=, default_list_id, default_trigger_id, get_array_data, get_boolean_data, get_data, get_date_data, get_demographic_data, get_element, get_integer_data, get_integer_element, get_time_data, get_time_element, get_time_offset_data, get_xml_time_data, #initialize, load_configuration, logger, logger=, password, post, put_array_data, put_data, put_demographic_data, put_extra_data, server, site_id, #to_param, triggers

Constructor Details

This class inherits a constructor from Mosaic::Lyris::Object

Instance Attribute Details

#addObject (readonly)

Returns the value of attribute add.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def add
  @add
end

#clickthruObject (readonly)

Returns the value of attribute clickthru.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def clickthru
  @clickthru
end

#enabledObject (readonly)

Returns the value of attribute enabled.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def enabled
  @enabled
end

#from_emailObject (readonly)

Returns the value of attribute from_email.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def from_email
  @from_email
end

#from_nameObject (readonly)

Returns the value of attribute from_name.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def from_name
  @from_name
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def id
  @id
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def message
  @message
end

#message_idObject (readonly)

Returns the value of attribute message_id.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def message_id
  @message_id
end

#message_textObject (readonly)

Returns the value of attribute message_text.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def message_text
  @message_text
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def name
  @name
end

#not_sentObject (readonly)

Returns the value of attribute not_sent.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def not_sent
  @not_sent
end

#recipients_dataObject (readonly)

Returns the value of attribute recipients_data.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def recipients_data
  @recipients_data
end

#sentObject (readonly)

Returns the value of attribute sent.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def sent
  @sent
end

#subjectObject (readonly)

Returns the value of attribute subject.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def subject
  @subject
end

#total_openedObject (readonly)

Returns the value of attribute total_opened.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def total_opened
  @total_opened
end

#total_sentObject (readonly)

Returns the value of attribute total_sent.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def total_sent
  @total_sent
end

#unique_bouncedObject (readonly)

Returns the value of attribute unique_bounced.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def unique_bounced
  @unique_bounced
end

#unique_clickObject (readonly)

Returns the value of attribute unique_click.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def unique_click
  @unique_click
end

#unique_openedObject (readonly)

Returns the value of attribute unique_opened.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def unique_opened
  @unique_opened
end

#unique_unsubscribedObject (readonly)

Returns the value of attribute unique_unsubscribed.



6
7
8
# File 'lib/mosaic/lyris/trigger.rb', line 6

def unique_unsubscribed
  @unique_unsubscribed
end

Class Method Details

.fire(id, *recipients) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mosaic/lyris/trigger.rb', line 28

def fire(id, *recipients)
  options = recipients.pop if recipients.last.is_a?(Hash)
  list_id = options[:list_id] || default_list_id
  id = lookup_trigger(id, :locale => options.delete(:locale)) if id.is_a?(Symbol)
  reply = post('triggers', 'fire-trigger') do |request|
    request.MLID list_id if list_id
    put_extra_data(request, 'trigger_id', id)
    put_extra_data(request, 'recipients', recipients.join(','))
    put_extra_data(request, 'recipients_data', recipients_data_url(options[:recipients_data]))
    put_extra_data(request, 'subject', options[:subject])
    put_extra_data(request, 'clickthru', 'on') if options[:clickthru]
    put_extra_data(request, 'add', 'yes') if options[:add]
    put_extra_data(request, 'message', options[:message])
    put_extra_data(request, 'message_text', options[:message_text])
    put_extra_data(request, 'from_email', options[:from_email])
    put_extra_data(request, 'from_name', options[:from_name])
  end
  sent = get_data(reply.at('/DATASET'), 'sent') || ''
  not_sent = get_data(reply.at('/DATASET'), 'not sent') || ''
  new options.merge(:id => id, :not_sent => not_sent.split(','), :sent => sent.split(','))
end

.lookup_trigger(key, options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/mosaic/lyris/trigger.rb', line 50

def lookup_trigger(key, options = {})
  locale = options[:locale] || I18n.locale
  locale = locale.to_s
  key = key.to_s
  if triggers[locale].is_a?(Hash) && triggers[locale][key]
    triggers[locale][key]
  else
    triggers[key]
  end
end

.query(what, options = {}) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/mosaic/lyris/trigger.rb', line 61

def query(what, options = {})
  if what == :all
    query_all(options)
  else
    query_one(what, options)
  end
end

.recipients_data_url(recipients_data) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/mosaic/lyris/trigger.rb', line 69

def recipients_data_url(recipients_data)
  return if recipients_data.nil?
  return recipients_data if URI.parse(recipients_data).scheme
  url = URI.parse(callback_url)
  url.path = recipients_data
  url.to_s
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/mosaic/lyris/trigger.rb', line 108

def enabled?
  enabled
end