legato 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7f49997e495542d636ee2f1937c26f44a06f831
4
- data.tar.gz: 4bada052ee24bcd680f3ab0e236e407991771526
3
+ metadata.gz: c6894ffe83c0b0804d91e08de3ff8b6afddf03fc
4
+ data.tar.gz: 75f96f307e200111ab1cb3ef0925aa3c1fe5d189
5
5
  SHA512:
6
- metadata.gz: 9b32fd09f5268b038f2a39ce46b1cb2ea858d8bd7a776e5aa6094155f224a44610f5c75bbe656a8077f5373335ea93adcee3a2ca2d7bc04280130ac1037e1c44
7
- data.tar.gz: 1f7b6b5f9ce488bee564710ad499adfa9b80059b309f0fbf35019134fd1e728e8c7da04e2a68b7edfe2ed5c7aba660bba2946f81d36ca2914deaf32cbcdfe584
6
+ metadata.gz: 3d9acc61f35b61b73969fbe12dace66ac5b82552e9089186825acf3596ba5e6c1f2578883acb56ab5d33b3ebb54d06157dcf2e40a2a4651b9281babbcd7628fe
7
+ data.tar.gz: 822a73cbf77fa7c33a12f21a7c71309b946cd18c9ca4f06b145e132aefcb1712488db0937d5d92343b13f6cf3b2e1e55026e6e4224cc6eb444b927894ea8584a
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
3
  - 1.9.2
5
4
  - 1.9.3
6
5
  - 2.0.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Legato 0.5.0 ##
2
+
3
+ * Use Query#tracking_scope when converting `metrics`, `dimensions`, and `sort` list of parameters with `to_params`
4
+
5
+ *Tony Pitale*
6
+
1
7
  ## Legato 0.4.0 ##
2
8
 
3
9
  * Adds support to lookup parent `web_property` or `account` from a child `profile`.
data/README.md CHANGED
@@ -64,7 +64,7 @@ profile.user == user #=> true
64
64
  7. The profile can also lookup its "parent" Web Property
65
65
 
66
66
  ```ruby
67
- profile.web_propery
67
+ profile.web_property
68
68
  ```
69
69
 
70
70
  ## Google Analytics Model ##
data/lib/legato.rb CHANGED
@@ -25,7 +25,11 @@ module Legato
25
25
  end
26
26
 
27
27
  def self.format_time(t)
28
- t.strftime('%Y-%m-%d')
28
+ if t.is_a?(String)
29
+ t
30
+ else
31
+ t.strftime('%Y-%m-%d')
32
+ end
29
33
  end
30
34
 
31
35
  def self.and_join_character
@@ -1,12 +1,11 @@
1
1
  module Legato
2
2
  class ListParameter
3
3
 
4
- attr_reader :name, :elements, :tracking_scope
4
+ attr_reader :name
5
5
 
6
- def initialize(name, elements=[], tracking_scope = "ga")
6
+ def initialize(name, elements=[])
7
7
  @name = name
8
- @elements = Array.wrap(elements)
9
- @tracking_scope = tracking_scope
8
+ @elements = Set.new Array.wrap(elements).compact
10
9
  end
11
10
 
12
11
  def name
@@ -14,11 +13,15 @@ module Legato
14
13
  end
15
14
 
16
15
  def <<(element)
17
- (@elements += Array.wrap(element)).compact!
16
+ @elements += Array.wrap(element).compact
18
17
  self
19
18
  end
20
19
 
21
- def to_params
20
+ def elements
21
+ @elements.to_a
22
+ end
23
+
24
+ def to_params(tracking_scope)
22
25
  value = elements.map{|element| Legato.to_ga_string(element, tracking_scope)}.join(',')
23
26
  value.empty? ? {} : {name => value}
24
27
  end
data/lib/legato/model.rb CHANGED
@@ -9,8 +9,7 @@ module Legato
9
9
  # @param *fields [Symbol] the names of the fields to retrieve
10
10
  # @return [ListParameter] the set of all metrics
11
11
  def metrics(*fields)
12
- fields, options = options_from_fields(fields)
13
- @metrics ||= ListParameter.new(:metrics, [], options.fetch(:tracking_scope, "ga"))
12
+ @metrics ||= ListParameter.new(:metrics, [])
14
13
  @metrics << fields
15
14
  end
16
15
 
@@ -19,8 +18,7 @@ module Legato
19
18
  # @param *fields [Symbol] the names of the fields to retrieve
20
19
  # @return [ListParameter] the set of all dimensions
21
20
  def dimensions(*fields)
22
- fields, options = options_from_fields(fields)
23
- @dimensions ||= ListParameter.new(:dimensions, [], options.fetch(:tracking_scope, "ga"))
21
+ @dimensions ||= ListParameter.new(:dimensions, [])
24
22
  @dimensions << fields
