Class: Mosaic::Lyris::Record

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

Instance Attribute Summary collapse

Class 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

#demographicsObject (readonly)

Returns the value of attribute demographics.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def demographics
  @demographics
end

#doubleoptinObject (readonly)

Returns the value of attribute doubleoptin.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def doubleoptin
  @doubleoptin
end

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def email
  @email
end

#encodingObject (readonly)

Returns the value of attribute encoding.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def encoding
  @encoding
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def id
  @id
end

#joindateObject (readonly)

Returns the value of attribute joindate.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def joindate
  @joindate
end

#list_idObject (readonly)

Returns the value of attribute list_id.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def list_id
  @list_id
end

#proofObject (readonly)

Returns the value of attribute proof.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def proof
  @proof
end

#stateObject (readonly)

Returns the value of attribute state.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def state
  @state
end

#statedateObject (readonly)

Returns the value of attribute statedate.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def statedate
  @statedate
end

#trashedObject (readonly)

Returns the value of attribute trashed.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def trashed
  @trashed
end

#triggerObject (readonly)

Returns the value of attribute trigger.



4
5
6
# File 'lib/mosaic/lyris/record.rb', line 4

def trigger
  @trigger
end

Class Method Details

.add(email, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mosaic/lyris/record.rb', line 18

def add(email, options = {})
  validate_options!(options)
  reply = post('record', 'add') do |request|
    request.MLID options[:list_id] if options[:list_id]
    put_data(request, 'email', email)
    put_demographic_data(request, options[:demographics])
    put_extra_data(request, 'trigger', 'yes') if options[:trigger]
    put_extra_data(request, 'proof', 'yes') if options[:proof]
    put_extra_data(request, 'state', options[:state])
    put_extra_data(request, 'encoding', options[:encoding])
    put_extra_data(request, 'doubleoptin', 'yes') if options[:doubleoptin]
  end
  new(options.merge(:id => reply.at('/DATASET/DATA').inner_html, :email => email, :state => options[:state] || 'active', :trashed => %w(bounced unsubscribed trashed).include?(options[:state].to_s)))
end

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



33
34
35
36
37
38
39
# File 'lib/mosaic/lyris/record.rb', line 33

def query(what, options = {})
  if /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i === what
    query_one(what, options)
  else
    query_all(what, options)
  end
end

.update(email, options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mosaic/lyris/record.rb', line 41

def update(email, options = {})
  validate_options!(options)
  reply = post('record', 'update') do |request|
    request.MLID options[:list_id] if options[:list_id]
    put_data(request, 'email', email)
    put_extra_data(request, 'new_email', options[:email])
    put_demographic_data(request, options[:demographics])
    put_extra_data(request, 'trigger', 'yes') if options[:trigger]
    put_extra_data(request, 'proof', 'yes') if options[:proof]
    put_extra_data(request, 'state', options[:state])
    put_extra_data(request, 'encoding', options[:encoding])
  end
  # TODO: query full record? this is an incomplete snapshot of the updated record (ie. it only contains updated attributes/demographics)
  new(options.merge(:id => reply.at('/DATASET/DATA').inner_html, :email => options[:email] || email, :state => options[:state], :trashed => options[:state] && %w(bounced unsubscribed trashed).include?(options[:state].to_s)))
end