rugalytics 0.0.2 → 0.0.3
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 +2 -0
- data/Manifest +1 -1
- data/lib/rugalytics/item.rb +4 -1
- data/lib/rugalytics.rb +45 -10
- data/rugalytics.gemspec +6 -6
- data/rugalytics.yml.example +5 -0
- data/spec/lib/rugalytics/item_spec.rb +1 -0
- data/spec/lib/rugalytics_spec.rb +101 -19
- metadata +4 -4
- data/lib/rugalytics/analytics.rb +0 -0
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
lib/rugalytics/account.rb
|
3
|
-
lib/rugalytics/analytics.rb
|
4
3
|
lib/rugalytics/connection.rb
|
5
4
|
lib/rugalytics/graph.rb
|
6
5
|
lib/rugalytics/item.rb
|
@@ -11,6 +10,7 @@ LICENSE
|
|
11
10
|
Manifest
|
12
11
|
README
|
13
12
|
README.rdoc
|
13
|
+
rugalytics.yml.example
|
14
14
|
spec/fixtures/analytics_account_find_all.html
|
15
15
|
spec/fixtures/analytics_profile_find_all.html
|
16
16
|
spec/fixtures/dashboard_report_webgroup.xml
|
data/lib/rugalytics/item.rb
CHANGED
data/lib/rugalytics.rb
CHANGED
@@ -7,10 +7,11 @@ require 'hpricot'
|
|
7
7
|
require 'activesupport'
|
8
8
|
require 'google/base'
|
9
9
|
require 'morph'
|
10
|
+
require 'yaml'
|
10
11
|
|
11
12
|
# See README for usage documentation.
|
12
13
|
module Rugalytics
|
13
|
-
VERSION = "0.0.
|
14
|
+
VERSION = "0.0.3"
|
14
15
|
|
15
16
|
FORMAT_PDF = '0' unless defined? FORMAT_PDF
|
16
17
|
FORMAT_XML = '1' unless defined? FORMAT_XML
|
@@ -29,16 +30,48 @@ module Rugalytics
|
|
29
30
|
class InvalidCredentials < Exception
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
class << self
|
34
|
+
def login username, password
|
35
|
+
Google::Base.establish_connection(username, password)
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_profile account_id_or_name, profile_id_or_name=nil
|
39
|
+
begin
|
40
|
+
Profile.find account_id_or_name, profile_id_or_name
|
41
|
+
rescue NameError => e
|
42
|
+
raise 'No connection - call Rugalytics.login(<username>,<password>)'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def default_profile
|
47
|
+
config_setup '.' unless config
|
48
|
+
if config && config.account
|
49
|
+
begin
|
50
|
+
find_profile config.account, config.profile
|
51
|
+
rescue Exception => e
|
52
|
+
if e.to_s.include? 'No connection'
|
53
|
+
login config.username, config.password if config.username && config.password
|
54
|
+
find_profile config.account, config.profile
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
35
59
|
|
36
|
-
|
37
|
-
|
38
|
-
Profile.find account_id_or_name, profile_id_or_name
|
39
|
-
rescue NameError => e
|
40
|
-
raise 'No connection - call Rugalytics.login(<username>,<password>)'
|
60
|
+
def config
|
61
|
+
@config
|
41
62
|
end
|
63
|
+
|
64
|
+
def config_setup root
|
65
|
+
config_file = "#{root}/config/rugalytics.yml"
|
66
|
+
config_file = "#{root}/rugalytics.yml" unless File.exist? config_file
|
67
|
+
@config = load_config(config_file) if File.exist? config_file
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_config filename
|
71
|
+
hash = YAML.load_file(filename)
|
72
|
+
OpenStruct.new(hash)
|
73
|
+
end
|
74
|
+
|
42
75
|
end
|
43
76
|
end
|
44
77
|
|
@@ -47,4 +80,6 @@ require File.dirname(__FILE__) + '/rugalytics/account'
|
|
47
80
|
require File.dirname(__FILE__) + '/rugalytics/profile'
|
48
81
|
require File.dirname(__FILE__) + '/rugalytics/report'
|
49
82
|
require File.dirname(__FILE__) + '/rugalytics/item'
|
50
|
-
require File.dirname(__FILE__) + '/rugalytics/graph'
|
83
|
+
require File.dirname(__FILE__) + '/rugalytics/graph'
|
84
|
+
|
85
|
+
# Rugalytics.config_setup(RAILS_ROOT) if defined?(RAILS_ROOT) && RAILS_ROOT
|
data/rugalytics.gemspec
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Rugalytics-0.0.
|
2
|
+
# Gem::Specification for Rugalytics-0.0.3
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{rugalytics}
|
7
|
-
s.version = "0.0.
|
7
|
+
s.version = "0.0.3"
|
8
8
|
|
9
9
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Rob McKinnon"]
|
13
|
-
s.date = %q{2008-06-
|
13
|
+
s.date = %q{2008-06-16}
|
14
14
|
s.description = %q{Rugalytics is a Ruby API for Google Analytics.}
|
15
15
|
s.email = ["rob ~@nospam@~ rubyforge.org"]
|
16
16
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README"]
|
17
|
-
s.files = ["CHANGELOG", "lib/rugalytics/account.rb", "lib/rugalytics/
|
17
|
+
s.files = ["CHANGELOG", "lib/rugalytics/account.rb", "lib/rugalytics/connection.rb", "lib/rugalytics/graph.rb", "lib/rugalytics/item.rb", "lib/rugalytics/profile.rb", "lib/rugalytics/report.rb", "lib/rugalytics.rb", "LICENSE", "Manifest", "README", "README.rdoc", "rugalytics.yml.example", "spec/fixtures/analytics_account_find_all.html", "spec/fixtures/analytics_profile_find_all.html", "spec/fixtures/dashboard_report_webgroup.xml", "spec/lib/rugalytics/account_spec.rb", "spec/lib/rugalytics/graph_spec.rb", "spec/lib/rugalytics/item_spec.rb", "spec/lib/rugalytics/profile_spec.rb", "spec/lib/rugalytics/report_spec.rb", "spec/lib/rugalytics_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "rugalytics.gemspec"]
|
18
18
|
s.has_rdoc = true
|
19
19
|
s.homepage = %q{}
|
20
20
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rugalytics", "--main", "README", "--inline-source"]
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency(%q<hpricot>, [">= 0.6"])
|
27
27
|
s.add_dependency(%q<activesupport>, [">= 2.0.2"])
|
28
28
|
s.add_dependency(%q<googlebase>, [">= 0.2.0"])
|
29
|
-
s.add_dependency(%q<morph>, [">= 0.
|
29
|
+
s.add_dependency(%q<morph>, [">= 0.2.0"])
|
30
30
|
end
|
31
31
|
|
32
32
|
|
@@ -44,7 +44,7 @@ end
|
|
44
44
|
# m.rubyforge_name = "rugalytics"
|
45
45
|
# m.rdoc_options << '--inline-source'
|
46
46
|
# m.rdoc_pattern = ["README", "CHANGELOG", "LICENSE"]
|
47
|
-
# m.dependencies = ["hpricot >=0.6", "activesupport >=2.0.2", "googlebase >=0.2.0", "morph >=0.
|
47
|
+
# m.dependencies = ["hpricot >=0.6", "activesupport >=2.0.2", "googlebase >=0.2.0", "morph >=0.2.0"]
|
48
48
|
# end
|
49
49
|
#
|
50
50
|
# rescue LoadError
|
@@ -12,6 +12,7 @@ describe Rugalytics::Item, 'when creating' do
|
|
12
12
|
item = Rugalytics::Item.new @attributes.split(','), @values.split(','), @url
|
13
13
|
|
14
14
|
item.url.should == 'http://theyworkforyou.co.nz/'
|
15
|
+
item.path.should == '/'
|
15
16
|
item.page_views.should == '189'
|
16
17
|
item.unique_page_views.should == '157'
|
17
18
|
item.time_on_page.should == '54.94957983193277'
|
data/spec/lib/rugalytics_spec.rb
CHANGED
@@ -2,32 +2,114 @@ require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe Rugalytics do
|
4
4
|
|
5
|
-
describe "finding a profile
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
describe "finding a profile" do
|
6
|
+
|
7
|
+
describe "by its account name and profile name" do
|
8
|
+
it 'should return the match' do
|
9
|
+
account_name = 'your_site.com'
|
10
|
+
profile_name = 'blog.your_site.com'
|
11
|
+
profile = mock('profile')
|
12
|
+
Rugalytics::Profile.should_receive(:find).with(account_name, profile_name).and_return profile
|
13
|
+
Rugalytics::find_profile(account_name, profile_name).should == profile
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "by its account_id and profile_id" do
|
18
|
+
it 'should return the match' do
|
19
|
+
account_id = 1254221
|
20
|
+
profile_id = 12341234
|
21
|
+
profile = mock('profile')
|
22
|
+
Rugalytics::Profile.should_receive(:find).with(account_id, profile_id).and_return profile
|
23
|
+
Rugalytics::find_profile(account_id, profile_id).should == profile
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "by passing single name when account and profile name are the same" do
|
28
|
+
it 'should return the match' do
|
29
|
+
name = 'your_site.com'
|
30
|
+
profile = mock('profile')
|
31
|
+
Rugalytics::Profile.should_receive(:find).with(name, nil).and_return profile
|
32
|
+
Rugalytics::find_profile(name).should == profile
|
33
|
+
end
|
12
34
|
end
|
13
35
|
end
|
14
36
|
|
15
|
-
describe
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
37
|
+
describe 'when RAILS_ROOT is nil' do
|
38
|
+
|
39
|
+
it 'should not call config_setup method' do
|
40
|
+
Rugalytics.should_not_receive(:config_setup)
|
41
|
+
load(File.dirname(__FILE__) + '/../../lib/rugalytics.rb')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'when RAILS_ROOT is defined and not nil' do
|
46
|
+
|
47
|
+
before do
|
48
|
+
@rails_root = '.'
|
49
|
+
@config_file = "#{@rails_root}/config/rugalytics.yml"
|
50
|
+
@alt_config_file = "#{@rails_root}/rugalytics.yml"
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should look for rugalytics.yml file' do
|
54
|
+
File.should_receive(:exist?).with(@config_file).and_return false
|
55
|
+
File.should_receive(:exist?).with(@alt_config_file).and_return false
|
56
|
+
Rugalytics.config_setup(@rails_root)
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'and config/rugalytics.yml is present' do
|
60
|
+
before do
|
61
|
+
File.stub!(:exist?).with(@config_file).and_return true
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should load config' do
|
65
|
+
Rugalytics.should_receive(:load_config).with(@config_file).and_return mock('config')
|
66
|
+
Rugalytics.config_setup(@rails_root)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should save username and password if in credentials' do
|
70
|
+
user = 'user'
|
71
|
+
password = 'password'
|
72
|
+
Rugalytics.stub!(:load_config).and_return OpenStruct.new({:username => user, :password => password})
|
73
|
+
Rugalytics.config_setup(@rails_root)
|
74
|
+
Rugalytics.config.username.should == user
|
75
|
+
Rugalytics.config.password.should == password
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should save profile if in credentials' do
|
79
|
+
profile = 'profile'
|
80
|
+
account = 'account'
|
81
|
+
Rugalytics.stub!(:load_config).and_return OpenStruct.new({:profile => profile, :account => account})
|
82
|
+
Rugalytics.config_setup(@rails_root)
|
83
|
+
Rugalytics.config.account.should == account
|
84
|
+
Rugalytics.config.profile.should == profile
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should load config file using Yaml' do
|
88
|
+
file = 'file'
|
89
|
+
hash = mock('hash')
|
90
|
+
YAML.should_receive(:load_file).with(file).and_return hash
|
91
|
+
OpenStruct.should_receive(:new).with(hash)
|
92
|
+
Rugalytics.load_config(file)
|
93
|
+
end
|
94
|
+
|
95
|
+
# it 'should call config_setup method' do
|
96
|
+
# RAILS_ROOT = '.'
|
97
|
+
# Rugalytics.should_receive(:config_setup).with(RAILS_ROOT)
|
98
|
+
# load(File.dirname(__FILE__) + '/../../lib/rugalytics.rb')
|
99
|
+
# RAILS_ROOT = nil
|
100
|
+
# end
|
101
|
+
|
22
102
|
end
|
23
103
|
end
|
24
104
|
|
25
|
-
describe "finding
|
26
|
-
it 'should
|
27
|
-
name = 'your_site.com'
|
105
|
+
describe "finding default profile when config has been set" do
|
106
|
+
it 'should find profile using config' do
|
28
107
|
profile = mock('profile')
|
29
|
-
|
30
|
-
|
108
|
+
profile_name = 'profile'
|
109
|
+
account = 'account'
|
110
|
+
Rugalytics.stub!(:config).and_return mock('config', :account=>account, :profile=>profile_name)
|
111
|
+
Rugalytics.should_receive(:find_profile).with(account,profile_name).and_return profile
|
112
|
+
Rugalytics.default_profile.should == profile
|
31
113
|
end
|
32
114
|
end
|
33
115
|
|
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
|
+
version: 0.0.3
|
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-06-
|
12
|
+
date: 2008-06-16 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.
|
49
|
+
version: 0.2.0
|
50
50
|
version:
|
51
51
|
description: Rugalytics is a Ruby API for Google Analytics.
|
52
52
|
email:
|
@@ -62,7 +62,6 @@ extra_rdoc_files:
|
|
62
62
|
files:
|
63
63
|
- CHANGELOG
|
64
64
|
- lib/rugalytics/account.rb
|
65
|
-
- lib/rugalytics/analytics.rb
|
66
65
|
- lib/rugalytics/connection.rb
|
67
66
|
- lib/rugalytics/graph.rb
|
68
67
|
- lib/rugalytics/item.rb
|
@@ -73,6 +72,7 @@ files:
|
|
73
72
|
- Manifest
|
74
73
|
- README
|
75
74
|
- README.rdoc
|
75
|
+
- rugalytics.yml.example
|
76
76
|
- spec/fixtures/analytics_account_find_all.html
|
77
77
|
- spec/fixtures/analytics_profile_find_all.html
|
78
78
|
- spec/fixtures/dashboard_report_webgroup.xml
|
data/lib/rugalytics/analytics.rb
DELETED
File without changes
|