Permalink
Browse files

Test happy path for google analytics client

  • Loading branch information...
1 parent f4f01fd commit 5ca06bb16ad46ba278ef80848d29c35b1f4ecfdd Pawel Badenski committed Jan 21, 2013
Showing with 27 additions and 9 deletions.
  1. +0 −8 lib/client.rb
  2. +4 −1 lib/collector.rb
  3. +23 −0 spec/integration/google_analytics_client_spec.rb
View
8 lib/client.rb
@@ -20,14 +20,6 @@ def authenticate(auth_code)
client
end
- def collect(config)
- results = config.analytics_parameters.map do |parameters|
- query(parameters)
- end
-
- results
- end
-
def query(parameters)
logger.debug { "Query GA with params: #{parameters}" }
View
5 lib/collector.rb
@@ -65,7 +65,10 @@ def collect_response(config)
end
def collect(config)
- GoogleAnalytics::Client.new(@auth_code).collect(config)
+ google_analytics_client = GoogleAnalytics::Client.new(@auth_code)
+ config.analytics_parameters.map do |parameters|
+ google_analytics_client.query(parameters)
+ end
end
end
View
23 spec/integration/google_analytics_client_spec.rb
@@ -0,0 +1,23 @@
+require_relative "spec_helper"
+
+describe GoogleAnalytics::Client do
+ before :each do
+ stub_credentials
+ register_oauth_refresh
+ register_api_discovery
+ end
+
+ it "should return data from google analytics API" do
+ ga_request = setup_ga_request(:ids => "ga:0", :metrics => "ga:stub-metric")
+ ga_request.register("2012-01-01", "2012-01-31", "weekly_transaction_response.json")
+
+ client = GoogleAnalytics::Client.new("some-auth-code")
+
+ data = client.query({ "ids" => "ga:0",
+ "metrics" => "ga:stub-metric",
+ "start-date" => "2012-01-01",
+ "end-date" => "2012-01-31" })
+
+ data["rows"].should_not be_empty
+ end
+end

0 comments on commit 5ca06bb

Please sign in to comment.