25
23
  end
26
24
 
@@ -61,7 +59,7 @@ module Legato
61
59
  end
62
60
 
63
61
  # Set the class used to make new instances of returned results from GA
64
- #
62
+ #
65
63
  # @param klass [Class] any class that accepts a hash of attributes to
66
64
  # initialize the values of the class
67
65
  # @return the original class given
@@ -74,7 +72,7 @@ module Legato
74
72
  end
75
73
 
76
74
  # Builds a `query` to get results from GA
77
- #
75
+ #
78
76
  # @param profile [Legato::Management::Profile] the profile to query GA against
79
77
  # @param options [Hash] options:
80
78
  # * start_date
@@ -92,16 +90,10 @@ module Legato
92
90
  end
93
91
 
94
92
  # Builds a `query` and sets the `realtime` property
95
- #
93
+ #
96
94
  # @return [Query] a new query with `realtime` property set
97
95
  def realtime
98
96
  Query.new(self).realtime
99
97
  end
100
-
101
- def options_from_fields(fields)
102
- options = fields.pop if fields.last.is_a?(Hash)
103
- [fields, (options || {})]
104
- end
105
-
106
98
  end
107
99
  end
data/lib/legato/query.rb CHANGED
@@ -182,7 +182,7 @@ module Legato
182
182
  end
183
183
 
184
184
  def sort=(arr)
185
- @sort = Legato::ListParameter.new(:sort, arr, tracking_scope)
185
+ @sort = Legato::ListParameter.new(:sort, arr)
186
186
  end
187
187
 
188
188
  def segment
@@ -221,7 +221,7 @@ module Legato
221
221
  }
222
222
 
223
223
  [metrics, dimensions, sort].each do |list|
224
- params.merge!(list.to_params) unless list.nil?
224
+ params.merge!(list.to_params(tracking_scope)) unless list.nil?
225
225
  end
226
226
 
227
227
  params.reject {|k,v| v.nil? || v.to_s.strip.length == 0}
@@ -1,3 +1,3 @@
1
1
  module Legato
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -29,7 +29,7 @@ describe Legato::ListParameter do
29
29
 
30
30
  it 'converts itself to params' do
31
31
  @list_parameter << :pageviews
32
- @list_parameter.to_params.should == {"metrics" => "ga:exits,ga:pageviews"}
32
+ @list_parameter.to_params("ga").should == {"metrics" => "ga:exits,ga:pageviews"}
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -22,6 +22,13 @@ describe "Legato::Model" do
22
22
  @model.metrics.should == Legato::ListParameter.new(:metrics, [:exits, :pageviews])
23
23
  end
24
24
 
25
+ it 'does not add duplicated metrics' do
26
+ @model.metrics :exits
27
+ @model.metrics :exits
28
+ @model.metrics :exits, :exits
29
+ @model.metrics.should == Legato::ListParameter.new(:metrics, [:exits])
30
+ end
31
+
25
32
  it 'has a dimension' do
26
33
  @model.dimensions :browser
27
34
  @model.dimensions.should == Legato::ListParameter.new(:dimensions, [:browser])
@@ -32,6 +39,13 @@ describe "Legato::Model" do
32
39
  @model.dimensions.should == Legato::ListParameter.new(:dimensions, [:browser, :city])
33
40
  end
34
41
 
42
+ it 'does not add duplicated dimensions' do
43
+ @model.dimensions :browser
44
+ @model.dimensions :browser
45
+ @model.dimensions :browser, :browser
46
+ @model.dimensions.should == Legato::ListParameter.new(:dimensions, [:browser])
47
+ end
48
+
35
49
  it 'knows the instance class it should use' do
36
50
  klass = Class.new
37
51
  @model.set_instance_klass(klass)
@@ -386,6 +386,17 @@ describe Legato::Query do
386
386
  }
387
387
  end
388
388
 
389
+ it "supports string formatted dates" do
390
+ @query.start_date = "2014-01-01"
391
+ @query.end_date = "yesterday"
392
+
393
+ @query.to_params.should == {
394
+ 'start-date' => "2014-01-01",
395
+ 'end-date' => "yesterday",
396
+ 'fields' => Legato::Query::REQUEST_FIELDS,
397
+ }
398
+ end
399
+
389
400
  it 'includes the limit' do
390
401
  @query.limit = 1000
391
402
  @query.to_params['max-results'].should == 1000
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  version: '0'
205
205
  requirements: []
206
206
  rubyforge_project: legato
207
- rubygems_version: 2.2.2
207
+ rubygems_version: 2.4.5
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: Access the Google Analytics API with Ruby