Class: GoodDataMarketo::Activity
- Inherits:
-
Object
- Object
- GoodDataMarketo::Activity
- Defined in:
- lib/gooddata_marketo/models/child/activity.rb
Instance Method Summary collapse
- #attributes(a = nil) ⇒ Object
- #date ⇒ Object
- #headers ⇒ Object (also: #columns)
- #id ⇒ Object
-
#initialize(data, config = {}) ⇒ Activity
constructor
attr_accessor :client.
- #name ⇒ Object
- #raw ⇒ Object (also: #json)
- #time ⇒ Object (also: #activity_date_time)
- #to_row ⇒ Object (also: #to_a)
- #type ⇒ Object (also: #activity_type)
- #values ⇒ Object
Constructor Details
#initialize(data, config = {}) ⇒ Activity
attr_accessor :client
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 7 def initialize data, config = {} data = JSON.parse(data, :symbolize_names => true) unless data.is_a? Hash @activity = { :id => data[:id], :activity_date_time => data[:activity_date_time].to_s, # Force this to be ADS DATETIME :activity_type => data[:activity_type], :mktg_asset_name => data[:mktg_asset_name], :raw => data } @headers = @activity.keys.map{|k| k.to_s.capitalize! } @headers.pop() attributes = data[:activity_attributes][:attribute] attribute_map = Hash.new attributes.map { |attr| @headers << property = attr[:attr_name].gsub(" ","_").downcase value = StringWizard.escape_special_characters(attr[:attr_value].to_s) attribute_map[property] = value } @attributes = attribute_map end |
Instance Method Details
#attributes(a = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 82 def attributes a = nil if a @attributes[a] else @attributes end end |
#date ⇒ Object
70 71 72 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 70 def date @activity[:date] end |
#headers ⇒ Object Also known as: columns
64 65 66 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 64 def headers @headers.map { |h| h.scan(/\w+/).join.downcase } end |
#id ⇒ Object
74 75 76 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 74 def id @activity[:id] end |
#name ⇒ Object
78 79 80 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 78 def name @activity[:mktg_asset_name] end |
#raw ⇒ Object Also known as: json
92 93 94 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 92 def raw @activity[:raw] end |
#time ⇒ Object Also known as: activity_date_time
46 47 48 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 46 def time @activity[:activity_date_time] end |
#to_row ⇒ Object Also known as: to_a
54 55 56 57 58 59 60 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 54 def to_row row = [self.id,self.time,self.type,self.name] @attributes.each do |attr| row << attr[1] end row.map! { |i| i.to_s } end |
#type ⇒ Object Also known as: activity_type
50 51 52 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 50 def type @activity[:activity_type] end |
#values ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gooddata_marketo/models/child/activity.rb', line 34 def values hash = Hash.new hash['id'] = self.id hash['activity_date_time'] = self.time hash['activity_type'] = self.type hash['mktg_asset_name'] = self.name @attributes.each do |attr| hash[attr[0].scan(/\w+/).join] = attr[1] end hash end |