simple-piwik 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/piwik/base.rb +23 -9
- data/lib/piwik/site.rb +2 -2
- data/lib/piwik/trackable.rb +1 -1
- data/lib/piwik/user.rb +2 -2
- data/script/console +1 -1
- data/simple-piwik.gemspec +2 -2
- data/test/simple-piwik_test.rb +19 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
data/lib/piwik/base.rb
CHANGED
@@ -10,6 +10,13 @@ module Piwik
|
|
10
10
|
class UnknownSite < ArgumentError; end
|
11
11
|
class UnknownUser < ArgumentError; end
|
12
12
|
|
13
|
+
mattr_accessor :piwik_url
|
14
|
+
mattr_accessor :auth_token
|
15
|
+
|
16
|
+
def self.is_configured?
|
17
|
+
@@piwik_url!=nil && @@auth_token!=nil
|
18
|
+
end
|
19
|
+
|
13
20
|
class Base
|
14
21
|
@@template = <<-EOF
|
15
22
|
# .piwik
|
@@ -76,18 +83,25 @@ EOF
|
|
76
83
|
end
|
77
84
|
|
78
85
|
# Checks for the config, creates it if not found
|
79
|
-
def self.
|
86
|
+
def self.load_config
|
80
87
|
config = {}
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
+
if Piwik.is_configured?
|
89
|
+
config = { :piwik_url => Piwik.piwik_url, :auth_token => Piwik.auth_token }
|
90
|
+
else
|
91
|
+
config_file = self.config_file
|
92
|
+
if config_file
|
93
|
+
temp_config = if File.exists?(config_file)
|
94
|
+
YAML::load(open(config_file))
|
95
|
+
else
|
96
|
+
open(config_file,'w') { |f| f.puts @@template }
|
97
|
+
YAML::load(@@template)
|
98
|
+
end
|
99
|
+
temp_config.each { |k,v| config[k.to_sym] = v } if temp_config
|
88
100
|
end
|
89
|
-
temp_config.each { |k,v| config[k.to_sym] = v } if temp_config
|
90
101
|
raise MissingConfiguration, "Please edit #{config_file} to include piwik url and auth_key" if config[:piwik_url] == nil || config[:auth_token] == nil
|
102
|
+
#cache settings
|
103
|
+
Piwik.piwik_url = config[:piwik_url]
|
104
|
+
Piwik.auth_token = config[:auth_token]
|
91
105
|
end
|
92
106
|
config
|
93
107
|
end
|
data/lib/piwik/site.rb
CHANGED
@@ -16,7 +16,7 @@ module Piwik
|
|
16
16
|
def initialize(attributes={}, piwik_url=nil, auth_token=nil)
|
17
17
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
18
18
|
@config = if piwik_url.nil? || auth_token.nil?
|
19
|
-
self.class.
|
19
|
+
self.class.load_config
|
20
20
|
else
|
21
21
|
{:piwik_url => piwik_url, :auth_token => auth_token}
|
22
22
|
end
|
@@ -35,7 +35,7 @@ module Piwik
|
|
35
35
|
def self.load(site_id, piwik_url=nil, auth_token=nil)
|
36
36
|
raise ArgumentError, "expected a site Id" if site_id.nil?
|
37
37
|
@config = if piwik_url.nil? || auth_token.nil?
|
38
|
-
|
38
|
+
load_config
|
39
39
|
else
|
40
40
|
{:piwik_url => piwik_url, :auth_token => auth_token}
|
41
41
|
end
|
data/lib/piwik/trackable.rb
CHANGED
@@ -58,7 +58,7 @@ module Piwik
|
|
58
58
|
cattr_accessor :use_async
|
59
59
|
|
60
60
|
#at point of starting up a rails project Rails.root points to nil, and this config loading breakes a rails app
|
61
|
-
@@url = Piwik::Base.
|
61
|
+
@@url = Piwik::Base.load_config[:piwik_url]
|
62
62
|
cattr_accessor :url
|
63
63
|
|
64
64
|
@@environments = ["production","development"]
|
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
|
@@ -94,7 +94,7 @@ module Piwik
|
|
94
94
|
def self.load(user_login, piwik_url=nil, auth_token=nil)
|
95
95
|
raise ArgumentError, "expected a user Login" if user_login.nil?
|
96
96
|
@config = if piwik_url.nil? || auth_token.nil?
|
97
|
-
|
97
|
+
load_config
|
98
98
|
else
|
99
99
|
{:piwik_url => piwik_url, :auth_token => auth_token}
|
100
100
|
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/simple-piwik.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{simple-piwik}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{mihael}]
|
12
|
-
s.date = %q{2011-08-
|
12
|
+
s.date = %q{2011-08-09}
|
13
13
|
s.description = %q{Provides simple access to the Piwik API.}
|
14
14
|
s.email = %q{mihael.ploh@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/test/simple-piwik_test.rb
CHANGED
@@ -54,16 +54,32 @@ class PiwikTest < Test::Unit::TestCase
|
|
54
54
|
def test_can_read_standalone_config
|
55
55
|
File.open(File.join(ENV["HOME"],".piwik"), "w") { p.puts(File.read("./files/config/piwik/yml")) } unless File.join(ENV["HOME"],".piwik")
|
56
56
|
assert_nothing_raised do
|
57
|
-
Piwik::Base.
|
57
|
+
Piwik::Base.load_config
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
61
|
def test_can_read_rails_config
|
63
62
|
stub_rails_env do
|
64
63
|
assert_nothing_raised do
|
65
|
-
Piwik::Base.
|
64
|
+
Piwik::Base.load_config
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_can_be_configured
|
70
|
+
stub_rails_env do
|
71
|
+
#configuring manualy overrides the config file settings, if any
|
72
|
+
Piwik.piwik_url = "url"
|
73
|
+
Piwik.auth_token = "token"
|
74
|
+
assert_equal true, Piwik.is_configured?
|
75
|
+
assert_nothing_raised do
|
76
|
+
Piwik::Base.load_config
|
77
|
+
assert_equal "url", Piwik.piwik_url
|
78
|
+
assert_equal "token", Piwik.auth_token
|
66
79
|
end
|
80
|
+
Piwik.piwik_url = nil
|
81
|
+
Piwik.auth_token = nil
|
67
82
|
end
|
68
83
|
end
|
84
|
+
|
69
85
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: simple-piwik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.5.
|
5
|
+
version: 0.5.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- mihael
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-08-
|
13
|
+
date: 2011-08-09 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|