Class: Mosaic::Lyris::Demographic

Inherits:
Object
  • Object
show all
Defined in:
lib/mosaic/lyris/demographic.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

#enabledObject (readonly)

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#groupObject (readonly)

Returns the value of attribute group.



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

def group
  @group
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#list_idObject (readonly)

Returns the value of attribute list_id.



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

def list_id
  @list_id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.add(type, name, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mosaic/lyris/demographic.rb', line 14

def add(type, name, options = {})
  validate_options!(type, options)
  reply = post('demographic', 'add') do |request|
    request.MLID options[:list_id] if options[:list_id]
    put_data(request, demographic_type(type), name)
    put_array_data(request, 'option', options[:option])
    put_data(request, 'state', 'enabled') if options[:enabled]
    put_data(request, 'size', options[:size]) if options[:size]
  end
  new(options.merge(:id => reply.at('/DATASET/DATA').inner_html.to_i, :name => name, :type => type))
end

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mosaic/lyris/demographic.rb', line 26

def query(what, options = {})
  reply = post('demographic', query_type(what)) do |request|
    request.MLID options[:list_id] if options[:list_id]
  end
  reply.search('/DATASET/RECORD').collect do |record|
    new :enabled => ([:enabled, :enabled_details].include?(what) || get_boolean_data(record, 'state', 'enabled')),
        :group => get_data(record, "group"),
        :id => get_integer_data(record, 'id'),
        :list_id => options[:list_id],
        :name => get_data(record, 'name'),
        :options => get_array_data(record, 'option'),
        :size => get_integer_data(record, 'size'),
        :type => get_data(record, 'type').downcase.gsub(/ /,'_').to_sym
  end
end