garb 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  class String
2
- def to_ga
2
+ def to_google_analytics
3
3
  "ga:#{self}"
4
4
  end
5
5
 
6
- def from_ga
6
+ def from_google_analytics
7
7
  self.gsub(/^ga\:/, '')
8
8
  end
9
9
  end
@@ -30,7 +30,7 @@ class Symbol
30
30
  :not_substring => '!@'
31
31
 
32
32
  # Metric filters
33
- def to_ga
34
- self.to_s.camelize(:lower).to_ga
33
+ def to_google_analytics
34
+ self.to_s.camelize(:lower).to_google_analytics
35
35
  end
36
36
  end
@@ -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"
@@ -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.to_ga
7
+ @target = target.to_google_analytics
8
8
  @operator = operator
9
9
  @prefix = prefix
10
10
  end
11
11
 
12
- def to_ga
12
+ def to_google_analytics
13
13
  @prefix ? "#{operator}#{target}" : "#{target}#{operator}"
14
14
  end
15
15
 
@@ -13,7 +13,7 @@ module Garb
13
13
  attribute :value, String
14
14
 
15
15
  def instance_name
16
- name.from_ga.underscore
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.from_ga
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
@@ -26,7 +26,7 @@ module Garb
26
26
  "#{k.target}#{URI.encode(k.operator.to_s, /[=<>]/)}#{CGI::escape(v.to_s)}"
27
27
  end.join(';')
28
28
  else
29
- elem.to_ga
29
+ elem.to_google_analytics
30
30
  end
31
31
  end.join(',')
32
32
 
@@ -3,7 +3,7 @@ module Garb
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -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
@@ -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, "=").to_ga
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, "=").to_ga
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).to_ga
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
@@ -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'.to_ga
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'.from_ga
10
+ assert_equal 'bob', 'ga:bob'.from_google_analytics
11
11
  end
12
12
  end
13
13
  end
@@ -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.to_ga
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.1
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
@@ -1,16 +0,0 @@
1
- class Array
2
- def group_to_array
3
- h = Hash.new
4
-
5
- each do |element|
6
- key = yield(element)
7
- if h.has_key?(key)
8
- h[key] << element
9
- else
10
- h[key] = [element]
11
- end
12
- end
13
-
14
- h.map{|k,v| v}
15
- end
16
- end