Skip to content
Browse files

switch to version 2 of the gdata api without adding any features or b…

…reaking anything
  • Loading branch information...
1 parent 09b36fe commit 0446243575d0b10b0aec9a0cb45c56874179eeda @tpitale tpitale committed May 6, 2010
Showing with 46 additions and 19 deletions.
  1. +8 −4 lib/garb/profile.rb
  2. +33 −13 test/fixtures/profile_feed.xml
  3. +4 −1 test/unit/garb/data_request_test.rb
  4. +1 −1 test/unit/garb/profile_test.rb
View
12 lib/garb/profile.rb
@@ -3,7 +3,7 @@ class Profile
include ProfileReports
- attr_reader :session, :table_id, :title, :account_name, :account_id, :web_property_id
+ attr_reader :session, :table_id, :title, :account_name, :account_id, :web_property_id, :segments
def initialize(entry, session)
@session = session
@@ -22,16 +22,20 @@ def id
def self.all(session = Session)
url = "https://www.google.com/analytics/feeds/accounts/default"
response = DataRequest.new(session, url).send_request
- parse(response.body).map {|entry| new(entry, session)}
+
+ parse_entries(parse(response.body)).map {|entry| new(entry, session)}
end
def self.first(id, session = Session)
all(session).detect {|profile| profile.id == id || profile.web_property_id == id }
end
- def self.parse(response_body)
- entry_hash = Crack::XML.parse(response_body)
+ def self.parse_entries(entry_hash)
entry_hash ? [entry_hash['feed']['entry']].flatten : []
end
+
+ def self.parse(response_body)
+ Crack::XML.parse(response_body)
+ end
end
end
View
46 test/fixtures/profile_feed.xml
@@ -1,19 +1,31 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dxp="http://schemas.google.com/analytics/2009" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">
+<?xml version='1.0' encoding='UTF-8'?>
+<feed xmlns='http://www.w3.org/2005/Atom' xmlns:dxp='http://schemas.google.com/analytics/2009' xmlns:ga='http://schemas.google.com/ga/2009' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;A0UASX45cCp7I2A9WxFQEUQ.&quot;' gd:kind='analytics#accounts'>
<id>http://www.google.com/analytics/feeds/accounts/tpitale@gmail.com</id>
- <updated>2009-10-02T07:47:35.000-07:00</updated>
- <title type="text">Profile list for tpitale@gmail.com</title>
- <link rel="self" type="application/atom+xml" href="http://www.google.com/analytics/feeds/accounts/default"/>
+ <updated>2010-05-06T19:27:28.028-07:00</updated>
+ <title>Profile list for tpitale@gmail.com</title>
+ <link rel='self' type='application/atom+xml' href='https://www.google.com/analytics/feeds/accounts/default'/>
<author><name>Google Analytics</name></author>
- <generator version="1.0">Google Analytics</generator>
+ <generator version='1.0'>Google Analytics</generator>
<openSearch:totalResults>2</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>2</openSearch:itemsPerPage>
- <entry>
+ <dxp:segment id='gaid::-1' name='All Visits'>
+ <dxp:definition> </dxp:definition>
+ </dxp:segment>
+ <dxp:segment id='gaid::-2' name='New Visitors'>
+ <dxp:definition>ga:visitorType==New Visitor</dxp:definition>
+ </dxp:segment>
+ <dxp:segment id='gaid::-3' name='Paid Search Traffic'>
+ <dxp:definition>ga:medium==cpa,ga:medium==cpc,ga:medium==cpm,ga:medium==cpp,ga:medium==cpv,ga:medium==ppc</dxp:definition>
+ </dxp:segment>
+ <dxp:segment id='gaid::0' name='Not New York'>
+ <dxp:definition>ga:city!=New York</dxp:definition>
+ </dxp:segment>
+ <entry gd:etag='W/&quot;CUcHSXs8fip7I2A9WxBUFUg.&quot;' gd:kind='analytics#account'>
<id>http://www.google.com/analytics/feeds/accounts/ga:12345</id>
<updated>2008-07-21T14:05:57.000-07:00</updated>
- <title type="text">Historical</title>
- <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
+ <title>Historical</title>
+ <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
<dxp:property name="ga:accountId" value="1111"/>
<dxp:property name="ga:accountName" value="Blog Beta"/>
<dxp:property name="ga:profileId" value="1212"/>
@@ -22,11 +34,19 @@
<dxp:property name="ga:timezone" value="America/New_York"/>
<dxp:tableId>ga:12345</dxp:tableId>
</entry>
- <entry>
+ <entry gd:etag='W/&quot;A0UASX45cCp7I2A9WxFQEUQ.&quot;' gd:kind='analytics#account'>
<id>http://www.google.com/analytics/feeds/accounts/ga:12346</id>
<updated>2008-11-24T11:51:07.000-08:00</updated>
- <title type="text">Presently</title>
- <link rel="alternate" type="text/html" href="http://www.google.com/analytics"/>
+ <title>Presently</title>
+ <link rel='alternate' type='text/html' href='http://www.google.com/analytics'/>
+ <ga:goal active='true' name='Contact Form Submission' number='1' value='100.0'>
+ <ga:destination caseSensitive='false' expression='/contact-submit' matchType='exact' step1Required='true'>
+ <ga:step name='Contact Form Page' number='1' path='/contact.html'/>
+ </ga:destination>
+ </ga:goal>
+ <ga:goal active='true' name='Newsletter Form Submission' number='2' value='25.0'>
+ <ga:destination caseSensitive='false' expression='/newsletter-submit' matchType='exact' step1Required='false'/>
+ </ga:goal>
<dxp:property name="ga:accountId" value="1111"/>
<dxp:property name="ga:accountName" value="Blog Beta"/>
<dxp:property name="ga:profileId" value="1213"/>
@@ -35,4 +55,4 @@
<dxp:property name="ga:timezone" value="America/New_York"/>
<dxp:tableId>ga:12346</dxp:tableId>
</entry>
-</feed>
+</feed>
View
5 test/unit/garb/data_request_test.rb
@@ -90,7 +90,10 @@ class DataRequestTest < MiniTest::Unit::TestCase
http = mock do |m|
m.expects(:use_ssl=).with(true)
m.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
- m.expects(:get).with('/data?key=value', {'Authorization' => 'GoogleLogin auth=toke', 'GData-Version' => '2'}).returns(response)
+ m.expects(:get).with('/data?key=value', {
+ 'Authorization' => 'GoogleLogin auth=toke',
+ 'GData-Version' => '2'
+ }).returns(response)
end
Net::HTTP.expects(:new).with('example.com', 443).returns(http)
View
2 test/unit/garb/profile_test.rb
@@ -47,7 +47,7 @@ class ProfileTest < MiniTest::Unit::TestCase
context "An instance of the Profile class" do
setup do
- entry = Profile.parse(read_fixture('profile_feed.xml')).first
+ entry = Profile.parse_entries(Profile.parse(read_fixture('profile_feed.xml'))).first
@profile = Profile.new(entry, Session)
end

0 comments on commit 0446243

Please sign in to comment.
Something went wrong with that request. Please try again.