legato 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +42 -0
- data/Gemfile +5 -0
- data/Rakefile +37 -1
- data/legato.gemspec +1 -1
- data/lib/legato/management/finder.rb +8 -0
- data/lib/legato/query.rb +5 -0
- data/lib/legato/user.rb +13 -7
- data/lib/legato/version.rb +1 -1
- data/spec/lib/legato/management/account_spec.rb +1 -1
- data/spec/support/examples/management_finder.rb +1 -1
- metadata +10 -9
data/CHANGELOG.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## Legato 0.0.3 ##
|
2
|
+
|
3
|
+
* Merged branch oauth-1-support
|
4
|
+
|
5
|
+
If you pass on an OAuth 1 (not 2, the default) token from the OAuth gem, Legato will use that.
|
6
|
+
Support for OAuth 2 is greater than OAuth 1 because of subtle and annoying differences in their operation.
|
7
|
+
|
8
|
+
*Tony Pitale*
|
9
|
+
|
10
|
+
## Legato 0.0.2 ##
|
11
|
+
|
12
|
+
* Specify request fields to slim down content returned
|
13
|
+
|
14
|
+
Include request fields columnHeaders/name, rows, totalResults, totalsForAllResults
|
15
|
+
|
16
|
+
*Patrick Roby*
|
17
|
+
|
18
|
+
* Add total results and totals_for_all_results to Query#load
|
19
|
+
|
20
|
+
*Patrick Roby*
|
21
|
+
|
22
|
+
* Change :order to :sort to match GA
|
23
|
+
|
24
|
+
*Patrick Roby*
|
25
|
+
|
26
|
+
* Add webPropertyId to Management::Profile
|
27
|
+
|
28
|
+
*Patrick Roby*
|
29
|
+
|
30
|
+
* Allow explicitly setting the join character on filters
|
31
|
+
|
32
|
+
*Tony Pitale*
|
33
|
+
|
34
|
+
* 1.8.7 Support
|
35
|
+
|
36
|
+
*Tony Pitale*
|
37
|
+
|
38
|
+
## Legato 0.0.1 ##
|
39
|
+
|
40
|
+
* Initial implementation
|
41
|
+
|
42
|
+
*Tony Pitale*
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
|
+
require 'oauth'
|
3
4
|
require 'oauth2'
|
4
5
|
|
5
6
|
# get oauth2 via device code, unimplemented as of now
|
@@ -8,7 +9,7 @@ require 'oauth2'
|
|
8
9
|
# curl -d "client_id={{client_id}}&client_secret={{client_secret}}&code=4/8O1xUKWzOdJESG7ednnulZPsbyNt&grant_type=http://oauth.net/grant_type/device/1.0" https://accounts.google.com/o/oauth2/token
|
9
10
|
# { "access_token" : "ERspXATXoblahblahblah", "token_type" : "Bearer", "expires_in" : 3600, "refresh_token" : "1/balhaajsdfklasfdjs;df" }
|
10
11
|
|
11
|
-
namespace :
|
12
|
+
namespace :oauth2 do
|
12
13
|
def client
|
13
14
|
# This is my test client account for Legato.
|
14
15
|
OAuth2::Client.new('779170787975.apps.googleusercontent.com', 'mbCISoZiSwyVQIDEbLj4EeEc', {
|
@@ -35,3 +36,38 @@ namespace :oauth do
|
|
35
36
|
puts access_token.token
|
36
37
|
end
|
37
38
|
end
|
39
|
+
|
40
|
+
namespace :oauth do
|
41
|
+
def consumer
|
42
|
+
OAuth::Consumer.new('779170787975.apps.googleusercontent.com', 'mbCISoZiSwyVQIDEbLj4EeEc', {
|
43
|
+
:site => "https://www.google.com",
|
44
|
+
:request_token_path => "/accounts/OAuthGetRequestToken",
|
45
|
+
:access_token_path => "/accounts/OAuthGetAccessToken",
|
46
|
+
:authorize_path => "/accounts/OAuthAuthorizeToken"
|
47
|
+
})
|
48
|
+
end
|
49
|
+
|
50
|
+
def request_token
|
51
|
+
@request_token ||= consumer.get_request_token({}, {:scope => "https://www.googleapis.com/auth/analytics.readonly"})
|
52
|
+
end
|
53
|
+
|
54
|
+
def auth_url
|
55
|
+
request_token.authorize_url
|
56
|
+
end
|
57
|
+
|
58
|
+
def access_token
|
59
|
+
@access_token ||= begin
|
60
|
+
print 'OAuth Code: '
|
61
|
+
code = $stdin.gets.strip
|
62
|
+
request_token.get_access_token(:oauth_verifier => code)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Get a new OAuth Token"
|
67
|
+
task :token do
|
68
|
+
`open "#{auth_url}"`
|
69
|
+
|
70
|
+
puts "Token: #{access_token.token}"
|
71
|
+
puts "Secret: #{access_token.secret}"
|
72
|
+
end
|
73
|
+
end
|
data/legato.gemspec
CHANGED
@@ -6,6 +6,14 @@ module Legato
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def all(user, path=default_path)
|
9
|
+
uri = if user.api_key
|
10
|
+
# oauth + api_key
|
11
|
+
base_uri + path + "?key=#{user.api_key}"
|
12
|
+
else
|
13
|
+
# oauth 2
|
14
|
+
base_uri + path
|
15
|
+
end
|
16
|
+
|
9
17
|
json = user.access_token.get(base_uri + path).body
|
10
18
|
MultiJson.decode(json)['items'].map {|item| new(item, user)}
|
11
19
|
end
|
data/lib/legato/query.rb
CHANGED
@@ -192,6 +192,11 @@ module Legato
|
|
192
192
|
params.reject {|k,v| v.nil? || v.to_s.strip.length == 0}
|
193
193
|
end
|
194
194
|
|
195
|
+
def to_query_string
|
196
|
+
list = to_params.map {|k,v| [k,v].join("=")}
|
197
|
+
"?#{list.join("&")}"
|
198
|
+
end
|
199
|
+
|
195
200
|
private
|
196
201
|
def request_for_query
|
197
202
|
profile.user.request(self)
|
data/lib/legato/user.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
module Legato
|
2
2
|
class User
|
3
|
-
attr_accessor :access_token
|
3
|
+
attr_accessor :access_token, :api_key
|
4
4
|
|
5
|
-
def initialize(token)
|
5
|
+
def initialize(token, api_key = nil)
|
6
6
|
self.access_token = token
|
7
|
+
self.api_key = api_key
|
7
8
|
end
|
8
9
|
|
9
10
|
URL = "https://www.googleapis.com/analytics/v3/data/ga"
|
10
11
|
|
11
12
|
def request(query)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
raw_response = if api_key
|
14
|
+
# oauth 1 + api key
|
15
|
+
query_string = URI.escape(query.to_query_string, '<>') # may need to add !~@
|
16
|
+
|
17
|
+
access_token.get(URL + query_string + "&key=#{api_key}")
|
18
|
+
else
|
19
|
+
# oauth 2
|
20
|
+
access_token.get(URL, :params => query.to_params)
|
17
21
|
end
|
22
|
+
|
23
|
+
Response.new(raw_response)
|
18
24
|
end
|
19
25
|
|
20
26
|
# Management
|
data/lib/legato/version.rb
CHANGED
@@ -9,7 +9,7 @@ describe Legato::Management::Account do
|
|
9
9
|
it_behaves_like "a management finder"
|
10
10
|
|
11
11
|
it 'creates a new account instance from a hash of attributes' do
|
12
|
-
user = stub
|
12
|
+
user = stub(:api_key => nil)
|
13
13
|
account = Legato::Management::Account.new({"id" => 12345, "name" => "Account 1"}, user)
|
14
14
|
account.user.should == user
|
15
15
|
account.id.should == 12345
|
@@ -3,7 +3,7 @@ shared_examples_for "a management finder" do
|
|
3
3
|
MultiJson.stubs(:decode).returns({'items' => ['item1', 'item2']})
|
4
4
|
response = stub(:body => 'some json')
|
5
5
|
access_token = stub(:get => response)
|
6
|
-
user = stub(:access_token => access_token)
|
6
|
+
user = stub(:access_token => access_token, :api_key => nil)
|
7
7
|
described_class.stubs(:new).returns('thing1', 'thing2')
|
8
8
|
|
9
9
|
described_class.all(user).should == ['thing1', 'thing2']
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: legato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tony Pitale
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-17 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
requirements:
|
81
81
|
- - "="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
hash: -
|
83
|
+
hash: -3728883836
|
84
84
|
segments:
|
85
85
|
- 2
|
86
86
|
- 0
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- .gitignore
|
148
148
|
- .rspec
|
149
149
|
- .travis.yml
|
150
|
+
- CHANGELOG.md
|
150
151
|
- Gemfile
|
151
152
|
- README.md
|
152
153
|
- Rakefile
|
@@ -204,12 +205,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
204
205
|
requirements:
|
205
206
|
- - ">="
|
206
207
|
- !ruby/object:Gem::Version
|
207
|
-
hash:
|
208
|
+
hash: 57
|
208
209
|
segments:
|
209
210
|
- 1
|
210
|
-
-
|
211
|
-
-
|
212
|
-
version: 1.
|
211
|
+
- 8
|
212
|
+
- 7
|
213
|
+
version: 1.8.7
|
213
214
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
215
|
none: false
|
215
216
|
requirements:
|