rugalytics 0.0.1

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,86 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Rugalytics::Account do
4
+
5
+ describe "being initialized" do
6
+ it "should accept :name as key" do
7
+ a = Rugalytics::Account.new(:name => 'test')
8
+ a.name.should == 'test'
9
+ end
10
+
11
+ it "should accept :account_id as key" do
12
+ a = Rugalytics::Account.new(:account_id => '12341234')
13
+ a.account_id.should == '12341234'
14
+ end
15
+ end
16
+
17
+ it "should be able to find all accounts for user" do
18
+ html = fixture('analytics_account_find_all.html')
19
+ Rugalytics::Account.should_receive(:get).and_return(html)
20
+ accounts = Rugalytics::Account.find_all
21
+ accounts.collect(&:name).should == %w[your_site.com webgroup.nd.edu]
22
+ accounts.collect(&:account_id).should == %w[1254221 344381].map(&:to_i)
23
+ end
24
+
25
+ it "should be able to find profiles for an account" do
26
+ html = fixture('analytics_profile_find_all.html')
27
+ Rugalytics::Profile.should_receive(:get).and_return(html)
28
+ accounts = Rugalytics::Account.new(:name => 'your_site.com', :account_id => '1254221').profiles
29
+ accounts.collect(&:name).should == ["blog.your_site.com"]
30
+ end
31
+
32
+ it "should print kind of pretty" do
33
+ account = Rugalytics::Account.new(:name => 'your_site.com', :account_id => '1254221')
34
+ account.to_s.should == "your_site.com (1254221)"
35
+ end
36
+
37
+ before do
38
+ @account = mock('account', :name=>'your_site.com', :account_id=>1254221)
39
+ end
40
+
41
+ describe "finding an account by its name" do
42
+ it 'should find all and return the match' do
43
+ Rugalytics::Account.should_receive(:find_all).and_return [@account]
44
+ Rugalytics::Account.find(@account.name).should == @account
45
+ end
46
+
47
+ it 'should return nil if there is no match' do
48
+ Rugalytics::Account.should_receive(:find_all).and_return [@account]
49
+ Rugalytics::Account.find('no_match').should be_nil
50
+ end
51
+ end
52
+
53
+ describe "finding an account by its account_id" do
54
+ it 'should find all and return the match' do
55
+ Rugalytics::Account.should_receive(:find_all).and_return [@account]
56
+ Rugalytics::Account.find(@account.account_id).should == @account
57
+ end
58
+
59
+ it 'should return nil if there is no match' do
60
+ Rugalytics::Account.should_receive(:find_all).and_return [@account]
61
+ Rugalytics::Account.find(111).should be_nil
62
+ end
63
+ end
64
+
65
+ describe "finding a profile by its profile_id" do
66
+
67
+ it 'should return the match' do
68
+ profile_id = 12341234
69
+ profile = mock('profile', :profile_id => profile_id)
70
+ account = Rugalytics::Account.new({})
71
+ account.should_receive(:profiles).and_return [profile]
72
+ account.find_profile(profile_id).should == profile
73
+ end
74
+ end
75
+
76
+ describe "finding a profile by its profile_id" do
77
+ it 'should return the match' do
78
+ profile_id = 12341234
79
+ name = 'blog.your_site.com'
80
+ profile = mock('profile', :profile_id => profile_id, :name => name)
81
+ account = Rugalytics::Account.new({})
82
+ account.should_receive(:profiles).and_return [profile]
83
+ account.find_profile(name).should == profile
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Rugalytics::Graph do
4
+
5
+ describe 'when creating' do
6
+
7
+ before :all do
8
+ @period = '1 May 2008 - 3 May 2008'
9
+ @name = 'Page Views'
10
+ @points = [5360, 3330, 4330]
11
+ end
12
+
13
+ it "should create fields for attributes and values" do
14
+ graph = Rugalytics::Graph.new @name, @period, @points
15
+
16
+ graph.from.should == Date.parse('2008-05-01')
17
+ graph.to.should == Date.parse('2008-05-03')
18
+
19
+ graph.points.should == @points
20
+ end
21
+
22
+ end
23
+
24
+ describe 'when counting total of points' do
25
+ it 'should sum points in graph' do
26
+ graph = Rugalytics::Graph.new '','',[5360, 3330, 4330]
27
+ graph.sum_of_points.should == 5360 + 3330 + 4330
28
+ end
29
+ end
30
+
31
+ describe 'when counting total of points' do
32
+ it 'should sum points in graph' do
33
+ graph = Rugalytics::Graph.new '','',[5360, 3330, 4330]
34
+ from = Date.parse('1 May 2003')
35
+ mid = Date.parse('2 May 2003')
36
+ to = Date.parse('3 May 2003')
37
+ graph.stub!(:from).and_return from
38
+ graph.stub!(:to).and_return to
39
+ graph.points_by_day.should == [[from,5360],[mid,3330],[to,4330]]
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Rugalytics::Item, 'when creating' do
4
+
5
+ before :all do
6
+ @url = 'theyworkforyou.co.nz'
7
+ @attributes = 'URL,Page Views,Unique Page Views,Time on Page,Bounce Rate,% Exit,$ Index'
8
+ @values = '/,189,157,54.94957983193277,0.4862385392189026,0.37037035822868347,0.0'
9
+ end
10
+
11
+ it "it should create fields for attributes and values" do
12
+ item = Rugalytics::Item.new @attributes.split(','), @values.split(','), @url
13
+
14
+ item.url.should == 'http://theyworkforyou.co.nz/'
15
+ item.page_views.should == '189'
16
+ item.unique_page_views.should == '157'
17
+ item.time_on_page.should == '54.94957983193277'
18
+ item.bounce_rate.should == '0.4862385392189026'
19
+ item.percentage_exit.should == '0.37037035822868347'
20
+ item.dollar_index.should == '0.0'
21
+ end
22
+
23
+ end
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Rugalytics::Profile do
4
+
5
+ describe "being initialized" do
6
+
7
+ it "should accept :name as key" do
8
+ a = Rugalytics::Profile.new(:name => 'test', :profile_id => '12341234')
9
+ a.name.should == 'test'
10
+ end
11
+
12
+ it "should accept :account_id as key" do
13
+ a = Rugalytics::Profile.new(:account_id => '12341234', :profile_id => '12341234')
14
+ a.account_id.should == '12341234'
15
+ end
16
+
17
+ it "should accept :profile_id as key" do
18
+ a = Rugalytics::Profile.new(:profile_id => '12341234')
19
+ a.profile_id.should == '12341234'
20
+ end
21
+
22
+ end
23
+
24
+ describe "finding by account id and profile id" do
25
+ it 'should find account and find profile' do
26
+ account_id = 1254221
27
+ profile_id = 12341234
28
+ account = mock('account')
29
+ profile = mock('profile')
30
+
31
+ Rugalytics::Account.should_receive(:find).with(1254221).and_return account
32
+ account.should_receive(:find_profile).with(profile_id).and_return profile
33
+ Rugalytics::Profile.find(account_id, profile_id).should == profile
34
+ end
35
+ end
36
+
37
+ describe 'finding pageviews' do
38
+ it 'should return total from loaded "Pageviews" report' do
39
+ profile = Rugalytics::Profile.new :profile_id=>123
40
+ profile.should_receive(:load_report).with('Pageviews',{}).and_return mock('report',:page_views_total=>100)
41
+ profile.pageviews.should == 100
42
+ end
43
+ describe 'when from and to dates are specified' do
44
+ it 'should return total from "Pageviews" report for given dates' do
45
+ profile = Rugalytics::Profile.new :profile_id=>123
46
+ from = '2008-05-01'
47
+ to = '2008-05-03'
48
+ options = {:from=>from, :to=>to}
49
+ profile.should_receive(:load_report).with('Pageviews', options).and_return mock('report',:page_views_total=>100)
50
+ profile.pageviews(options).should == 100
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'finding visits' do
56
+ it 'should return total from loaded "Visits" report' do
57
+ profile = Rugalytics::Profile.new :profile_id=>123
58
+ profile.should_receive(:load_report).with('Visits',{}).and_return mock('report',:visits_total=>100)
59
+ profile.visits.should == 100
60
+ end
61
+ describe 'when from and to dates are specified' do
62
+ it 'should return total from "Visits" report for given dates' do
63
+ profile = Rugalytics::Profile.new :profile_id=>123
64
+ from = '2008-05-01'
65
+ to = '2008-05-03'
66
+ options = {:from=>from, :to=>to}
67
+ profile.should_receive(:load_report).with('Visits', options).and_return mock('report',:visits_total=>100)
68
+ profile.visits(options).should == 100
69
+ end
70
+ end
71
+ end
72
+
73
+ it "should be able to find all profiles for an account" do
74
+ html = fixture('analytics_profile_find_all.html')
75
+ Rugalytics::Profile.should_receive(:get).and_return(html)
76
+ accounts = Rugalytics::Profile.find_all('1254221')
77
+ accounts.collect(&:name).should == ["blog.your_site.com"]
78
+ end
79
+
80
+ describe "finding by account name and profile name" do
81
+ it 'should find account and find profile' do
82
+ account_name = 'your_site.com'
83
+ profile_name = 'blog.your_site.com'
84
+ account = mock('account')
85
+ profile = mock('profile')
86
+
87
+ Rugalytics::Account.should_receive(:find).with(account_name).and_return account
88
+ account.should_receive(:find_profile).with(profile_name).and_return profile
89
+ Rugalytics::Profile.find(account_name, profile_name).should == profile
90
+ end
91
+ end
92
+
93
+ describe "finding a profile by passing single name when account and profile name are the same" do
94
+ it 'should find account and find profile' do
95
+ name = 'your_site.com'
96
+ account = mock('account')
97
+ profile = mock('profile')
98
+
99
+ Rugalytics::Account.should_receive(:find).with(name).and_return account
100
+ account.should_receive(:find_profile).with(name).and_return profile
101
+ Rugalytics::Profile.find(name).should == profile
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,153 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ describe Rugalytics::Report do
4
+
5
+ describe "creating report from csv" do
6
+
7
+ describe "when setting report attributes" do
8
+ before :all do
9
+ csv = %Q|# ----------------------------------------
10
+ theyworkforyou.co.nz
11
+ Top Content,
12
+ 26 May 2008,31 May 2008
13
+ # ----------------------------------------|
14
+ @report = Rugalytics::Report.new(csv)
15
+ end
16
+
17
+ it "should set base url from second line of text" do
18
+ @report.base_url.should == 'theyworkforyou.co.nz'
19
+ end
20
+
21
+ it "should set report name from third line of text" do
22
+ @report.report_name.should == 'Top Content'
23
+ end
24
+
25
+ it "should set start date from fourth line of text" do
26
+ @report.start_date.should == '26 May 2008'
27
+ end
28
+
29
+ it "should set end date from fourth line of text" do
30
+ @report.end_date.should == '31 May 2008'
31
+ end
32
+ end
33
+
34
+ describe "when creating items from 'Table'" do
35
+ before :all do
36
+ @base_url = %Q|theyworkforyou.co.nz|
37
+ @attributes = %Q|URL,Page Views,Unique Page Views,Time on Page,Bounce Rate,% Exit,$ Index|
38
+ @values1 = %Q|/,189,157,54.94957983193277,0.4862385392189026,0.37037035822868347,0.0|
39
+ @values2 = %Q|/bills,60,38,54.17307692307692,0.0,0.13333334028720856,0.0|
40
+ @csv = %Q|# ----------------------------------------
41
+ #{@base_url}
42
+ Top Content,
43
+ 26 May 2008,31 May 2008
44
+ # ----------------------------------------
45
+ # ----------------------------------------
46
+ # Table
47
+ # ----------------------------------------
48
+ #{@attributes}
49
+ #{@values1}
50
+ #{@values2}
51
+ # --------------------------------------------------------------------------------
52
+ |
53
+ end
54
+
55
+ it 'should create item for each data row in "Table"' do
56
+ item1 = mock('item1')
57
+ item2 = mock('item2')
58
+ Rugalytics::Item.should_receive(:new).with(@attributes.split(','), @values1.split(','), @base_url).and_return item1
59
+ Rugalytics::Item.should_receive(:new).with(@attributes.split(','), @values2.split(','), @base_url).and_return item2
60
+
61
+ report = Rugalytics::Report.new(@csv)
62
+ report.items.should == [item1, item2]
63
+ end
64
+ end
65
+
66
+ describe "when creating items from '.*MiniTableTable'" do
67
+ before :all do
68
+ @base_url = %Q|theyworkforyou.co.nz|
69
+ @browser_attributes = %Q|Browser,Visits,% visits|
70
+ @browser_values = %Q|Firefox,1529,0.17185568809509277|
71
+ @connection_speed_attributes = %Q|Connection Speed,Visits,% visits|
72
+ @connection_speed_values = %Q|Unknown,3987,0.4481285810470581|
73
+ @csv = %Q|# ----------------------------------------
74
+ #{@base_url}
75
+ Visitors Overview,
76
+ 3 May 2008,2 June 2008
77
+ # ----------------------------------------
78
+ # ----------------------------------------
79
+ # BrowserMiniTable
80
+ # ----------------------------------------
81
+ #{@browser_attributes}
82
+ #{@browser_values}
83
+
84
+ # ----------------------------------------
85
+ # ConnectionSpeedMiniTable
86
+ # ----------------------------------------
87
+ #{@connection_speed_attributes}
88
+ #{@connection_speed_values}
89
+ # --------------------------------------------------------------------------------|
90
+ end
91
+ it 'should create item for each data row in "XxxMiniTable"' do
92
+ browser_item = mock('browser_item')
93
+ connection_item = mock('item')
94
+ Rugalytics::Item.should_receive(:new).with(@browser_attributes.split(','), @browser_values.split(','), @base_url).and_return browser_item
95
+ Rugalytics::Item.should_receive(:new).with(@connection_speed_attributes.split(','), @connection_speed_values.split(','), @base_url).and_return connection_item
96
+
97
+ report = Rugalytics::Report.new(@csv)
98
+ report.browser_items.should == [browser_item]
99
+ report.connection_speed_items.should == [connection_item]
100
+ report.attribute_names.should == ['browser_items', 'connection_speed_items']
101
+ end
102
+ end
103
+
104
+ describe "when creating graph points from 'Graph'" do
105
+ before :all do
106
+ @period = %Q|1 May 2008 - 31 May 2008|
107
+ @name = %Q|Page Views|
108
+ @csv = %Q|# ----------------------------------------
109
+ theyworkforyou.co.nz
110
+ Top Content,
111
+ 26 May 2008,31 May 2008
112
+ # ----------------------------------------
113
+
114
+ # ----------------------------------------
115
+ # Graph
116
+ # ----------------------------------------
117
+ #{@period}
118
+ #{@name}
119
+ "5,360"
120
+ 433|
121
+ end
122
+
123
+ it 'should create graph with data under "Graph"' do
124
+ graph = mock('graph')
125
+ Rugalytics::Graph.should_receive(:new).with(@name, @period, [5360, 433]).and_return graph
126
+
127
+ report = Rugalytics::Report.new(@csv)
128
+ report.page_views_graph.should == graph
129
+ report.attribute_names.should == ['page_views_graph']
130
+ end
131
+ end
132
+ end
133
+
134
+ describe 'when retrieving total using method not defined on class' do
135
+ it 'should return total from graph named in method name' do
136
+ report = Rugalytics::Report.new
137
+ report.should_receive(:respond_to?).with(:page_views_graph).and_return true
138
+ report.should_receive(:page_views_graph).and_return mock('graph', :sum_of_points=>100)
139
+ report.method_missing(:page_views_total).should == 100
140
+ end
141
+ end
142
+
143
+ describe 'when retrieving list by day using method not defined on class' do
144
+ it 'should return by day list from graph named in method name' do
145
+ report = Rugalytics::Report.new
146
+ report.should_receive(:respond_to?).with(:page_views_graph).and_return true
147
+ points_by_day = mock('points_by_day')
148
+ report.should_receive(:page_views_graph).and_return mock('graph', :points_by_day=>points_by_day)
149
+ report.method_missing(:page_views_by_day).should == points_by_day
150
+ end
151
+ end
152
+
153
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe Rugalytics do
4
+
5
+ describe "finding a profile by its account name and profile name" do
6
+ it 'should return the match' do
7
+ account_name = 'your_site.com'
8
+ profile_name = 'blog.your_site.com'
9
+ profile = mock('profile')
10
+ Rugalytics::Profile.should_receive(:find).with(account_name, profile_name).and_return profile
11
+ Rugalytics::find_profile(account_name, profile_name).should == profile
12
+ end
13
+ end
14
+
15
+ describe "finding a profile by its account_id and profile_id" do
16
+ it 'should return the match' do
17
+ account_id = 1254221
18
+ profile_id = 12341234
19
+ profile = mock('profile')
20
+ Rugalytics::Profile.should_receive(:find).with(account_id, profile_id).and_return profile
21
+ Rugalytics::find_profile(account_id, profile_id).should == profile
22
+ end
23
+ end
24
+
25
+ describe "finding a profile by passing single name when account and profile name are the same" do
26
+ it 'should return the match' do
27
+ name = 'your_site.com'
28
+ profile = mock('profile')
29
+ Rugalytics::Profile.should_receive(:find).with(name, nil).and_return profile
30
+ Rugalytics::find_profile(name).should == profile
31
+ end
32
+ end
33
+
34
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,7 @@
1
+ --color
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+ --diff
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ gem 'rspec'
3
+ require 'spec'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/rugalytics'
6
+
7
+ def fixture(filename)
8
+ open("#{File.dirname(__FILE__)}/fixtures/#{filename}").read
9
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rugalytics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rob McKinnon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0.6"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: activesupport
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 2.0.2
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: googlebase
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: morph
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.1.5
50
+ version:
51
+ description: Rugalytics is a Ruby API for Google Analytics.
52
+ email:
53
+ - rob ~@nospam@~ rubyforge.org
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - CHANGELOG
60
+ - LICENSE
61
+ - README
62
+ files:
63
+ - CHANGELOG
64
+ - lib/rugalytics/account.rb
65
+ - lib/rugalytics/analytics.rb
66
+ - lib/rugalytics/connection.rb
67
+ - lib/rugalytics/graph.rb
68
+ - lib/rugalytics/item.rb
69
+ - lib/rugalytics/profile.rb
70
+ - lib/rugalytics/report.rb
71
+ - lib/rugalytics.rb
72
+ - LICENSE
73
+ - Manifest
74
+ - README
75
+ - README.rdoc
76
+ - spec/fixtures/analytics_account_find_all.html
77
+ - spec/fixtures/analytics_profile_find_all.html
78
+ - spec/fixtures/dashboard_report_webgroup.xml
79
+ - spec/lib/rugalytics/account_spec.rb
80
+ - spec/lib/rugalytics/graph_spec.rb
81
+ - spec/lib/rugalytics/item_spec.rb
82
+ - spec/lib/rugalytics/profile_spec.rb
83
+ - spec/lib/rugalytics/report_spec.rb
84
+ - spec/lib/rugalytics_spec.rb
85
+ - spec/spec.opts
86
+ - spec/spec_helper.rb
87
+ - rugalytics.gemspec
88
+ has_rdoc: true
89
+ homepage: ""
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --line-numbers
93
+ - --inline-source
94
+ - --title
95
+ - Rugalytics
96
+ - --main
97
+ - README
98
+ - --inline-source
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ requirements: []
114
+
115
+ rubyforge_project: rugalytics
116
+ rubygems_version: 1.1.0
117
+ signing_key:
118
+ specification_version: 2
119
+ summary: Rugalytics is a Ruby API for Google Analytics.
120
+ test_files: []
121
+