legato 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +6 -4
- data/lib/legato.rb +1 -0
- data/lib/legato/filter.rb +8 -3
- data/lib/legato/management/account.rb +6 -7
- data/lib/legato/management/goal.rb +9 -13
- data/lib/legato/management/model.rb +26 -0
- data/lib/legato/management/profile.rb +2 -12
- data/lib/legato/management/web_property.rb +2 -12
- data/lib/legato/model.rb +11 -10
- data/lib/legato/query.rb +25 -18
- data/lib/legato/version.rb +1 -1
- data/spec/lib/legato/filter_spec.rb +9 -4
- data/spec/lib/legato/model_spec.rb +4 -4
- data/spec/lib/legato/query_spec.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57fdae39cb4c7cbf5275ecf85ebac7130edf5a9f
|
4
|
+
data.tar.gz: d0a991e8ff4c2136ffe2e4cbe0a15919d62acac4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97dcdeb45f4a6e56db5e6793811bb9bc3cae3760fa6f3ae5fe0aef56075c1d7a2db1b5ea92bd87571f6b60360a51185874cabd83d287623d502bf37f676f9ea8
|
7
|
+
data.tar.gz: 7a79a0bf57d303944b3bf32e7fe3a950d3956a4068fbeeeeb6f56f08494196645b0fa54bfe5d6060879d40109ed59186ea2f48fb02fc83fd69c7c60abb99e4a5
|
data/CHANGELOG.md
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -11,12 +11,14 @@ Examples of unacceptable behavior by participants include:
|
|
11
11
|
* Trolling or insulting/derogatory comments
|
12
12
|
* Public or private harassment
|
13
13
|
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
14
|
-
* Other unethical or unprofessional conduct
|
14
|
+
* Other unethical or unprofessional conduct
|
15
15
|
|
16
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct
|
16
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
17
|
+
|
18
|
+
By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
17
19
|
|
18
20
|
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
19
21
|
|
20
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
|
22
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting a project maintainer at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Maintainers are obligated to maintain confidentiality with regard to the reporter of an incident.
|
21
23
|
|
22
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.
|
24
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.3.0, available at [http://contributor-covenant.org/version/1/3/0/](http://contributor-covenant.org/version/1/3/0/)
|
data/lib/legato.rb
CHANGED
data/lib/legato/filter.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Legato
|
2
2
|
class Filter
|
3
|
-
attr_accessor :field, :operator, :value, :join_character
|
3
|
+
attr_accessor :field, :operator, :value, :join_character
|
4
4
|
|
5
5
|
OPERATORS = {
|
6
6
|
# metrics
|
@@ -21,12 +21,17 @@ module Legato
|
|
21
21
|
# :descending => '-'
|
22
22
|
}
|
23
23
|
|
24
|
-
def initialize(field, operator, value, join_character
|
24
|
+
def initialize(query, field, operator, value, join_character)
|
25
|
+
@query = query
|
26
|
+
|
25
27
|
self.field = field
|
26
28
|
self.operator = operator
|
27
29
|
self.value = value
|
28
30
|
self.join_character = join_character # if nil, will be overridden by Query#apply_filter
|
29
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
def tracking_scope
|
34
|
+
@query.tracking_scope
|
30
35
|
end
|
31
36
|
|
32
37
|
def google_field
|
@@ -11,15 +11,14 @@ module Legato
|
|
11
11
|
"/accounts/#{id}"
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
GA_ATTRIBUTES = {
|
15
|
+
:id => 'id',
|
16
|
+
:name => 'name'
|
17
|
+
}
|
16
18
|
|
17
|
-
|
18
|
-
self.user = user
|
19
|
+
include Model
|
19
20
|
|
20
|
-
|
21
|
-
self.name = attributes['name'] || attributes[:name]
|
22
|
-
end
|
21
|
+
attr_writer :web_properties
|
23
22
|
|
24
23
|
def web_properties
|
25
24
|
@web_properties ||= WebProperty.for_account(self)
|
@@ -12,19 +12,15 @@ module Legato
|
|
12
12
|
self.class.default_path + "/" + id.to_s
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
['id', 'name', 'accountId', 'webPropertyId', 'profileId'].each { |key| attributes.delete(key) }
|
26
|
-
self.attributes = attributes
|
27
|
-
end
|
15
|
+
GA_ATTRIBUTES = {
|
16
|
+
:id => 'id',
|
17
|
+
:name => 'name',
|
18
|
+
:account_id => 'accountId',
|
19
|
+
:web_property_id => 'webPropertyId',
|
20
|
+
:profile_id => 'profileId'
|
21
|
+
}
|
22
|
+
|
23
|
+
include Model
|
28
24
|
|
29
25
|
def self.for_account(account)
|
30
26
|
all(account.user, account.path+'/webproperties/~all/profiles/~all/goals')
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Legato
|
2
|
+
module Management
|
3
|
+
module Model
|
4
|
+
|
5
|
+
def self.included(model)
|
6
|
+
model.class_eval do
|
7
|
+
attr_accessor *model::GA_ATTRIBUTES.keys
|
8
|
+
attr_accessor :user, :attributes
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(attributes, user)
|
13
|
+
self.user = user
|
14
|
+
self.attributes = attributes
|
15
|
+
|
16
|
+
build(attributes)
|
17
|
+
end
|
18
|
+
|
19
|
+
def build(attributes)
|
20
|
+
self.class::GA_ATTRIBUTES.each do |key,string_key|
|
21
|
+
self.send("#{key}=", attributes.delete(string_key) || attributes.delete(key))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -20,19 +20,9 @@ module Legato
|
|
20
20
|
:web_property_id => 'webPropertyId'
|
21
21
|
}
|
22
22
|
|
23
|
-
|
24
|
-
attr_accessor :user, :attributes
|
25
|
-
attr_writer :account, :web_property
|
26
|
-
|
27
|
-
def initialize(attributes, user)
|
28
|
-
self.user = user
|
29
|
-
|
30
|
-
GA_ATTRIBUTES.each do |key,string_key|
|
31
|
-
self.send("#{key}=", attributes.delete(string_key) || attributes.delete(key))
|
32
|
-
end
|
23
|
+
include Model
|
33
24
|
|
34
|
-
|
35
|
-
end
|
25
|
+
attr_writer :account, :web_property
|
36
26
|
|
37
27
|
def self.for_account(account)
|
38
28
|
all(account.user, account.path+'/webproperties/~all/profiles')
|
@@ -18,19 +18,9 @@ module Legato
|
|
18
18
|
:website_url => 'websiteUrl'
|
19
19
|
}
|
20
20
|
|
21
|
-
|
22
|
-
attr_accessor :user, :attributes
|
23
|
-
attr_writer :account, :profiles
|
24
|
-
|
25
|
-
def initialize(attributes, user)
|
26
|
-
self.user = user
|
27
|
-
|
28
|
-
GA_ATTRIBUTES.each do |key,string_key|
|
29
|
-
self.send("#{key}=", attributes.delete(string_key) || attributes.delete(key))
|
30
|
-
end
|
21
|
+
include Model
|
31
22
|
|
32
|
-
|
33
|
-
end
|
23
|
+
attr_writer :account, :profiles
|
34
24
|
|
35
25
|
def self.for_account(account)
|
36
26
|
all(account.user, account.path+'/webproperties')
|
data/lib/legato/model.rb
CHANGED
@@ -33,16 +33,13 @@ module Legato
|
|
33
33
|
# parameters used for filtering the request to GA
|
34
34
|
# @return [Proc] the body of newly defined method
|
35
35
|
def filter(name, &block)
|
36
|
-
|
37
|
-
|
38
|
-
(class << self; self; end).instance_eval do
|
39
|
-
define_method(name) {|*args| Query.new(self).apply_filter(*args, &block)}
|
40
|
-
end
|
36
|
+
add_method_to_set(name, :filters, &block)
|
41
37
|
end
|
42
38
|
|
43
39
|
def segments
|
44
40
|
@segments ||= {}
|
45
41
|
end
|
42
|
+
alias :segment_filters :segments
|
46
43
|
|
47
44
|
# Define a segment
|
48
45
|
#
|
@@ -51,11 +48,7 @@ module Legato
|
|
51
48
|
# parameters used for segmenting the request to GA
|
52
49
|
# @return [Proc] the body of newly defined method
|
53
50
|
def segment(name, &block)
|
54
|
-
|
55
|
-
|
56
|
-
(class << self; self; end).instance_eval do
|
57
|
-
define_method(name) {|*args| Query.new(self).apply_segment_filter(*args, &block)}
|
58
|
-
end
|
51
|
+
add_method_to_set(name, :segment_filters, &block)
|
59
52
|
end
|
60
53
|
|
61
54
|
# Set the class used to make new instances of returned results from GA
|
@@ -96,5 +89,13 @@ module Legato
|
|
96
89
|
def realtime
|
97
90
|
Query.new(self).realtime
|
98
91
|
end
|
92
|
+
|
93
|
+
def add_method_to_set(name, type, &block)
|
94
|
+
send(type)[name] = block
|
95
|
+
|
96
|
+
(class << self; self; end).instance_eval do
|
97
|
+
define_method(name) {|*args| Query.new(self).apply_filter_expression(type, *args, &block)}
|
98
|
+
end
|
99
|
+
end
|
99
100
|
end
|
100
101
|
end
|
data/lib/legato/query.rb
CHANGED
@@ -32,7 +32,7 @@ module Legato
|
|
32
32
|
methods.each do |method|
|
33
33
|
class_eval <<-CODE
|
34
34
|
def #{method}(field, value, join_character=nil)
|
35
|
-
Filter.new(field, :#{method}, value, join_character)
|
35
|
+
Filter.new(self, field, :#{method}, value, join_character)
|
36
36
|
end
|
37
37
|
CODE
|
38
38
|
end
|
@@ -79,6 +79,9 @@ module Legato
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def apply_filter_expression(filter_set, *args, &block)
|
82
|
+
# if given :filters or :segment_filters, make a set
|
83
|
+
filter_set = send(filter_set) if filter_set.is_a?(Symbol)
|
84
|
+
|
82
85
|
@profile = extract_profile(args)
|
83
86
|
|
84
87
|
join_character = Legato.and_join_character # filters are joined by AND
|
@@ -233,25 +236,13 @@ module Legato
|
|
233
236
|
end
|
234
237
|
|
235
238
|
def to_params
|
236
|
-
|
237
|
-
'ids' => profile_id,
|
238
|
-
'start-date' => Legato.format_time(start_date),
|
239
|
-
'end-date' => Legato.format_time(end_date),
|
240
|
-
'max-results' => limit,
|
241
|
-
'start-index' => offset,
|
242
|
-
'segment' => segment_id || segment,
|
243
|
-
'filters' => filters.to_params, # defaults to AND filtering
|
244
|
-
'fields' => REQUEST_FIELDS,
|
245
|
-
'quotaUser' => quota_user,
|
246
|
-
'userIp' => user_ip,
|
247
|
-
'samplingLevel' => sampling_level
|
248
|
-
}
|
239
|
+
base_params.tap do |params|
|
249
240
|
|
250
|
-
|
251
|
-
|
252
|
-
|
241
|
+
[metrics, dimensions, sort].compact.each do |list|
|
242
|
+
params.merge!(list.to_params(tracking_scope))
|
243
|
+
end
|
253
244
|
|
254
|
-
|
245
|
+
end
|
255
246
|
end
|
256
247
|
|
257
248
|
def to_query_string
|
@@ -268,6 +259,22 @@ module Legato
|
|
268
259
|
|
269
260
|
private
|
270
261
|
|
262
|
+
def base_params
|
263
|
+
{
|
264
|
+
'ids' => profile_id,
|
265
|
+
'start-date' => Legato.format_time(start_date),
|
266
|
+
'end-date' => Legato.format_time(end_date),
|
267
|
+
'max-results' => limit,
|
268
|
+
'start-index' => offset,
|
269
|
+
'segment' => segment_id || segment,
|
270
|
+
'filters' => filters.to_params, # defaults to AND filtering
|
271
|
+
'fields' => REQUEST_FIELDS,
|
272
|
+
'quotaUser' => quota_user,
|
273
|
+
'userIp' => user_ip,
|
274
|
+
'samplingLevel' => sampling_level
|
275
|
+
}.reject! {|_,v| v.nil? || v.to_s.strip.length == 0}
|
276
|
+
end
|
277
|
+
|
271
278
|
def tracking_scope_valid?
|
272
279
|
VALID_TRACKING_SCOPES.keys.include?(tracking_scope)
|
273
280
|
end
|
data/lib/legato/version.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Legato::Filter do
|
4
|
+
let(:klass) { Class.new.tap { |k| k.extend(Legato::Model)} }
|
5
|
+
let(:query) { Legato::Query.new(klass) }
|
6
|
+
|
4
7
|
context "a Filter instance with mcf" do
|
5
8
|
before :each do
|
6
|
-
|
9
|
+
query.tracking_scope = 'mcf'
|
10
|
+
|
11
|
+
@filter = Legato::Filter.new(query, :exits, :lt, 1000, nil)
|
7
12
|
end
|
8
13
|
|
9
14
|
it 'represents itself as a parameter' do
|
@@ -11,14 +16,14 @@ describe Legato::Filter do
|
|
11
16
|
end
|
12
17
|
|
13
18
|
it 'joins with another filter' do
|
14
|
-
filter2 = Legato::Filter.new(:pageviews, :gt, 1000, ','
|
19
|
+
filter2 = Legato::Filter.new(query, :pageviews, :gt, 1000, ',')
|
15
20
|
filter2.join_with(@filter.to_param).should == "mcf:exits<1000,mcf:pageviews>1000"
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
19
24
|
context "a Filter instance" do
|
20
25
|
before :each do
|
21
|
-
@filter = Legato::Filter.new(:exits, :lt, 1000, nil)
|
26
|
+
@filter = Legato::Filter.new(query, :exits, :lt, 1000, nil)
|
22
27
|
end
|
23
28
|
|
24
29
|
it 'has a field' do
|
@@ -52,7 +57,7 @@ describe Legato::Filter do
|
|
52
57
|
end
|
53
58
|
|
54
59
|
it 'joins with another filter' do
|
55
|
-
filter2 = Legato::Filter.new(:pageviews, :gt, 1000, ',')
|
60
|
+
filter2 = Legato::Filter.new(query, :pageviews, :gt, 1000, ',')
|
56
61
|
|
57
62
|
filter2.join_with(@filter.to_param).should == "ga:exits<1000,ga:pageviews>1000"
|
58
63
|
end
|
@@ -72,14 +72,14 @@ describe "Legato::Model" do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'returns a Query instance for a filter' do
|
75
|
-
query = stub(:
|
75
|
+
query = stub(:apply_filter_expression => "a query")
|
76
76
|
Legato::Query.stubs(:new).returns(query)
|
77
77
|
|
78
78
|
@model.filter :high, &@block
|
79
79
|
@model.high('arg1').should == 'a query'
|
80
80
|
|
81
81
|
Legato::Query.should have_received(:new).with(@model)
|
82
|
-
query.should have_received(:
|
82
|
+
query.should have_received(:apply_filter_expression).with(:filters, 'arg1')
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -99,14 +99,14 @@ describe "Legato::Model" do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'returns a Query instance for a segment' do
|
102
|
-
query = stub(:
|
102
|
+
query = stub(:apply_filter_expression => "a query")
|
103
103
|
Legato::Query.stubs(:new).returns(query)
|
104
104
|
|
105
105
|
@model.segment :high, &@block
|
106
106
|
@model.high('arg1').should == 'a query'
|
107
107
|
|
108
108
|
Legato::Query.should have_received(:new).with(@model)
|
109
|
-
query.should have_received(:
|
109
|
+
query.should have_received(:apply_filter_expression).with(:segment_filters, 'arg1')
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -10,7 +10,7 @@ describe Legato::Query do
|
|
10
10
|
it "returns a new filter for #{operator} to the set" do
|
11
11
|
Legato::Filter.stubs(:new).returns("a filter")
|
12
12
|
filter = @query.send(operator, :key, 2000)
|
13
|
-
Legato::Filter.should have_received(:new).with(:key, operator, 2000, nil)
|
13
|
+
Legato::Filter.should have_received(:new).with(@query, :key, operator, 2000, nil)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -205,7 +205,7 @@ describe Legato::Query do
|
|
205
205
|
|
206
206
|
context 'when applying filters' do
|
207
207
|
before :each do
|
208
|
-
@filter = Legato::Filter.new(:key, :eql, 1000, nil)
|
208
|
+
@filter = Legato::Filter.new(query, :key, :eql, 1000, nil)
|
209
209
|
query.stubs(:eql).returns(@filter)
|
210
210
|
|
211
211
|
@filters = stub(:<<)
|
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
|
+
version: 0.7.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:
|
11
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- lib/legato/management/account_summary.rb
|
155
155
|
- lib/legato/management/finder.rb
|
156
156
|
- lib/legato/management/goal.rb
|
157
|
+
- lib/legato/management/model.rb
|
157
158
|
- lib/legato/management/profile.rb
|
158
159
|
- lib/legato/management/query.rb
|
159
160
|
- lib/legato/management/segment.rb
|