forked from er1c/gattica
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
209 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
source "http://rubygems.org" | ||
gemspec | ||
gem 'test-unit' | ||
gem 'hpricot' #, 0.8.6 | ||
gem 'test-unit' #, 2.4.5 | ||
gem 'bundler' #, 1.0.21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
<<<<<<< HEAD | ||
gattica (0.5.1) | ||
======= | ||
gattica (0.6.0) | ||
gattica | ||
>>>>>>> upstream/master | ||
hpricot | ||
test-unit | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
hpricot (0.8.6) | ||
<<<<<<< HEAD | ||
rake (0.9.2.2) | ||
======= | ||
>>>>>>> upstream/master | ||
test-unit (2.4.5) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
<<<<<<< HEAD | ||
rake | ||
======= | ||
gattica! | ||
>>>>>>> upstream/master | ||
test-unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
--- | ||
:major: 0 | ||
:minor: 5 | ||
:minor: 6 | ||
:patch: 1 | ||
:build: | ||
:build: !!null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,54 @@ | ||
require 'rubygems' | ||
require 'hpricot' | ||
|
||
module Gattica | ||
|
||
# Represents an account that an authenticated user has access to | ||
|
||
class Account | ||
|
||
include Convertible | ||
|
||
attr_reader :id, :updated, :title, :table_id, :account_id, :account_name, | ||
:profile_id, :web_property_id, :goals | ||
|
||
def initialize(xml) | ||
@id = xml.at(:id).inner_html | ||
@id = xml.at("link[@rel='self']").attributes['href'] | ||
@updated = DateTime.parse(xml.at(:updated).inner_html) | ||
@title = xml.at(:title).inner_html | ||
@table_id = xml.at('dxp:tableid').inner_html | ||
@account_id = xml.at("dxp:property[@name='ga:accountId']").attributes['value'].to_i | ||
@account_name = xml.at("dxp:property[@name='ga:accountName']").attributes['value'] | ||
@profile_id = xml.at("dxp:property[@name='ga:profileId']").attributes['value'].to_i | ||
@web_property_id = xml.at("dxp:property[@name='ga:webPropertyId']").attributes['value'] | ||
@goals = xml.search('ga:goal').collect do |goal| { | ||
:active => goal.attributes['active'], | ||
:name => goal.attributes['name'], | ||
:number => goal.attributes['number'].to_i, | ||
:value => goal.attributes['value'].to_f, | ||
} | ||
@account_id = find_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 | ||
|
||
def xpath_value(xml, xpath) | ||
xml.at(xpath).attributes['value'] | ||
end | ||
|
||
def find_account_id(xml) | ||
xml.at("dxp:property[@name='ga:accountId']").attributes['value'].to_i | ||
end | ||
|
||
def find_account_name(xml) | ||
xml.at("dxp:property[@name='ga:accountName']").attributes['value'] | ||
end | ||
|
||
def find_profile_id(xml) | ||
xml.at("dxp:property[@name='ga:profileId']").attributes['value'].to_i | ||
end | ||
|
||
def set_account_name(account_feed_entry) | ||
if @account_id == find_account_id(account_feed_entry) | ||
@account_name = find_account_name(account_feed_entry) | ||
end | ||
end | ||
|
||
|
||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.