Permalink
Browse files

starting to add new feeds to get back a list of segments

profile now uses AccountFeedRequest
  • Loading branch information...
1 parent a011451 commit c9f362c1a1e08396eb0547a4521110374f12aec4 @tpitale tpitale committed May 15, 2010
View
@@ -11,6 +11,7 @@
require 'garb/version'
require 'garb/authentication_request'
require 'garb/data_request'
+require 'garb/account_feed_request'
require 'garb/session'
require 'garb/profile_reports'
require 'garb/profile'
@@ -0,0 +1,25 @@
+module Garb
+ class AccountFeedRequest < DataRequest
+ URL = "https://www.google.com/analytics/feeds/accounts/default"
+
+ def initialize(session = Session)
+ @request = DataRequest.new(session, URL)
+ end
+
+ def response
+ @response ||= @request.send_request
+ end
+
+ def parsed_response
+ @parsed_response ||= Crack::XML.parse(response.body)
+ end
+
+ def entries
+ parsed_response ? [parsed_response['feed']['entry']].flatten : []
+ end
+
+ def segments
+ parsed_response ? [parsed_response['dxp:segment']].flatten : []
+ end
+ end
+end
View
@@ -20,23 +20,11 @@ def id
end
def self.all(session = Session)
- url = "https://www.google.com/analytics/feeds/accounts/default"
- response = DataRequest.new(session, url).send_request
-
- puts response.body
- parse_entries(parse(response.body)).map {|entry| new(entry, session)}
+ AccountFeedRequest.new(session).entries.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_entries(entry_hash)
- entry_hash ? [entry_hash['feed']['entry']].flatten : []
- end
-
- def self.parse(response_body)
- Crack::XML.parse(response_body)
- end
end
end
@@ -0,0 +1,9 @@
+require File.join(File.dirname(__FILE__), '..', '..', '/test_helper')
+
+module Garb
+ class AccountFeedRequestTest < MiniTest::Unit::TestCase
+ context "An AccountFeedRequest" do
+
+ end
+ end
+end
@@ -7,17 +7,12 @@ class ProfileTest < MiniTest::Unit::TestCase
setup {@session = Session.new}
should "be able to return a list of all profiles" do
- url = 'https://www.google.com/analytics/feeds/accounts/default'
-
- xml = read_fixture('profile_feed.xml')
-
- data_request = stub
- data_request.stubs(:send_request).returns(stub(:body => xml))
- DataRequest.stubs(:new).returns(data_request)
+ afr = AccountFeedRequest.new
+ afr.stubs(:parsed_response).returns(Crack::XML.parse(read_fixture('profile_feed.xml')))
+ AccountFeedRequest.stubs(:new).returns(afr)
assert_equal ['12345', '12346'], Profile.all(@session).map(&:id)
- assert_received(DataRequest, :new) {|e| e.with(@session, url)}
- assert_received(data_request, :send_request)
+ assert_received(AccountFeedRequest, :new) {|e| e.with(@session)}
end
should "return the first profile for a given web property id" do
@@ -47,7 +42,10 @@ class ProfileTest < MiniTest::Unit::TestCase
context "An instance of the Profile class" do
setup do
- entry = Profile.parse_entries(Profile.parse(read_fixture('profile_feed.xml'))).first
+ afr = AccountFeedRequest.new
+ afr.stubs(:parsed_response).returns(Crack::XML.parse(read_fixture('profile_feed.xml')))
+
+ entry = afr.entries.first
@profile = Profile.new(entry, Session)
end

0 comments on commit c9f362c

Please sign in to comment.