macros-garb 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ module Garb
4
+ class ReportResponseTest < Test::Unit::TestCase
5
+ context "An instance of the ReportResponse class" do
6
+ setup do
7
+ @xml = File.read(File.join(File.dirname(__FILE__), '..', "/fixtures/report_feed.xml"))
8
+ @response = ReportResponse.new(@xml)
9
+ end
10
+
11
+ should "parse xml response with happymapper" do
12
+ h1 = {"city"=>"(not set)", "pageviews"=>"33", "country"=>"(not set)"}
13
+ h2 = {"city"=>"Kabul", "pageviews"=>"2", "country"=>"Afghanistan"}
14
+ h3 = {"city"=>"Tirana", "pageviews"=>"1", "country"=>"Albania"}
15
+
16
+ OpenStruct.expects(:new).with(h1).returns('entry1')
17
+ OpenStruct.expects(:new).with(h2).returns('entry2')
18
+ OpenStruct.expects(:new).with(h3).returns('entry3')
19
+
20
+ assert_equal(['entry1', 'entry2', 'entry3'], @response.parse)
21
+ end
22
+
23
+ should "have results or parse them" do
24
+ @response.expects(:parse)
25
+ @response.results
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,71 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ module Garb
4
+ # Also tests Garb::Resource, which is the basis for Garb::Report
5
+ class ReportTest < Test::Unit::TestCase
6
+ context "An instance of the Report class" do
7
+ setup do
8
+ @now = Time.now
9
+ Time.stubs(:now).returns(@now)
10
+ @profile = stub(:table_id => 'ga:1234')
11
+ @report = Report.new(@profile)
12
+ end
13
+
14
+ %w(metrics dimensions filters sorts).each do |param|
15
+ should "have parameters for #{param}" do
16
+ assert @report.send(:"#{param}").is_a?(ReportParameter)
17
+ end
18
+ end
19
+
20
+ should "have default parameters" do
21
+ @report.stubs(:format_time).returns('2009-08-01')
22
+ params = {'ids' => 'ga:1234', 'start-date' => '2009-08-01', 'end-date' => '2009-08-01'}
23
+ assert_equal params, @report.default_params
24
+ end
25
+
26
+ should "collect params from metrics, dimensions, filters, sort, and defaults" do
27
+ @report.stubs(:metrics).returns(stub(:to_params => {'metrics' => 6}))
28
+ @report.stubs(:dimensions).returns(stub(:to_params => {'dimensions' => 5}))
29
+ @report.stubs(:filters).returns(stub(:to_params => {'filters' => 4}))
30
+ @report.stubs(:sorts).returns(stub(:to_params => {'sort' => 3}))
31
+ @report.stubs(:page_params).returns({'page_params' => 2})
32
+ @report.stubs(:default_params).returns({'default_params' => 1})
33
+
34
+ params = {'metrics' => 6, 'dimensions' => 5, 'filters' => 4, 'sort' => 3, 'page_params' => 2, 'default_params' => 1}
35
+ assert_equal params, @report.params
36
+ end
37
+
38
+ should "format time" do
39
+ assert_equal @now.strftime('%Y-%m-%d'), @report.format_time(@now)
40
+ end
41
+
42
+ should "send a data request to GA" do
43
+ response = mock {|m| m.expects(:body).returns('response body') }
44
+ request = mock {|m| m.expects(:send_request).returns(response) }
45
+ @report.expects(:params).returns('params')
46
+
47
+ DataRequest.expects(:new).with(Garb::Report::URL, 'params').returns(request)
48
+ assert_equal 'response body', @report.send_request_for_body
49
+ end
50
+
51
+ should "fetch and parse results from GA" do
52
+ @report.expects(:send_request_for_body).with().returns('xml')
53
+ ReportResponse.expects(:new).with('xml').returns(mock(:results => ['entry']))
54
+ assert_equal ['entry'], @report.results
55
+ end
56
+ end
57
+
58
+ context "An instance of the Report class with initial options" do
59
+ setup do
60
+ @profile = stub(:table_id => 'ga:1234')
61
+ @report = Report.new(@profile, :limit => 10, :offset => 20)
62
+ end
63
+
64
+ should "have page paramaters" do
65
+ params = {'max-results' => 10, 'start-index' => 20}
66
+ assert_equal params, @report.page_params
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ class TestReport
4
+ include Garb::Resource
5
+ end
6
+
7
+ # Most of the resource testing is done as a part of ReportTest
8
+ class ResourceTest < Test::Unit::TestCase
9
+
10
+ context "A class with Garb::Resource mixed in" do
11
+ should "get results from GA" do
12
+ profile = stub
13
+ TestReport.expects(:send_request_for_body).returns('xml')
14
+ Garb::ReportResponse.expects(:new).with('xml').returns(mock(:results => 'analytics'))
15
+
16
+ assert_equal 'analytics', TestReport.results(profile)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ module Garb
4
+ class SessionTest < Test::Unit::TestCase
5
+
6
+ context "The Session class" do
7
+
8
+ should "be able retrieve an auth_token for a user" do
9
+ auth_request = mock {|m| m.expects(:auth_token).with({}).returns('toke') }
10
+ AuthenticationRequest.expects(:new).with('email', 'password').returns(auth_request)
11
+
12
+ Session.login('email', 'password')
13
+ assert_equal 'toke', Session.auth_token
14
+ end
15
+
16
+ should "be able retrieve an auth_token for a user with secure ssl" do
17
+ auth_request = mock {|m| m.expects(:auth_token).with({:secure => true}).returns('toke') }
18
+ AuthenticationRequest.expects(:new).with('email', 'password').returns(auth_request)
19
+
20
+ Session.login('email', 'password', :secure => true)
21
+ assert_equal 'toke', Session.auth_token
22
+ end
23
+
24
+ should "retain the email address for this session" do
25
+ AuthenticationRequest.stubs(:new).returns(stub(:auth_token => 'toke'))
26
+
27
+ Session.login('email', 'password')
28
+ assert_equal 'email', Session.email
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ class StringTest < Test::Unit::TestCase
4
+ context "An instance of a String" do
5
+ should 'prefix a string with ga: for GA' do
6
+ assert_equal 'ga:bob', 'bob'.to_ga
7
+ end
8
+
9
+ should 'remove ga: prefix' do
10
+ assert_equal 'bob', 'ga:bob'.from_ga
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
+
3
+ class SymbolTest < Test::Unit::TestCase
4
+
5
+ context "An instance of the Symbol class" do
6
+
7
+ should "properly format itself for ga" do
8
+ assert_equal "ga:requestUri", :request_uri.to_ga
9
+ end
10
+
11
+ should "define a :desc operator" do
12
+ operator = stub()
13
+ symbol = :foo
14
+
15
+ Operator.expects(:new).with(:foo, '-', true).returns(operator)
16
+ assert_equal operator, :foo.desc
17
+ end
18
+
19
+ def self.should_define_operator(operators)
20
+ operators.each do |method, operator|
21
+ should "define an :#{method} operator" do
22
+ new_operator = stub()
23
+ symbol = :foo
24
+
25
+ Operator.expects(:new).with(:foo, operator).returns(new_operator)
26
+ assert_equal new_operator, :foo.send(method)
27
+ end
28
+ end
29
+ end
30
+
31
+ should_define_operator :eql => '==',
32
+ :not_eql => '!=',
33
+ :gt => '>',
34
+ :gte => '>=',
35
+ :lt => '<',
36
+ :lte => '<=',
37
+ :matches => '==',
38
+ :does_not_match => '!=',
39
+ :contains => '=~',
40
+ :does_not_contain => '!~',
41
+ :substring => '=@',
42
+ :not_substring => '!@'
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: macros-garb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.6
5
+ platform: ruby
6
+ authors:
7
+ - Tony Pitale
8
+ - Justin Marney
9
+ - Patrick Reagan
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-06-30 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: happymapper
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.2.5
26
+ version:
27
+ description:
28
+ email: tony.pitale@viget.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - README.md
37
+ - Rakefile
38
+ - lib/extensions
39
+ - lib/extensions/array.rb
40
+ - lib/extensions/operator.rb
41
+ - lib/extensions/string.rb
42
+ - lib/extensions/symbol.rb
43
+ - lib/garb
44
+ - lib/garb/account.rb
45
+ - lib/garb/authentication_request.rb
46
+ - lib/garb/data_request.rb
47
+ - lib/garb/oauth_session.rb
48
+ - lib/garb/profile.rb
49
+ - lib/garb/report.rb
50
+ - lib/garb/report_parameter.rb
51
+ - lib/garb/report_response.rb
52
+ - lib/garb/resource.rb
53
+ - lib/garb/session.rb
54
+ - lib/garb/version.rb
55
+ - lib/garb.rb
56
+ - test/fixtures
57
+ - test/fixtures/cacert.pem
58
+ - test/fixtures/profile_feed.xml
59
+ - test/fixtures/report_feed.xml
60
+ - test/test_helper.rb
61
+ - test/unit
62
+ - test/unit/account_test.rb
63
+ - test/unit/authentication_request_test.rb
64
+ - test/unit/data_request_test.rb
65
+ - test/unit/garb_test.rb
66
+ - test/unit/oauth_session_test.rb
67
+ - test/unit/operator_test.rb
68
+ - test/unit/profile_test.rb
69
+ - test/unit/report_parameter_test.rb
70
+ - test/unit/report_response_test.rb
71
+ - test/unit/report_test.rb
72
+ - test/unit/resource_test.rb
73
+ - test/unit/session_test.rb
74
+ - test/unit/string_test.rb
75
+ - test/unit/symbol_test.rb
76
+ has_rdoc: false
77
+ homepage: http://github.com/vigetlabs/garb
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.2.0
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Google Analytics API Ruby Wrapper
102
+ test_files:
103
+ - test/fixtures
104
+ - test/fixtures/cacert.pem
105
+ - test/fixtures/profile_feed.xml
106
+ - test/fixtures/report_feed.xml
107
+ - test/test_helper.rb
108
+ - test/unit
109
+ - test/unit/account_test.rb
110
+ - test/unit/authentication_request_test.rb
111
+ - test/unit/data_request_test.rb
112
+ - test/unit/garb_test.rb
113
+ - test/unit/oauth_session_test.rb
114
+ - test/unit/operator_test.rb
115
+ - test/unit/profile_test.rb
116
+ - test/unit/report_parameter_test.rb
117
+ - test/unit/report_response_test.rb
118
+ - test/unit/report_test.rb
119
+ - test/unit/resource_test.rb
120
+ - test/unit/session_test.rb
121
+ - test/unit/string_test.rb
122
+ - test/unit/symbol_test.rb