garb 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,11 +32,11 @@ module Garb
32
32
  http = Net::HTTP.new(uri.host, uri.port)
33
33
  http.use_ssl = true
34
34
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
35
- http.get("#{uri.path}#{query_string}", 'Authorization' => "GoogleLogin auth=#{@session.auth_token}")
35
+ http.get("#{uri.path}#{query_string}", {'Authorization' => "GoogleLogin auth=#{@session.auth_token}", 'GData-Version' => '2'})
36
36
  end
37
37
 
38
38
  def oauth_user_request
39
- @session.access_token.get("#{uri}#{query_string}")
39
+ @session.access_token.get("#{uri}#{query_string}", {'GData-Version' => '2'})
40
40
  end
41
41
  end
42
42
  end
@@ -23,7 +23,7 @@ module Garb
23
23
 
24
24
  def entries
25
25
  entry_hash = Crack::XML.parse(@xml)
26
- entry_hash ? [entry_hash['feed']['entry']].flatten : []
26
+ entry_hash ? [entry_hash['feed']['entry']].flatten.compact : []
27
27
  end
28
28
 
29
29
  def values_for(entry)
data/lib/garb/resource.rb CHANGED
@@ -40,6 +40,10 @@ module Garb
40
40
  @filter_parameters = FilterParameters.new
41
41
  end
42
42
 
43
+ def set_segment_id(id)
44
+ @segment = "gaid::#{id.to_i}"
45
+ end
46
+
43
47
  def results(profile, opts = {}, &block)
44
48
  @profile = profile.is_a?(Profile) ? profile : Profile.first(profile, opts.fetch(:session, Session))
45
49
 
@@ -67,13 +71,18 @@ module Garb
67
71
  'end-date' => format_time(@end_date)}
68
72
  end
69
73
 
74
+ def segment_params
75
+ @segment ? {'segment' => @segment} : {}
76
+ end
77
+
70
78
  def params
71
79
  [
72
80
  metrics.to_params,
73
81
  dimensions.to_params,
74
82
  sort.to_params,
75
83
  filters.to_params,
76
- page_params
84
+ page_params,
85
+ segment_params
77
86
  ].inject(default_params) do |p, i|
78
87
  p.merge(i)
79
88
  end
data/lib/garb/version.rb CHANGED
@@ -3,7 +3,7 @@ module Garb
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 7
6
- TINY = 4
6
+ TINY = 5
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -9,6 +9,13 @@ module Garb
9
9
 
10
10
  assert_equal ['33', '2', '1'], response.results.map(&:pageviews)
11
11
  end
12
+
13
+ should "return an empty array if there are no results" do
14
+ response = ReportResponse.new("result xml")
15
+ Crack::XML.stubs(:parse).with("result xml").returns({'feed' => {'entry' => nil}})
16
+
17
+ assert_equal [], response.results
18
+ end
12
19
  end
13
20
  end
14
21
  end
@@ -43,6 +43,11 @@ module Garb
43
43
  assert_equal params, @report.default_params
44
44
  end
45
45
 
46
+ should "allow setting a segment id to the segment params" do
47
+ @report.set_segment_id 121
48
+ assert_equal({'segment' => 'gaid::121'}, @report.segment_params)
49
+ end
50
+
46
51
  should "collect params from metrics, dimensions, filters, sort, and defaults" do
47
52
  @report.stubs(:metrics).returns(stub(:to_params => {'metrics' => 6}))
48
53
  @report.stubs(:dimensions).returns(stub(:to_params => {'dimensions' => 5}))
@@ -50,9 +55,12 @@ module Garb
50
55
  @report.stubs(:sort).returns(stub(:to_params => {'sort' => 3}))
51
56
  @report.stubs(:page_params).returns({'page_params' => 2})
52
57
  @report.stubs(:default_params).returns({'default_params' => 1})
58
+ @report.stubs(:segment_params).returns({'segment' => 'gaid::10'})
53
59
 
54
- params = {'metrics' => 6, 'dimensions' => 5, 'filters' => 4, 'sort' => 3, 'page_params' => 2, 'default_params' => 1}
55
- assert_equal params, @report.params
60
+ expected_params = {'metrics' => 6,'dimensions' => 5, 'filters' => 4, 'sort' => 3,
61
+ 'page_params' => 2, 'default_params' => 1, 'segment' => 'gaid::10'}
62
+
63
+ assert_equal expected_params, @report.params
56
64
  end
57
65
 
58
66
  should "format time" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 4
9
- version: 0.7.4
8
+ - 5
9
+ version: 0.7.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tony Pitale
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-25 00:00:00 -04:00
17
+ date: 2010-05-15 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency