autometal-piwik 0.4.4 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/LICENSE +4 -0
- data/README.md +88 -0
- data/Rakefile +33 -16
- data/VERSION +1 -0
- data/autometal-piwik.gemspec +39 -30
- data/lib/piwik.rb +2 -6
- data/lib/piwik/base.rb +52 -37
- data/lib/piwik/site.rb +87 -33
- data/lib/piwik/trackable.rb +5 -4
- data/lib/piwik/user.rb +18 -19
- data/script/console +1 -1
- data/test/files/config/example_piwik.yml +4 -0
- data/test/piwik_test.rb +64 -4
- data/test/test_helper.rb +6 -3
- metadata +37 -81
- data/License.txt +0 -20
- data/Manifest.txt +0 -20
- data/PostInstall.txt +0 -4
- data/README.rdoc +0 -92
- data/Todo.txt +0 -6
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -82
- data/setup.rb +0 -1585
- data/test/files/config/piwik.yml +0 -2
data/lib/piwik/trackable.rb
CHANGED
@@ -57,22 +57,23 @@ module Piwik
|
|
57
57
|
@@use_async = false
|
58
58
|
cattr_accessor :use_async
|
59
59
|
|
60
|
-
@@url = Piwik::Base.load_config_from_file[:piwik_url]
|
61
|
-
cattr_accessor :url
|
62
|
-
|
63
60
|
@@environments = ["production","development"]
|
64
61
|
cattr_accessor :environments
|
65
62
|
|
66
63
|
@@formats = [:html, :all]
|
67
64
|
cattr_accessor :formats
|
68
65
|
|
66
|
+
def self.url
|
67
|
+
Piwik.piwik_url
|
68
|
+
end
|
69
|
+
|
69
70
|
=begin rdoc
|
70
71
|
Checks whether the model can be tracked using piwik by checking for a piwik_id and domain fields.
|
71
72
|
This is a pretty specific use case, a more generic application tracking solution is available here:
|
72
73
|
https://github.com/Achillefs/piwik_analytics/ (this file is actually swiped from that plugin)
|
73
74
|
=end
|
74
75
|
def self.enabled?(format)
|
75
|
-
raise Piwik::MissingConfiguration if url.blank?
|
76
|
+
raise Piwik::MissingConfiguration if self.url.blank?
|
76
77
|
environments.include?(Rails.env) && formats.include?(format.to_sym)
|
77
78
|
end
|
78
79
|
end
|
data/lib/piwik/user.rb
CHANGED
@@ -18,7 +18,7 @@ module Piwik
|
|
18
18
|
def initialize(attributes={}, piwik_url=nil, auth_token=nil)
|
19
19
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
20
20
|
@config = if piwik_url.nil? || auth_token.nil?
|
21
|
-
self.class.
|
21
|
+
self.class.load_config
|
22
22
|
else
|
23
23
|
{:piwik_url => piwik_url, :auth_token => auth_token}
|
24
24
|
end
|
@@ -47,11 +47,12 @@ module Piwik
|
|
47
47
|
raise ArgumentError, "Email can not be blank" if email.blank?
|
48
48
|
user_alias = login if user_alias.blank?
|
49
49
|
|
50
|
-
|
51
|
-
result = parse_xml(xml)
|
50
|
+
result = call('UsersManager.addUser', :userLogin => login, :password => password, :email => email, :alias => user_alias)
|
52
51
|
@created_at = Time.current
|
53
|
-
|
54
|
-
|
52
|
+
#puts "\n create #{result} \n"
|
53
|
+
|
54
|
+
if result["result"]
|
55
|
+
result['message'] == 'ok' ? true : false
|
55
56
|
else
|
56
57
|
false
|
57
58
|
end
|
@@ -67,9 +68,8 @@ module Piwik
|
|
67
68
|
raise ArgumentError, "Email can not be blank" if email.blank?
|
68
69
|
user_alias = login if user_alias.blank?
|
69
70
|
|
70
|
-
|
71
|
-
result
|
72
|
-
result['success'] ? true : false
|
71
|
+
result = call('UsersManager.updateUser', :userLogin => login, :password => password, :email => email, :alias => user_alias)
|
72
|
+
result['result'] == 'success' ? true : false
|
73
73
|
end
|
74
74
|
|
75
75
|
# Deletes the current user from Piwik.
|
@@ -77,10 +77,9 @@ module Piwik
|
|
77
77
|
# Equivalent Piwik API call: UsersManager.deleteUser (userLogin)
|
78
78
|
def destroy
|
79
79
|
raise UnknownUser, "User not existent in Piwik yet, call 'save' first" if new?
|
80
|
-
|
81
|
-
result = parse_xml(xml)
|
80
|
+
result = call('UsersManager.deleteUser', :userLogin => login)
|
82
81
|
freeze
|
83
|
-
result['
|
82
|
+
result['result'] == 'success' ? true : false
|
84
83
|
end
|
85
84
|
|
86
85
|
# Returns an instance of <tt>Piwik::User</tt> representing the user identified by
|
@@ -95,7 +94,7 @@ module Piwik
|
|
95
94
|
def self.load(user_login, piwik_url=nil, auth_token=nil)
|
96
95
|
raise ArgumentError, "expected a user Login" if user_login.nil?
|
97
96
|
@config = if piwik_url.nil? || auth_token.nil?
|
98
|
-
|
97
|
+
load_config
|
99
98
|
else
|
100
99
|
{:piwik_url => piwik_url, :auth_token => auth_token}
|
101
100
|
end
|
@@ -118,14 +117,14 @@ module Piwik
|
|
118
117
|
#
|
119
118
|
# Equivalent Piwik API call: UsersManager.getUser (userLogin)
|
120
119
|
def self.get_user_attributes_by_login(user_login, piwik_url, auth_token)
|
121
|
-
|
122
|
-
result
|
120
|
+
result = call('UsersManager.getUser', {:userLogin => user_login}, piwik_url, auth_token)
|
121
|
+
#puts "\n get_user_attributes_by_login #{result} \n"
|
123
122
|
attributes = {
|
124
|
-
:login => result[
|
125
|
-
:user_alias => result[
|
126
|
-
:email => result[
|
127
|
-
:password => result[
|
128
|
-
:created_at => Time.parse(result[
|
123
|
+
:login => result[0]['login'],
|
124
|
+
:user_alias => result[0]['alias'],
|
125
|
+
:email => result[0]['email'],
|
126
|
+
:password => result[0]['password'],
|
127
|
+
:created_at => Time.parse(result[0]['date_registered'])
|
129
128
|
}
|
130
129
|
attributes
|
131
130
|
end
|
data/script/console
CHANGED
@@ -5,6 +5,6 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
5
5
|
libs = " -r irb/completion"
|
6
6
|
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
7
|
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/piwik.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/simple-piwik.rb'}"
|
9
9
|
puts "Loading piwik gem"
|
10
10
|
exec "#{irb} #{libs} --simple-prompt"
|
data/test/piwik_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__),"test_helper")
|
1
|
+
#require File.join(File.expand_path(File.dirname(__FILE__)),"test_helper")
|
2
|
+
require 'test_helper'
|
2
3
|
|
3
4
|
class PiwikTest < Test::Unit::TestCase
|
4
5
|
def setup
|
@@ -50,19 +51,78 @@ class PiwikTest < Test::Unit::TestCase
|
|
50
51
|
assert_equal true, @user.destroy
|
51
52
|
end
|
52
53
|
|
54
|
+
def test_unknown_site
|
55
|
+
assert_raises Piwik::UnknownSite do
|
56
|
+
Piwik::Site.load(0)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_get_javascript_tag
|
61
|
+
assert_equal nil, @site.id
|
62
|
+
@site.save
|
63
|
+
assert_not_equal 0, @site.id
|
64
|
+
assert_not_equal nil, @site.id
|
65
|
+
reloaded = Piwik::Site.load(@site.id)
|
66
|
+
assert_equal reloaded.id, @site.id
|
67
|
+
assert_equal 0, reloaded.get_javascript_tag =~ /^<!-- Piwik -->/
|
68
|
+
assert_equal true, reloaded.destroy
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_get_page_titles
|
72
|
+
assert_equal nil, @site.id
|
73
|
+
@site.save
|
74
|
+
assert_not_equal 0, @site.id
|
75
|
+
assert_not_equal nil, @site.id
|
76
|
+
#TODO: maybe make an actual website visit here, by calling the Piwik tracking REST api, so that Piwik actually records something and the test can become more accurate
|
77
|
+
reloaded = Piwik::Site.load(@site.id)
|
78
|
+
assert_equal reloaded.id, @site.id
|
79
|
+
assert_equal true, reloaded.get_page_titles!=nil
|
80
|
+
assert_equal true, reloaded.get_page_titles.kind_of?(Array)
|
81
|
+
assert_equal true, reloaded.destroy
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_get_page_urls
|
85
|
+
assert_equal nil, @site.id
|
86
|
+
@site.save
|
87
|
+
assert_not_equal 0, @site.id
|
88
|
+
assert_not_equal nil, @site.id
|
89
|
+
#TODO: maybe make an actual website visit here, by calling the Piwik tracking REST api, so that Piwik actually records something and the test can become more accurate
|
90
|
+
reloaded = Piwik::Site.load(@site.id)
|
91
|
+
assert_equal reloaded.id, @site.id
|
92
|
+
assert_equal true, reloaded.get_page_urls!=nil
|
93
|
+
assert_equal true, reloaded.get_page_urls.kind_of?(Array)
|
94
|
+
assert_equal true, reloaded.destroy
|
95
|
+
end
|
96
|
+
|
53
97
|
def test_can_read_standalone_config
|
54
98
|
File.open(File.join(ENV["HOME"],".piwik"), "w") { p.puts(File.read("./files/config/piwik/yml")) } unless File.join(ENV["HOME"],".piwik")
|
55
99
|
assert_nothing_raised do
|
56
|
-
Piwik::Base.
|
100
|
+
Piwik::Base.load_config
|
57
101
|
end
|
58
102
|
end
|
59
103
|
|
60
|
-
|
61
104
|
def test_can_read_rails_config
|
62
105
|
stub_rails_env do
|
63
106
|
assert_nothing_raised do
|
64
|
-
Piwik::Base.
|
107
|
+
Piwik::Base.load_config
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_can_be_configured
|
113
|
+
stub_rails_env do
|
114
|
+
#configuring manualy overrides the config file settings, if any
|
115
|
+
Piwik.piwik_url = "url"
|
116
|
+
Piwik.auth_token = "token"
|
117
|
+
assert_equal true, Piwik.is_configured?
|
118
|
+
assert_nothing_raised do
|
119
|
+
Piwik::Base.load_config
|
120
|
+
assert_equal "url", Piwik.piwik_url
|
121
|
+
assert_equal "token", Piwik.auth_token
|
65
122
|
end
|
123
|
+
Piwik.piwik_url = nil
|
124
|
+
Piwik.auth_token = nil
|
66
125
|
end
|
67
126
|
end
|
127
|
+
|
68
128
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
require 'piwik'
|
2
6
|
|
3
7
|
class Test::Unit::TestCase
|
4
8
|
def stub_rails_env &block
|
5
9
|
Object.const_set("RAILS_ROOT", File.join(File.dirname(__FILE__),"files"))
|
6
10
|
yield
|
7
|
-
Object.const_set("RAILS_ROOT",nil)
|
8
11
|
end
|
9
|
-
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autometal-piwik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 1
|
10
|
+
version: 0.6.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Achillefs Charmpilas
|
14
|
+
- mihael
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date:
|
19
|
+
date: 2013-01-05 00:00:00 +01:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -26,34 +27,18 @@ dependencies:
|
|
26
27
|
requirements:
|
27
28
|
- - ">="
|
28
29
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
30
|
+
hash: 21
|
30
31
|
segments:
|
31
|
-
- 2
|
32
32
|
- 3
|
33
|
-
- 8
|
34
|
-
version: 2.3.8
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: xml-simple
|
39
|
-
prerelease: false
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 1
|
46
|
-
segments:
|
47
|
-
- 1
|
48
33
|
- 0
|
49
|
-
-
|
50
|
-
version:
|
34
|
+
- 9
|
35
|
+
version: 3.0.9
|
51
36
|
type: :runtime
|
52
|
-
version_requirements: *
|
37
|
+
version_requirements: *id001
|
53
38
|
- !ruby/object:Gem::Dependency
|
54
39
|
name: rest-client
|
55
40
|
prerelease: false
|
56
|
-
requirement: &
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
57
42
|
none: false
|
58
43
|
requirements:
|
59
44
|
- - ">="
|
@@ -65,58 +50,38 @@ dependencies:
|
|
65
50
|
- 1
|
66
51
|
version: 1.6.1
|
67
52
|
type: :runtime
|
68
|
-
version_requirements: *
|
53
|
+
version_requirements: *id002
|
69
54
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
55
|
+
name: json
|
71
56
|
prerelease: false
|
72
|
-
requirement: &
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
73
58
|
none: false
|
74
59
|
requirements:
|
75
60
|
- - ">="
|
76
61
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
62
|
+
hash: 11
|
78
63
|
segments:
|
79
|
-
-
|
80
|
-
- 0
|
64
|
+
- 1
|
81
65
|
- 4
|
82
|
-
version: 2.0.4
|
83
|
-
type: :development
|
84
|
-
version_requirements: *id004
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: hoe
|
87
|
-
prerelease: false
|
88
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ">="
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
hash: 19
|
94
|
-
segments:
|
95
|
-
- 2
|
96
66
|
- 6
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
email:
|
103
|
-
- ac@humbuckercode.co.uk
|
67
|
+
version: 1.4.6
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id003
|
70
|
+
description: Provides simple access to the Piwik API.
|
71
|
+
email: ac@humbuckercode.co.uk
|
104
72
|
executables: []
|
105
73
|
|
106
74
|
extensions: []
|
107
75
|
|
108
76
|
extra_rdoc_files:
|
109
|
-
-
|
110
|
-
-
|
111
|
-
- PostInstall.txt
|
112
|
-
- Todo.txt
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
113
79
|
files:
|
114
|
-
-
|
115
|
-
-
|
116
|
-
-
|
117
|
-
- README.rdoc
|
80
|
+
- .document
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
118
83
|
- Rakefile
|
119
|
-
-
|
84
|
+
- VERSION
|
120
85
|
- autometal-piwik.gemspec
|
121
86
|
- lib/piwik.rb
|
122
87
|
- lib/piwik/base.rb
|
@@ -124,25 +89,16 @@ files:
|
|
124
89
|
- lib/piwik/trackable.rb
|
125
90
|
- lib/piwik/user.rb
|
126
91
|
- script/console
|
127
|
-
-
|
128
|
-
- script/generate
|
129
|
-
- script/txt2html
|
130
|
-
- setup.rb
|
131
|
-
- test/files/config/piwik.yml
|
92
|
+
- test/files/config/example_piwik.yml
|
132
93
|
- test/piwik_test.rb
|
133
94
|
- test/test_helper.rb
|
134
95
|
has_rdoc: true
|
135
|
-
homepage:
|
96
|
+
homepage: https://github.com/Achillefs/autometal-piwik
|
136
97
|
licenses: []
|
137
98
|
|
138
|
-
post_install_message:
|
139
|
-
|
140
|
-
|
141
|
-
http://github.com/Achillefs/piwik/
|
142
|
-
|
143
|
-
rdoc_options:
|
144
|
-
- --main
|
145
|
-
- README.rdoc
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
146
102
|
require_paths:
|
147
103
|
- lib
|
148
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -165,10 +121,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
121
|
version: "0"
|
166
122
|
requirements: []
|
167
123
|
|
168
|
-
rubyforge_project:
|
169
|
-
rubygems_version: 1.
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.6.1
|
170
126
|
signing_key:
|
171
127
|
specification_version: 3
|
172
|
-
summary: A
|
173
|
-
test_files:
|
174
|
-
|
128
|
+
summary: A ruby client for the Piwik API.
|
129
|
+
test_files: []
|
130
|
+
|
data/License.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2011 Achillefs Charmpilas - Humbucker Ltd (http://humbuckercode.co.uk/licks)
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
License.txt
|
2
|
-
Manifest.txt
|
3
|
-
PostInstall.txt
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
|
-
Todo.txt
|
7
|
-
autometal-piwik.gemspec
|
8
|
-
lib/piwik.rb
|
9
|
-
lib/piwik/base.rb
|
10
|
-
lib/piwik/site.rb
|
11
|
-
lib/piwik/trackable.rb
|
12
|
-
lib/piwik/user.rb
|
13
|
-
script/console
|
14
|
-
script/destroy
|
15
|
-
script/generate
|
16
|
-
script/txt2html
|
17
|
-
setup.rb
|
18
|
-
test/files/config/piwik.yml
|
19
|
-
test/piwik_test.rb
|
20
|
-
test/test_helper.rb
|