legato 0.3.3 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGEwNThlYTM2NzM2YTVlYTgxYmMxODFkMWEzNjEyM2QyYjg1NWI2Ng==
5
- data.tar.gz: !binary |-
6
- OGI3NzZlYzdlZmI3NzVlZDIxM2I0YWFkYjU5NzE5NGU2NDFmZGQzMw==
2
+ SHA1:
3
+ metadata.gz: b7f49997e495542d636ee2f1937c26f44a06f831
4
+ data.tar.gz: 4bada052ee24bcd680f3ab0e236e407991771526
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjgxODA4Nzg3YmVjNjZhNDMwMmE2ZTQ2Y2U3ZmExOTg0ZjQ1NDdjMjI3YjNh
10
- ZmNiNTk3ZjhkOWQ4OTJiY2ZiMGU2YTI2ZGU1MzUyYjAyYTBkZTViYjJlOTMy
11
- MDdlNWUzNTBiODI1ZjQ4MGJhNzhiMGM4N2U0YTU1NzcxNTVhZGU=
12
- data.tar.gz: !binary |-
13
- Y2E3ZDQxNmIyMDJkOTU3NmQzMmE0ZDA1MmJkNDY3ZGE5MGUyYjVhZmFiOGI0
14
- MWM0Y2E4YjJkY2EwNWNkNWFjN2NlM2Y4N2I2OWRhN2UxZGUwMDViYjc4MmJi
15
- MjY2OTI0MjNkZmIxZGM1MzUzNjBiODQ0NDQ0Yzg5ODY1M2M5MDY=
6
+ metadata.gz: 9b32fd09f5268b038f2a39ce46b1cb2ea858d8bd7a776e5aa6094155f224a44610f5c75bbe656a8077f5373335ea93adcee3a2ca2d7bc04280130ac1037e1c44
7
+ data.tar.gz: 1f7b6b5f9ce488bee564710ad499adfa9b80059b309f0fbf35019134fd1e728e8c7da04e2a68b7edfe2ed5c7aba660bba2946f81d36ca2914deaf32cbcdfe584
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Legato 0.4.0 ##
2
+
3
+ * Adds support to lookup parent `web_property` or `account` from a child `profile`.
4
+
1
5
  ## Legato 0.3.3 ##
2
6
 
3
7
  * Adds `realtime` to `Legato::Model`, returns `Query` with tracking_scope set for the realtime API
data/README.md CHANGED
@@ -61,6 +61,11 @@ profile = user.profiles.first
61
61
  profile.user == user #=> true
