Permalink
Browse files

added support for setting the segment id on a report or a customer re…

…source
  • Loading branch information...
tpitale committed May 16, 2010
1 parent fd9e98a commit c2b165482ed6a6cdad428abc2bcf275b7b080a59
Showing with 22 additions and 5 deletions.
  1. +2 −2 lib/garb/data_request.rb
  2. +10 −1 lib/garb/resource.rb
  3. +10 −2 test/unit/garb/report_test.rb
View
@@ -32,11 +32,11 @@ def single_user_request
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- http.get("#{uri.path}#{query_string}", 'Authorization' => "GoogleLogin auth=#{@session.auth_token}")
+ http.get("#{uri.path}#{query_string}", {'Authorization' => "GoogleLogin auth=#{@session.auth_token}", 'GData-Version' => '2'})
end
def oauth_user_request
- @session.access_token.get("#{uri}#{query_string}")
+ @session.access_token.get("#{uri}#{query_string}", {'GData-Version' => '2'})
end
end
end
View
@@ -40,6 +40,10 @@ def clear_filters
@filter_parameters = FilterParameters.new
end
+ def set_segment_id(id)
+ @segment = "gaid::#{id.to_i}"
+ end
+
def results(profile, opts = {}, &block)
@profile = profile.is_a?(Profile) ? profile : Profile.first(profile, opts.fetch(:session, Session))
@@ -67,13 +71,18 @@ def default_params
'end-date' => format_time(@end_date)}
end
+ def segment_params
+ @segment ? {'segment' => @segment} : {}
+ end
+
def params
[
metrics.to_params,
dimensions.to_params,
sort.to_params,
filters.to_params,
- page_params
+ page_params,
+ segment_params
].inject(default_params) do |p, i|
p.merge(i)
end
@@ -43,16 +43,24 @@ class ReportTest < MiniTest::Unit::TestCase
assert_equal params, @report.default_params
end
+ should "allow setting a segment id to the segment params" do
+ @report.set_segment_id 121
+ assert_equal({'segment' => 'gaid::121'}, @report.segment_params)
+ end
+
should "collect params from metrics, dimensions, filters, sort, and defaults" do
@report.stubs(:metrics).returns(stub(:to_params => {'metrics' => 6}))
@report.stubs(:dimensions).returns(stub(:to_params => {'dimensions' => 5}))
@report.stubs(:filters).returns(stub(:to_params => {'filters' => 4}))
@report.stubs(:sort).returns(stub(:to_params => {'sort' => 3}))
@report.stubs(:page_params).returns({'page_params' => 2})
@report.stubs(:default_params).returns({'default_params' => 1})
+ @report.stubs(:segment_params).returns({'segment' => 'gaid::10'})
- params = {'metrics' => 6, 'dimensions' => 5, 'filters' => 4, 'sort' => 3, 'page_params' => 2, 'default_params' => 1}
- assert_equal params, @report.params
+ expected_params = {'metrics' => 6,'dimensions' => 5, 'filters' => 4, 'sort' => 3,
+ 'page_params' => 2, 'default_params' => 1, 'segment' => 'gaid::10'}
+
+ assert_equal expected_params, @report.params
end
should "format time" do

0 comments on commit c2b1654

Please sign in to comment.