statwhore 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +1 -0
- data/Manifest.txt +1 -0
- data/examples/profiles.rb +40 -0
- data/lib/statwhore/google/analytics/profile.rb +33 -8
- data/lib/statwhore/version.rb +1 -1
- data/spec/statwhore_google_analytics_profile_spec.rb +20 -0
- metadata +3 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/statwhore'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
include Statwhore::Google::Analytics
|
6
|
+
|
7
|
+
logger = Logger.new('../log/debug.log')
|
8
|
+
config = YAML::load(open(ENV["HOME"] + '/.statwhore'))
|
9
|
+
Google::Base.establish_connection(config[:username], config[:password])
|
10
|
+
|
11
|
+
class Site < OpenStruct; end
|
12
|
+
|
13
|
+
live = [
|
14
|
+
Site.new(:account => 344381, :profile => 3939049, :name => 'ace'),
|
15
|
+
Site.new(:account => 344381, :profile => 4804412, :name => 'admissions'),
|
16
|
+
Site.new(:account => 344381, :profile => 6345870, :name => 'building_communities'),
|
17
|
+
Site.new(:account => 344381, :profile => 8071820, :name => 'campus_ministry'),
|
18
|
+
Site.new(:account => 344381, :profile => 4505702, :name => 'career'),
|
19
|
+
Site.new(:account => 344381, :profile => 5190819, :name => 'committees'),
|
20
|
+
Site.new(:account => 344381, :profile => 3090719, :name => 'conductor'),
|
21
|
+
Site.new(:account => 344381, :profile => 4900769, :name => 'enlighten'),
|
22
|
+
Site.new(:account => 344381, :profile => 5190683, :name => 'green'),
|
23
|
+
Site.new(:account => 344381, :profile => 5309061, :name => 'issa'),
|
24
|
+
Site.new(:account => 344381, :profile => 1027308, :name => 'law'),
|
25
|
+
Site.new(:account => 344381, :profile => 8220615, :name => 'old2gold'),
|
26
|
+
Site.new(:account => 1254221, :profile => 2420755, :name => 'pray'),
|
27
|
+
Site.new(:account => 344381, :profile => 6085464, :name => 'summer_scholars'),
|
28
|
+
Site.new(:account => 344381, :profile => 4263845, :name => 'vocation'),
|
29
|
+
Site.new(:account => 344381, :profile => 543890, :name => 'webgroup')
|
30
|
+
]
|
31
|
+
|
32
|
+
# dates = {:from => Time.mktime(2007, 10, 1), :to => Time.now}
|
33
|
+
# dates = {:from => Time.mktime(2008, 1, 1), :to => Time.now}
|
34
|
+
dates = {:from => Time.mktime(2008, 4, 1), :to => Time.now}
|
35
|
+
puts live.inject(0) { |total, site|
|
36
|
+
views = Profile.find(site.account, site.profile).pageviews(dates)
|
37
|
+
puts "#{views} - #{site.name}"
|
38
|
+
total += views
|
39
|
+
total
|
40
|
+
}
|
@@ -50,17 +50,19 @@ module Statwhore
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def pageviews(options={})
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
get_item_summary_by_message(options.merge(:message => 'pageviews'))
|
54
|
+
end
|
55
|
+
|
56
|
+
def pageviews_by_day(options={})
|
57
|
+
get_serie_by_label(options.merge({:label => 'pageviews'}))
|
57
58
|
end
|
58
59
|
|
59
60
|
def visits(options={})
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
get_item_summary_by_message(options.merge(:message => 'visits'))
|
62
|
+
end
|
63
|
+
|
64
|
+
def visits_by_day(options={})
|
65
|
+
get_serie_by_label(options.merge({:label => 'visits'}))
|
64
66
|
end
|
65
67
|
|
66
68
|
# takes a Date, Time or String
|
@@ -71,6 +73,29 @@ module Statwhore
|
|
71
73
|
def to_s
|
72
74
|
"#{name} (#{profile_id})"
|
73
75
|
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def get_item_summary_by_message(options={})
|
79
|
+
raise ArgumentError unless options.has_key?(:message)
|
80
|
+
message = options.delete(:message).to_s.capitalize
|
81
|
+
response = report(options.merge({:report => 'Dashboard'}))
|
82
|
+
doc = Hpricot::XML(response)
|
83
|
+
pageviews = (doc/:ItemSummary).detect { |summary| summary.at('Message').inner_html == message }
|
84
|
+
pageviews && pageviews.at('SummaryValue') ? pageviews.at('SummaryValue').inner_html.gsub(/\D/, '').to_i : 0
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_serie_by_label(options={})
|
88
|
+
raise ArgumentError unless options.has_key?(:label)
|
89
|
+
label = options.delete(:label).to_s.capitalize
|
90
|
+
response = report(options.merge({:report => 'Dashboard'}))
|
91
|
+
doc = Hpricot::XML(response)
|
92
|
+
serie = (doc/:Serie).detect { |serie| serie.at('Label').inner_html == label }
|
93
|
+
if serie
|
94
|
+
(serie/:Point).inject([]) { |collection, point| collection << [Date.parse(point.at('Label').inner_html), point.at('Value').inner_html.to_i] }
|
95
|
+
else
|
96
|
+
[]
|
97
|
+
end
|
98
|
+
end
|
74
99
|
end
|
75
100
|
end
|
76
101
|
end
|
data/lib/statwhore/version.rb
CHANGED
@@ -35,6 +35,16 @@ describe "Statwhore::Google::Analytics::Profile" do
|
|
35
35
|
profile.pageviews.should == 283
|
36
36
|
end
|
37
37
|
|
38
|
+
it "should be able to get pageviews by day" do
|
39
|
+
profile = Statwhore::Google::Analytics::Profile.new(:account_id => 344381, :profile_id => 543890)
|
40
|
+
xml = open(File.dirname(__FILE__) + '/fixtures/dashboard_report_webgroup.xml').read
|
41
|
+
Statwhore::Google::Analytics::Profile.should_receive(:get).and_return(xml)
|
42
|
+
dates = profile.pageviews_by_day
|
43
|
+
dates.first.should == [Date.civil(2008, 2, 8), 72]
|
44
|
+
dates.last.should == [Date.civil(2008, 3, 9), 0]
|
45
|
+
dates.size.should == 31
|
46
|
+
end
|
47
|
+
|
38
48
|
it "should be able to get visits" do
|
39
49
|
profile = Statwhore::Google::Analytics::Profile.new(:account_id => 344381, :profile_id => 543890)
|
40
50
|
xml = open(File.dirname(__FILE__) + '/fixtures/dashboard_report_webgroup.xml').read
|
@@ -42,4 +52,14 @@ describe "Statwhore::Google::Analytics::Profile" do
|
|
42
52
|
profile.visits.should == 228
|
43
53
|
end
|
44
54
|
|
55
|
+
it "should be able to get visits by day" do
|
56
|
+
profile = Statwhore::Google::Analytics::Profile.new(:account_id => 344381, :profile_id => 543890)
|
57
|
+
xml = open(File.dirname(__FILE__) + '/fixtures/dashboard_report_webgroup.xml').read
|
58
|
+
Statwhore::Google::Analytics::Profile.should_receive(:get).and_return(xml)
|
59
|
+
dates = profile.visits_by_day
|
60
|
+
dates.first.should == [Date.civil(2008, 2, 8), 67]
|
61
|
+
dates.last.should == [Date.civil(2008, 3, 9), 0]
|
62
|
+
dates.size.should == 31
|
63
|
+
end
|
64
|
+
|
45
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statwhore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FIXME full name
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-05-
|
12
|
+
date: 2008-05-13 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- Rakefile
|
59
59
|
- config/hoe.rb
|
60
60
|
- config/requirements.rb
|
61
|
+
- examples/profiles.rb
|
61
62
|
- lib/statwhore.rb
|
62
63
|
- lib/statwhore/connection.rb
|
63
64
|
- lib/statwhore/google.rb
|