62
62
  ```
63
63
 
64
+ 7. The profile can also lookup its "parent" Web Property
65
+
66
+ ```ruby
67
+ profile.web_propery
68
+ ```
64
69
 
65
70
  ## Google Analytics Model ##
66
71
 
data/lib/legato/cli.rb CHANGED
@@ -26,10 +26,10 @@ module Legato
26
26
 
27
27
  class CLI
28
28
  def initialize
29
- path = File.join(ENV['HOME'], '.legato.yml')
29
+ config_path = File.join(ENV['HOME'], '.legato.yml')
30
30
 
31
- if File.exists?(path)
32
- @config = YAML.load_file(path) rescue {}
31
+ if File.exists?(config_path)
32
+ @config = YAML.load_file(config_path) rescue {}
33
33
  else
34
34
  puts "##########################################################"
35
35
  puts "We can auto-load OAuth2 config from ~/.legato.yml"
@@ -40,7 +40,7 @@ module Legato
40
40
 
41
41
  build_access_token
42
42
 
43
- print_yaml
43
+ print_yaml unless File.exists?(config_path)
44
44
  end
45
45
 
46
46
  def run
@@ -93,6 +93,10 @@ module Legato
93
93
 
94
94
  @access_token = client.auth_code.get_token(code, :redirect_uri => 'http://localhost')
95
95
  @config['token'] = @access_token.token
96
+
97
+ puts
98
+ print "Your oauth token is #{@config['token']}"
99
+ puts
96
100
  end
97
101
  end
98
102
 
@@ -15,8 +15,9 @@ module Legato
15
15
 
16
16
  def initialize(attributes, user)
17
17
  self.user = user
18
- self.id = attributes['id']
19
- self.name = attributes['name']
18
+
19
+ self.id = attributes['id'] || attributes[:id]
20
+ self.name = attributes['name'] || attributes[:name]
20
21
  end
21
22
 
22
23
  def web_properties
@@ -26,6 +27,10 @@ module Legato
26
27
  def profiles
27
28
  Profile.for_account(self)
28
29
  end
30
+
31
+ def self.from_child(child)
32
+ all(child.user).detect {|a| a.id == child.account_id}
33
+ end
29
34
  end
30
35
  end
31
36
  end
@@ -6,17 +6,28 @@ module Legato
6
6
  end
7
7
 
8
8
  def all(user, path=default_path)
9
- uri = if user.api_key
9
+ uri = uri_for_user(user, path)
10
+
11
+ json = user.access_token.get(uri).body
12
+ items = MultiJson.decode(json).fetch('items', [])
13
+ items.map {|item| new(item, user)}
14
+ end
15
+
16
+ def get(user, path)
17
+ uri = uri_for_user(user, path)
18
+ json = user.access_token.get(uri).body
19
+
20
+ new(MultiJson.decode(json), user)
21
+ end
22
+
23
+ def uri_for_user(user, path)
24
+ if user.api_key
10
25
  # oauth + api_key
11
26
  base_uri + path + "?key=#{user.api_key}"
12
27
  else
13
28
  # oauth 2
14
29
  base_uri + path
15
30
  end
16
-
17
- json = user.access_token.get(base_uri + path).body
18
- items = MultiJson.decode(json).fetch('items', [])
19
- items.map {|item| new(item, user)}
20
31
  end
21
32
  end
22
33
  end
@@ -13,16 +13,23 @@ module Legato
13
13
  "/accounts/#{account_id}/webproperties/#{web_property_id}/profiles/#{id}"
14
14
  end
15
15
 
16
- attr_accessor :id, :name, :web_property_id, :account_id, :user, :attributes
16
+ GA_ATTRIBUTES = {
17
+ :id => 'id',
18
+ :name => 'name',
19
+ :account_id => 'accountId',
20
+ :web_property_id => 'webPropertyId'
21
+ }
22
+
23
+ attr_accessor *GA_ATTRIBUTES.keys
24
+ attr_accessor :user, :attributes
17
25
 
18
26
  def initialize(attributes, user)
19
27
  self.user = user
20
- self.id = attributes['id']
21
- self.name = attributes['name']
22
- self.account_id = attributes['accountId']
23
- self.web_property_id = attributes['webPropertyId']
24
28
 
25
- ['id', 'name', 'accountId', 'webPropertyId'].each { |key| attributes.delete(key) }
29
+ GA_ATTRIBUTES.each do |key,string_key|
30
+ self.send("#{key}=", attributes.delete(string_key) || attributes.delete(key))
31
+ end
32
+
26
33
  self.attributes = attributes
27
34
  end
28
35
 
@@ -34,6 +41,14 @@ module Legato
34
41
  all(web_property.user, web_property.path+'/profiles')
35
42
  end
36
43
 
44
+ def account
45
+ @account ||= Account.from_child(self)
46
+ end
47
+
48
+ def web_property
49
+ @web_property ||= WebProperty.from_child(self)
50
+ end
51
+
37
52
  def goals
38
53
  Goal.for_profile(self)
39
54
  end
@@ -11,20 +11,43 @@ module Legato
11
11
  "/accounts/#{account_id}/webproperties/#{id}"
12
12
  end
13
13
 
14
- attr_accessor :id, :name, :website_url, :account_id, :user, :attributes
14
+ GA_ATTRIBUTES = {
15
+ :id => 'id',
16
+ :name => 'name',
17
+ :account_id => 'accountId',
18
+ :website_url => 'websiteUrl'
19
+ }
20
+
21
+ attr_accessor *GA_ATTRIBUTES.keys
22
+ attr_accessor :user, :attributes
15
23
 
16
24
  def initialize(attributes, user)
17
25
  self.user = user
18
- self.id = attributes['id']
19
- self.name = attributes.delete('name')
20
- self.website_url = attributes.delete('websiteUrl')
21
- self.account_id = attributes.delete('accountId')
26
+
27
+ GA_ATTRIBUTES.each do |key,string_key|
28
+ self.send("#{key}=", attributes.delete(string_key) || attributes.delete(key))
29
+ end
30
+
22
31
  self.attributes = attributes
23
32
  end
24
33
 
25
34
  def self.for_account(account)
26
35
  all(account.user, account.path+'/webproperties')
27
36
  end
37
+
38
+ def profiles
39
+ Profile.for_web_property(self)
40
+ end
41
+
42
+ def account
43
+ @account ||= Account.from_child(self)
44
+ end
45
+
46
+ def self.from_child(child)
47
+ path = new({:id => child.web_property_id, :account_id => child.account_id}, nil).path
48
+
49
+ get(child.user, path)
50
+ end
28
51
  end
29
52
  end
30
53
  end
@@ -1,3 +1,3 @@
1
1
  module Legato
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -15,6 +15,12 @@ describe Legato::Management::Account do
15
15
  account.id.should == 12345
16
16
  account.name.should == "Account 1"
17
17
  end
18
+
19
+ it 'finds an instance from a child management instance' do
20
+ user = stub(:api_key => nil)
21
+ profile = Legato::Management::Profile.new({:account_id => 123}, user)
22
+ # account = Legato::Management::Account
23
+ end
18
24
  end
19
25
 
20
26
  context "An Account instance" do
@@ -1,29 +1,50 @@
1
1
  shared_examples_for "a management finder" do
2
2
  let(:response) { stub(:body => 'some json') }
3
- let(:access_token) { access_token = stub(:get => response) }
3
+ let(:access_token) { stub(:get => response) }
4
4
  let(:user) { stub(:access_token => access_token, :api_key => nil) }
5
5
 
6
- after do
7
- user.should have_received(:access_token)
8
- access_token.should have_received(:get).with('https://www.googleapis.com/analytics/v3/management'+described_class.default_path)
9
- response.should have_received(:body)
10
- MultiJson.should have_received(:decode).with('some json')
11
- end
6
+ context ".all" do
7
+ after do
8
+ user.should have_received(:access_token)
9
+ access_token.should have_received(:get).with('https://www.googleapis.com/analytics/v3/management'+described_class.default_path)
10
+ response.should have_received(:body)
11
+ MultiJson.should have_received(:decode).with('some json')
12
+ end
13
+
14
+ it "returns an array of all #{subject_class_name} available to a user" do
15
+ MultiJson.stubs(:decode).returns({'items' => ['item1', 'item2']})
16
+ described_class.stubs(:new).returns('thing1', 'thing2')
17
+
18
+ described_class.all(user).should == ['thing1', 'thing2']
12
19
 
13
- it "returns an array of all #{subject_class_name} available to a user" do
14
- MultiJson.stubs(:decode).returns({'items' => ['item1', 'item2']})
15
- described_class.stubs(:new).returns('thing1', 'thing2')
20
+ described_class.should have_received(:new).with('item1', user)
21
+ described_class.should have_received(:new).with('item2', user)
22
+ end
16
23
 
17
- described_class.all(user).should == ['thing1', 'thing2']
24
+ it "returns an empty array of #{subject_class_name} when there are no results" do
25
+ MultiJson.stubs(:decode).returns({})
26
+ described_class.all(user).should == []
18
27
 
19
- described_class.should have_received(:new).with('item1', user)
20
- described_class.should have_received(:new).with('item2', user)
28
+ described_class.should have_received(:new).never
29
+ end
21
30
  end
22
31
 
23
- it "returns an empty array of #{subject_class_name} when there are no results" do
24
- MultiJson.stubs(:decode).returns({})
25
- described_class.all(user).should == []
32
+ context ".get" do
33
+ after do
34
+ user.should have_received(:access_token)
35
+ access_token.should have_received(:get).with('https://www.googleapis.com/analytics/v3/management/path')
36
+ response.should have_received(:body)
37
+ MultiJson.should have_received(:decode).with('some json')
38
+ end
39
+
40
+ it "returns an instance of #{subject_class_name} for a given path" do
41
+ MultiJson.stubs(:decode).returns('attributes')
42
+ described_class.stubs(:new).returns('thing')
43
+
44
+ path = '/path'
26
45
 
27
- described_class.should have_received(:new).never
46
+ expect(described_class.get(user, path)).to eq('thing')
47
+ expect(described_class).to have_received(:new).with('attributes', user)
48
+ end
28
49
  end
29
- end
50
+ end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.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-08-01 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mocha
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bourne
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -84,42 +84,42 @@ dependencies:
84
84
  name: fakeweb
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: multi_json
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description: Access the Google Analytics Core Reporting and Management APIs with Ruby.
@@ -132,10 +132,10 @@ executables:
132
132
  extensions: []
133
133
  extra_rdoc_files: []
134
134
  files:
135
- - .gitignore
136
- - .rspec
137
- - .ruby-version
138
- - .travis.yml
135
+ - ".gitignore"
136
+ - ".rspec"
137
+ - ".ruby-version"
138
+ - ".travis.yml"
139
139
  - CHANGELOG.md
140
140
  - Gemfile
141
141
  - README.md
@@ -194,17 +194,17 @@ require_paths:
194
194
  - lib
195
195
  required_ruby_version: !ruby/object:Gem::Requirement
196
196
  requirements:
197
- - - ! '>='
197
+ - - ">="
198
198
  - !ruby/object:Gem::Version
199
199
  version: 1.8.7
200
200
  required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
- - - ! '>='
202
+ - - ">="
203
203
  - !ruby/object:Gem::Version
204
204
  version: '0'
205
205
  requirements: []
206
206
  rubyforge_project: legato
207
- rubygems_version: 2.2.1
207
+ rubygems_version: 2.2.2
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: Access the Google Analytics API with Ruby
@@ -233,4 +233,3 @@ test_files:
233
233
  - spec/spec_helper.rb
234
234
  - spec/support/examples/management_finder.rb
235
235
  - spec/support/macros/oauth.rb
236
- has_rdoc: