rugalytics 0.0.4 → 0.0.5

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.0.5. report names are now methods that can be called on profile, load_report is deprecated
2
+
1
3
  v0.0.4. fix for HTML and URL changes at Google Analytics site
2
4
 
3
5
  v0.0.3. get some rails integration going on, with config/rugalytics.yml
data/README CHANGED
@@ -18,6 +18,24 @@ Should be up at rubyforge, so to install:
18
18
  sudo gem install rugalytics
19
19
 
20
20
 
21
+ == Changes in v0.0.5
22
+
23
+ The load_report method has been deprecated, instead call the report name as
24
+ a method, for example:
25
+
26
+ # Instead of this
27
+ report = profile.load_report('Pageviews', :from => '2007-01-01')
28
+
29
+ # Do this
30
+ report = profile.pageviews_report(:from => '2007-01-01')
31
+
32
+ # Instead of this
33
+ report = profile.load_report('TrafficSources')
34
+
35
+ # Do this
36
+ report = profile.traffic_sources_report
37
+
38
+
21
39
  == Authenticate
22
40
 
23
41
  Login with your Google Analytics user name and password:
@@ -55,7 +73,7 @@ Obtaining page views:
55
73
 
56
74
  The +pageviews+ method is doing this under the hood:
57
75
 
58
- report = profile.load_report('Pageviews', :from=>'2007-01-01', :to=>'2007-01-02')
76
+ report = profile.pageviews_report(:from=>'2007-01-01', :to=>'2007-01-02')
59
77
 
60
78
  report.page_views_total
61
79
  => 24980
@@ -77,7 +95,7 @@ the Export tab, and then mousing over the CSV option.
77
95
 
78
96
  Let's load the TrafficSources report:
79
97
 
80
- report = profile.load_report 'TrafficSources'
98
+ report = profile.traffic_sources_report
81
99
 
82
100
  report.report_name
83
101
  => "Traffic Sources Overview"
@@ -96,17 +114,17 @@ Let's load the TrafficSources report:
96
114
 
97
115
  Let's try another report, VisitorsOverview:
98
116
 
99
- report = profile.load_report 'VisitorsOverview'
117
+ report = profile.visitors_overview_report
100
118
 
101
119
  report.browser_items[1]
102
- => #<Rugalytics::Item @percentage_visits="0.18", @visits="3140", @browser="Firefox">
120
+ => # Rugalytics::Item @percentage_visits="0.18", @visits="3140", @browser="Firefox"
103
121
 
104
122
  report.connection_speed_items[3]
105
- => #<Rugalytics::Item @connection_speed="Dialup", @percentage_visits="0.06340057402849197", @visits="1100">
123
+ => # Rugalytics::Item @connection_speed="Dialup", @percentage_visits="0.06340057402849197", @visits="1100"
106
124
 
107
125
  Let's now grab 100 lines of the Networks report:
108
126
 
109
- report = profile.load_report 'Networks', :rows=>100
127
+ report = profile.networks_report :rows=>100
110
128
 
111
129
  report.items.size
112
130
  => 100
@@ -121,13 +139,13 @@ To use from Rails, make a config file rails_root/config/rugalytics.yml
121
139
  with the following contents:
122
140
 
123
141
  ---
124
- account: <account_name>
125
- profile: <profile_name>
126
- username: <user_name>
127
- password: <pass_w>
142
+ account: [account_name]
143
+ profile: [profile_name]
144
+ username: [user_name]
145
+ password: [pass_w]
128
146
 
129
147
  Remember to tell your source control system to ignore this file! If you're
130
- using git, this means adding config/rugalytics.yml to you .gitignore
148
+ using git, this means adding config/rugalytics.yml to your .gitignore
131
149
  file.
132
150
 
133
151
  vi .gitignore
@@ -137,7 +155,7 @@ You can now use Rugalytics from within Rails, and login will be done
137
155
  automatically, e.g.:
138
156
 
139
157
  profile = Rugalytics.default_profile
140
- report = profile.load_report('TopContent', :from=>(Date.today - 7) )
158
+ report = profile.top_content_report(:from=>(Date.today - 7) )
141
159
  top_items_over_week = report.items.sort_by{|i| i.unique_page_views.to_i}.reverse
142
160
 
143
161
 
data/README.rdoc CHANGED
@@ -18,6 +18,24 @@ Should be up at rubyforge, so to install:
18
18
  sudo gem install rugalytics
19
19
 
20
20
 
21
+ == Changes in v0.0.5
22
+
23
+ The load_report method has been deprecated, instead call the report name as
24
+ a method, for example:
25
+
26
+ # Instead of this
27
+ report = profile.load_report('Pageviews', :from => '2007-01-01')
28
+
29
+ # Do this
30
+ report = profile.pageviews_report(:from => '2007-01-01')
31
+
32
+ # Instead of this
33
+ report = profile.load_report('TrafficSources')
34
+
35
+ # Do this
36
+ report = profile.traffic_sources_report
37
+
38
+
21
39
  == Authenticate
22
40
 
23
41
  Login with your Google Analytics user name and password:
@@ -55,7 +73,7 @@ Obtaining page views:
55
73
 
56
74
  The +pageviews+ method is doing this under the hood:
57
75
 
58
- report = profile.load_report('Pageviews', :from=>'2007-01-01', :to=>'2007-01-02')
76
+ report = profile.pageviews_report(:from=>'2007-01-01', :to=>'2007-01-02')
59
77
 
60
78
  report.page_views_total
61
79
  => 24980
@@ -77,7 +95,7 @@ the Export tab, and then mousing over the CSV option.
77
95
 
78
96
  Let's load the TrafficSources report:
79
97
 
80
- report = profile.load_report 'TrafficSources'
98
+ report = profile.traffic_sources_report
81
99
 
82
100
  report.report_name
83
101
  => "Traffic Sources Overview"
@@ -96,17 +114,17 @@ Let's load the TrafficSources report:
96
114
 
97
115
  Let's try another report, VisitorsOverview:
98
116
 
99
- report = profile.load_report 'VisitorsOverview'
117
+ report = profile.visitors_overview_report
100
118
 
101
119
  report.browser_items[1]
102
- => #<Rugalytics::Item @percentage_visits="0.18", @visits="3140", @browser="Firefox">
120
+ => # Rugalytics::Item @percentage_visits="0.18", @visits="3140", @browser="Firefox"
103
121
 
104
122
  report.connection_speed_items[3]
105
- => #<Rugalytics::Item @connection_speed="Dialup", @percentage_visits="0.06340057402849197", @visits="1100">
123
+ => # Rugalytics::Item @connection_speed="Dialup", @percentage_visits="0.06340057402849197", @visits="1100"
106
124
 
107
125
  Let's now grab 100 lines of the Networks report:
108
126
 
109
- report = profile.load_report 'Networks', :rows=>100
127
+ report = profile.networks_report :rows=>100
110
128
 
111
129
  report.items.size
112
130
  => 100
@@ -121,13 +139,13 @@ To use from Rails, make a config file rails_root/config/rugalytics.yml
121
139
  with the following contents:
122
140
 
123
141
  ---
124
- account: <account_name>
125
- profile: <profile_name>
126
- username: <user_name>
127
- password: <pass_w>
142
+ account: [account_name]
143
+ profile: [profile_name]
144
+ username: [user_name]
145
+ password: [pass_w]
128
146
 
129
147
  Remember to tell your source control system to ignore this file! If you're
130
- using git, this means adding config/rugalytics.yml to you .gitignore
148
+ using git, this means adding config/rugalytics.yml to your .gitignore
131
149
  file.
132
150
 
133
151
  vi .gitignore
@@ -137,7 +155,7 @@ You can now use Rugalytics from within Rails, and login will be done
137
155
  automatically, e.g.:
138
156
 
139
157
  profile = Rugalytics.default_profile
140
- report = profile.load_report('TopContent', :from=>(Date.today - 7) )
158
+ report = profile.top_content_report(:from=>(Date.today - 7) )
141
159
  top_items_over_week = report.items.sort_by{|i| i.unique_page_views.to_i}.reverse
142
160
 
143
161
 
data/Rakefile CHANGED
@@ -20,4 +20,9 @@ end
20
20
  desc "Open an irb session preloaded with this library"
21
21
  task :console do
22
22
  sh "irb -rubygems -r ./lib/rugalytics.rb"
23
+ end
24
+
25
+ desc "Run all examples with RCov"
26
+ task :rcov do
27
+ sh '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -Ilib -S rcov --text-report -o "coverage" -x "Library" spec/lib/**/*'
23
28
  end
@@ -27,13 +27,25 @@ module Rugalytics
27
27
  @profile_id = attrs[:profile_id] if attrs.has_key?(:profile_id)
28
28
  end
29
29
 
30
+ def method_missing symbol, *args
31
+ if name = symbol.to_s[/^(.+)_report$/, 1]
32
+ options = args && args.size == 1 ? args[0] : {}
33
+ create_report(name.camelize, options)
34
+ else
35
+ super
36
+ end
37
+ end
38
+
30
39
  def load_report(name, options={})
31
- report = Rugalytics::Report.new report(options.merge({:report=>name}))
32
- puts report.attribute_names
33
- report
40
+ if options=={}
41
+ ActiveSupport::Deprecation.warn "Profile#load_report('#{name}') has been deprecated, use Profile##{name.tableize}_report instead"
42
+ else
43
+ ActiveSupport::Deprecation.warn "Profile#load_report('#{name}',options) has been deprecated, use Profile##{name.tableize}_report(options) instead"
44
+ end
45
+ create_report(name, options={})
34
46
  end
35
47
 
36
- def report(options={})
48
+ def get_report_csv(options={})
37
49
  options.reverse_merge!({
38
50
  :report => 'Dashboard',
39
51
  :from => Time.now.utc - 7.days,
@@ -65,19 +77,19 @@ module Rugalytics
65
77
  end
66
78
 
67
79
  def pageviews(options={})
68
- load_report('Pageviews',options).page_views_total
80
+ pageviews_report(options).page_views_total
69
81
  end
70
82
 
71
83
  def pageviews_by_day(options={})
72
- load_report('Pageviews',options).page_views_by_day
84
+ pageviews_report(options).page_views_by_day
73
85
  end
74
86
 
75
87
  def visits(options={})
76
- load_report('Visits',options).visits_total
88
+ visits_report(options).visits_total
77
89
  end
78
90
 
79
91
  def visits_by_day(options={})
80
- load_report('Visits',options).visits_by_day
92
+ visits_report(options).visits_by_day
81
93
  end
82
94
 
83
95
  # takes a Date, Time or String
@@ -91,26 +103,11 @@ module Rugalytics
91
103
  end
92
104
 
93
105
  private
94
- def get_item_summary_by_message(options={})
95
- raise ArgumentError unless options.has_key?(:message)
96
- message = options.delete(:message).to_s.capitalize
97
- response = report(options.merge({:report => 'Dashboard'}))
98
- doc = Hpricot::XML(response)
99
- pageviews = (doc/:ItemSummary).detect { |summary| summary.at('Message').inner_html == message }
100
- pageviews && pageviews.at('SummaryValue') ? pageviews.at('SummaryValue').inner_html.gsub(/\D/, '').to_i : 0
101
- end
102
106
 
103
- def get_serie_by_label(options={})
104
- raise ArgumentError unless options.has_key?(:label)
105
- label = options.delete(:label).to_s.capitalize
106
- response = report(options.merge({:report => 'Dashboard'}))
107
- doc = Hpricot::XML(response)
108
- serie = (doc/:Serie).detect { |serie| serie.at('Label').inner_html == label }
109
- if serie
110
- (serie/:Point).inject([]) { |collection, point| collection << [Date.parse(point.at('Label').inner_html), point.at('Value').inner_html.to_i] }
111
- else
112
- []
113
- end
107
+ def create_report(name, options={})
108
+ report = Rugalytics::Report.new get_report_csv(options.merge({:report=>name}))
109
+ puts report.attribute_names
110
+ report
114
111
  end
115
112
  end
116
113
  end
data/lib/rugalytics.rb CHANGED
@@ -11,7 +11,7 @@ require 'yaml'
11
11
 
12
12
  # See README for usage documentation.
13
13
  module Rugalytics
14
- VERSION = "0.0.4"
14
+ VERSION = "0.0.5"
15
15
 
16
16
  FORMAT_PDF = '0' unless defined? FORMAT_PDF
17
17
  FORMAT_XML = '1' unless defined? FORMAT_XML
data/rugalytics.gemspec CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Rugalytics-0.0.4
2
+ # Gem::Specification for Rugalytics-0.0.5
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: rugalytics
7
7
  version: !ruby/object:Gem::Version
8
- version: 0.0.4
8
+ version: 0.0.5
9
9
  platform: ruby
10
10
  authors:
11
11
  - Rob McKinnon
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-08-01 00:00:00 +01:00
15
+ date: 2008-08-03 00:00:00 +01:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -3,22 +3,18 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  describe Rugalytics::Profile do
4
4
 
5
5
  describe "being initialized" do
6
-
7
6
  it "should accept :name as key" do
8
- a = Rugalytics::Profile.new(:name => 'test', :profile_id => '12341234')
9
- a.name.should == 'test'
7
+ profile = Rugalytics::Profile.new(:name => 'test', :profile_id => '12341234')
8
+ profile.name.should == 'test'
10
9
  end
11
-
12
10
  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'
11
+ profile = Rugalytics::Profile.new(:account_id => '12341234', :profile_id => '12341234')
12
+ profile.account_id.should == '12341234'
15
13
  end
16
-
17
14
  it "should accept :profile_id as key" do
18
- a = Rugalytics::Profile.new(:profile_id => '12341234')
19
- a.profile_id.should == '12341234'
15
+ profile = Rugalytics::Profile.new(:profile_id => '12341234')
16
+ profile.profile_id.should == '12341234'
20
17
  end
21
-
22
18
  end
23
19
 
24
20
  describe "finding by account id and profile id" do
@@ -35,37 +31,68 @@ describe Rugalytics::Profile do
35
31
  end
36
32
 
37
33
  describe 'finding pageviews' do
34
+ before do
35
+ @profile = Rugalytics::Profile.new :profile_id=>123
36
+ @report = mock('report',:page_views_total=>100)
37
+ end
38
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
39
+ @profile.should_receive(:pageviews_report).with({}).and_return @report
40
+ @profile.pageviews.should == @report.page_views_total
42
41
  end
43
42
  describe 'when from and to dates are specified' do
44
43
  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
44
+ options = {:from=>'2008-05-01', :to=>'2008-05-03'}
45
+ @profile.should_receive(:pageviews_report).with(options).and_return @report
46
+ @profile.pageviews(options).should == @report.page_views_total
51
47
  end
52
48
  end
53
49
  end
54
50
 
55
51
  describe 'finding visits' do
52
+ before do
53
+ @profile = Rugalytics::Profile.new :profile_id=>123
54
+ @report = mock('report', :visits_total=>100)
55
+ end
56
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
57
+ @profile.should_receive(:visits_report).with({}).and_return @report
58
+ @profile.visits.should == @report.visits_total
60
59
  end
61
60
  describe 'when from and to dates are specified' do
62
61
  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
62
+ options = {:from=>'2008-05-01', :to=>'2008-05-03'}
63
+ @profile.should_receive(:visits_report).with(options).and_return @report
64
+ @profile.visits(options).should == @report.visits_total
65
+ end
66
+ end
67
+ end
68
+
69
+ describe 'finding report when called with method ending in _report' do
70
+ before do
71
+ @profile = Rugalytics::Profile.new :profile_id=>123
72
+ @report = mock('report', :visits_total=>100)
73
+ end
74
+ it 'should find report using create_report method' do
75
+ @profile.should_receive(:create_report).with('Visits',{}).and_return @report
76
+ @profile.visits_report.should == @report
77
+ end
78
+ it 'should find instantiate report with report csv' do
79
+ csv = 'csv'
80
+ @profile.should_receive(:get_report_csv).with({:report=>'Visits'}).and_return csv
81
+ @report.stub!(:attribute_names).and_return ''
82
+ Rugalytics::Report.should_receive(:new).with(csv).and_return @report
83
+ @profile.visits_report.should == @report
84
+ end
85
+ describe 'when report name is two words' do
86
+ it 'should find report using create_report method' do
87
+ @profile.should_receive(:create_report).with('VisitorsOverview',{}).and_return @report
88
+ @profile.visitors_overview_report.should == @report
89
+ end
90
+ end
91
+ describe 'when dates are given' do
92
+ it 'should find report using create_report method passing date options' do
93
+ options = {:from=>'2008-05-01', :to=>'2008-05-03'}
94
+ @profile.should_receive(:create_report).with('Visits', options).and_return @report
95
+ @profile.visits_report(options).should == @report
69
96
  end
70
97
  end
71
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugalytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob McKinnon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-01 00:00:00 +01:00
12
+ date: 2008-08-03 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency