Class: Gattica::Account

Inherits:
Object
  • Object
show all
Includes:
Convertible
Defined in:
lib/gattica/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Convertible

#to_h, #to_query, #to_s, #to_xml

Constructor Details

#initialize(xml) ⇒ Account

Returns a new instance of Account.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gattica/account.rb', line 8

def initialize(xml)
  @id = xml.at("link[@rel='self']").attributes['href']
  @updated = DateTime.parse(xml.at(:updated).inner_html)
  @account_id = (xml)

  @title = xpath_value(xml, "dxp:property[@name='ga:profileName']")
  @table_id = xpath_value(xml, "dxp:property[@name='dxp:tableId']")
  @profile_id = find_profile_id(xml)
  @web_property_id = xpath_value(xml, "dxp:property[@name='ga:webPropertyId']")
  @goals = []
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



5
6
7
# File 'lib/gattica/account.rb', line 5

def 
  @account_id
end

#account_nameObject (readonly)

Returns the value of attribute account_name.



5
6
7
# File 'lib/gattica/account.rb', line 5

def 
  @account_name
end

#goalsObject (readonly)

Returns the value of attribute goals.



5
6
7
# File 'lib/gattica/account.rb', line 5

def goals
  @goals
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/gattica/account.rb', line 5

def id
  @id
end

#profile_idObject (readonly)

Returns the value of attribute profile_id.



5
6
7
# File 'lib/gattica/account.rb', line 5

def profile_id
  @profile_id
end

#table_idObject (readonly)

Returns the value of attribute table_id.



5
6
7
# File 'lib/gattica/account.rb', line 5

def table_id
  @table_id
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/gattica/account.rb', line 5

def title
  @title
end

#updatedObject (readonly)

Returns the value of attribute updated.



5
6
7
# File 'lib/gattica/account.rb', line 5

def updated
  @updated
end

#web_property_idObject (readonly)

Returns the value of attribute web_property_id.



5
6
7
# File 'lib/gattica/account.rb', line 5

def web_property_id
  @web_property_id
end

Instance Method Details

#find_account_id(xml) ⇒ Object



24
25
26
# File 'lib/gattica/account.rb', line 24

def (xml)
  xml.at("dxp:property[@name='ga:accountId']").attributes['value'].to_i
end

#find_account_name(xml) ⇒ Object



28
29
30
# File 'lib/gattica/account.rb', line 28

def (xml)
  xml.at("dxp:property[@name='ga:accountName']").attributes['value']
end

#find_profile_id(xml) ⇒ Object



32
33
34
# File 'lib/gattica/account.rb', line 32

def find_profile_id(xml)
  xml.at("dxp:property[@name='ga:profileId']").attributes['value'].to_i
end

#set_account_name(account_feed_entry) ⇒ Object



36
37
38
39
40
# File 'lib/gattica/account.rb', line 36

def ()
  if @account_id == ()
    @account_name = ()
  end
end

#set_goals(goals_feed_entry) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gattica/account.rb', line 42

def set_goals(goals_feed_entry)
  if @profile_id == find_profile_id(goals_feed_entry)
    goal = goals_feed_entry.search('ga:goal').first
    @goals.push({
      :active => goal.attributes['active'],
      :name => goal.attributes['name'],
      :number => goal.attributes['number'].to_i,
      :value => goal.attributes['value'].to_f
    })
  end
end

#xpath_value(xml, xpath) ⇒ Object



20
21
22
# File 'lib/gattica/account.rb', line 20

def xpath_value(xml, xpath)
  xml.at(xpath).attributes['value']
end