garb 0.4.1 → 0.4.2
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/lib/extensions/string.rb +2 -2
- data/lib/extensions/symbol.rb +2 -2
- data/lib/garb.rb +1 -1
- data/lib/garb/operator.rb +2 -2
- data/lib/garb/profile.rb +4 -3
- data/lib/garb/profile_array.rb +18 -0
- data/lib/garb/report_parameter.rb +1 -1
- data/lib/garb/version.rb +1 -1
- data/test/unit/account_test.rb +1 -1
- data/test/unit/operator_test.rb +3 -3
- data/test/unit/string_test.rb +2 -2
- data/test/unit/symbol_test.rb +1 -1
- metadata +2 -2
- data/lib/extensions/array.rb +0 -16
data/lib/extensions/string.rb
CHANGED
data/lib/extensions/symbol.rb
CHANGED
data/lib/garb.rb
CHANGED
@@ -9,6 +9,7 @@ require 'happymapper'
|
|
9
9
|
require 'active_support'
|
10
10
|
|
11
11
|
require 'garb/version'
|
12
|
+
require 'garb/profile_array'
|
12
13
|
require 'garb/authentication_request'
|
13
14
|
require 'garb/data_request'
|
14
15
|
require 'garb/session'
|
@@ -22,7 +23,6 @@ require 'garb/operator'
|
|
22
23
|
|
23
24
|
require 'extensions/string'
|
24
25
|
require 'extensions/symbol'
|
25
|
-
require 'extensions/array'
|
26
26
|
|
27
27
|
module Garb
|
28
28
|
GA = "http://schemas.google.com/analytics/2008"
|
data/lib/garb/operator.rb
CHANGED
@@ -4,12 +4,12 @@ module Garb
|
|
4
4
|
attr_reader :target, :operator, :prefix
|
5
5
|
|
6
6
|
def initialize(target, operator, prefix=false)
|
7
|
-
@target = target.
|
7
|
+
@target = target.to_google_analytics
|
8
8
|
@operator = operator
|
9
9
|
@prefix = prefix
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def to_google_analytics
|
13
13
|
@prefix ? "#{operator}#{target}" : "#{target}#{operator}"
|
14
14
|
end
|
15
15
|
|
data/lib/garb/profile.rb
CHANGED
@@ -13,7 +13,7 @@ module Garb
|
|
13
13
|
attribute :value, String
|
14
14
|
|
15
15
|
def instance_name
|
16
|
-
name.
|
16
|
+
name.from_google_analytics.underscore
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -38,13 +38,14 @@ module Garb
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def id
|
41
|
-
@table_id.
|
41
|
+
@table_id.from_google_analytics
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.all
|
45
45
|
url = "https://www.google.com/analytics/feeds/accounts/default"
|
46
46
|
response = DataRequest.new(url).send_request
|
47
|
-
Entry.parse(response.body).map {|entry| new(entry)}
|
47
|
+
profiles = Entry.parse(response.body).map {|entry| new(entry)}
|
48
|
+
ProfileArray.new(profiles)
|
48
49
|
end
|
49
50
|
|
50
51
|
def self.first(id)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Garb
|
2
|
+
class ProfileArray < Array
|
3
|
+
def group_to_array
|
4
|
+
h = Hash.new
|
5
|
+
|
6
|
+
each do |element|
|
7
|
+
key = yield(element)
|
8
|
+
if h.has_key?(key)
|
9
|
+
h[key] << element
|
10
|
+
else
|
11
|
+
h[key] = [element]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
h.map{|k,v| v}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/garb/version.rb
CHANGED
data/test/unit/account_test.rb
CHANGED
@@ -6,7 +6,7 @@ module Garb
|
|
6
6
|
should "have an array of accounts with all profiles" do
|
7
7
|
p1 = stub(:account_id => '1111', :account_name => 'Blog 1')
|
8
8
|
p2 = stub(:account_id => '1112', :account_name => 'Blog 2')
|
9
|
-
Profile.stubs(:all).returns([p1,p2,p1,p2])
|
9
|
+
Profile.stubs(:all).returns(ProfileArray.new([p1,p2,p1,p2]))
|
10
10
|
Account.expects(:new).with([p1,p1]).returns('account1')
|
11
11
|
Account.expects(:new).with([p2,p2]).returns('account2')
|
12
12
|
assert_equal ['account1','account2'], Account.all
|
data/test/unit/operator_test.rb
CHANGED
@@ -4,15 +4,15 @@ module Garb
|
|
4
4
|
class OperatorTest < MiniTest::Unit::TestCase
|
5
5
|
context "An instance of an Operator" do
|
6
6
|
should "lower camelize the target" do
|
7
|
-
assert_equal "ga:uniqueVisits=", Operator.new(:unique_visits, "=").
|
7
|
+
assert_equal "ga:uniqueVisits=", Operator.new(:unique_visits, "=").to_google_analytics
|
8
8
|
end
|
9
9
|
|
10
10
|
should "return target and operator together" do
|
11
|
-
assert_equal "ga:metric=", Operator.new(:metric, "=").
|
11
|
+
assert_equal "ga:metric=", Operator.new(:metric, "=").to_google_analytics
|
12
12
|
end
|
13
13
|
|
14
14
|
should "prefix the operator to the target" do
|
15
|
-
assert_equal "-ga:metric", Operator.new(:metric, "-", true).
|
15
|
+
assert_equal "-ga:metric", Operator.new(:metric, "-", true).to_google_analytics
|
16
16
|
end
|
17
17
|
|
18
18
|
should "know if it is equal to another operator" do
|
data/test/unit/string_test.rb
CHANGED
@@ -3,11 +3,11 @@ require File.join(File.dirname(__FILE__), '..', '/test_helper')
|
|
3
3
|
class StringTest < MiniTest::Unit::TestCase
|
4
4
|
context "An instance of a String" do
|
5
5
|
should 'prefix a string with ga: for GA' do
|
6
|
-
assert_equal 'ga:bob', 'bob'.
|
6
|
+
assert_equal 'ga:bob', 'bob'.to_google_analytics
|
7
7
|
end
|
8
8
|
|
9
9
|
should 'remove ga: prefix' do
|
10
|
-
assert_equal 'bob', 'ga:bob'.
|
10
|
+
assert_equal 'bob', 'ga:bob'.from_google_analytics
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/test/unit/symbol_test.rb
CHANGED
@@ -5,7 +5,7 @@ class SymbolTest < MiniTest::Unit::TestCase
|
|
5
5
|
context "An instance of the Symbol class" do
|
6
6
|
|
7
7
|
should "properly format itself for ga" do
|
8
|
-
assert_equal "ga:requestUri", :request_uri.
|
8
|
+
assert_equal "ga:requestUri", :request_uri.to_google_analytics
|
9
9
|
end
|
10
10
|
|
11
11
|
should "define a :desc operator" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
@@ -44,7 +44,6 @@ extra_rdoc_files: []
|
|
44
44
|
files:
|
45
45
|
- README.md
|
46
46
|
- Rakefile
|
47
|
-
- lib/extensions/array.rb
|
48
47
|
- lib/extensions/string.rb
|
49
48
|
- lib/extensions/symbol.rb
|
50
49
|
- lib/garb/account.rb
|
@@ -53,6 +52,7 @@ files:
|
|
53
52
|
- lib/garb/oauth_session.rb
|
54
53
|
- lib/garb/operator.rb
|
55
54
|
- lib/garb/profile.rb
|
55
|
+
- lib/garb/profile_array.rb
|
56
56
|
- lib/garb/report.rb
|
57
57
|
- lib/garb/report_parameter.rb
|
58
58
|
- lib/garb/report_response.rb
|