legato 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ 1.9.3-p362
data/README.md CHANGED
@@ -144,6 +144,7 @@ Operators on dimensions:
144
144
  * :limit - The maximum number of results to be returned
145
145
  * :offset - The starting index
146
146
  * :sort - metric/dimension to sort by
147
+ * :quota_user - any arbitrary string that uniquely identifies a user (40 characters max)
147
148
 
148
149
  ## License ##
149
150
 
@@ -168,4 +169,4 @@ Operators on dimensions:
168
169
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
169
170
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
170
171
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
171
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
172
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,73 +1,100 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
2
3
 
3
4
  require 'oauth'
4
5
  require 'oauth2'
5
6
 
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
10
+
6
11
  # get oauth2 via device code, unimplemented as of now
7
12
  # curl -d "client_id={{client_id}}&scope=https://www.googleapis.com/auth/analytics.readonly" https://accounts.google.com/o/oauth2/device/code
8
13
  # { "device_code" : "4/8O1xUKWzOdJESG7ednnulZPsbyNt", "user_code" : "3tywhirg", "verification_url" : "http://www.google.com/device", "expires_in" : 1800, "interval" : 5 }
9
14
  # 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
10
15
  # { "access_token" : "ERspXATXoblahblahblah", "token_type" : "Bearer", "expires_in" : 3600, "refresh_token" : "1/balhaajsdfklasfdjs;df" }
11
16
 
12
- namespace :oauth2 do
13
- def client
17
+ module OAuth2Helpers
18
+ def build_client(id, secret)
14
19
  # This is my test client account for Legato.
15
- OAuth2::Client.new('779170787975.apps.googleusercontent.com', 'mbCISoZiSwyVQIDEbLj4EeEc', {
20
+ opts = {
16
21
  :authorize_url => 'https://accounts.google.com/o/oauth2/auth',
17
22
  :token_url => 'https://accounts.google.com/o/oauth2/token'
18
- })
23
+ }
24
+
25
+ OAuth2::Client.new(id, secret, opts)
19
26
  end
20
27
 
21
- def auth_url
28
+ def auth_url(client)
22
29
  client.auth_code.authorize_url({
23
30
  :scope => 'https://www.googleapis.com/auth/analytics.readonly',
24
31
  :redirect_uri => 'http://localhost'
25
32
  })
26
33
  end
27
34
 
35
+ extend self
36
+ end
37
+
38
+ namespace :oauth2 do
28
39
  desc "Get a new OAuth2 Token"
29
40
  task :token do
30
- `open "#{auth_url}"`
41
+ puts 'Get your OAuth2 id and secret from the API Console: https://code.google.com/apis/console#access'
42
+
43
+ puts
44
+ print 'Your OAuth2 id: '
45
+ oauth_id = $stdin.gets.strip
46
+ print 'Your OAuth2 secret: '
47
+ oauth_secret = $stdin.gets.strip
48
+
49
+ client = OAuth2Helpers.build_client(oauth_id, oauth_secret)
31
50
 
32
- print 'OAuth2 Code: '
33
- code = $stdin.gets
51
+ puts
52
+ puts "Opening the OAuth2 auth url: #{OAuth2Helpers.auth_url(client)} ..."
53
+ `open "#{OAuth2Helpers.auth_url(client)}"`
34
54
 
35
- access_token = client.auth_code.get_token(code.strip, :redirect_uri => 'http://localhost')
55
+ puts
56
+ print 'OAuth2 Code (in the url): '
57
+ code = $stdin.gets.strip
58
+
59
+ access_token = client.auth_code.get_token(code, :redirect_uri => 'http://localhost')
60
+
61
+ puts
62
+ puts "Here's your access token: "
36
63
  puts access_token.token
37
64
  end
38
65
  end
39
66
 
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
67
+ # namespace :oauth do
68
+ # def consumer(id, secret)
69
+ # OAuth::Consumer.new('779170787975.apps.googleusercontent.com', 'mbCISoZiSwyVQIDEbLj4EeEc', {
70
+ # :site => "https://www.google.com",
71
+ # :request_token_path => "/accounts/OAuthGetRequestToken",
72
+ # :access_token_path => "/accounts/OAuthGetAccessToken",
73
+ # :authorize_path => "/accounts/OAuthAuthorizeToken"
74
+ # })
75
+ # end
49
76
 
50
- def request_token
51
- @request_token ||= consumer.get_request_token({}, {:scope => "https://www.googleapis.com/auth/analytics.readonly"})
52
- end
77
+ # def request_token
78
+ # @request_token ||= consumer.get_request_token({}, {:scope => "https://www.googleapis.com/auth/analytics.readonly"})
79
+ # end
53
80
 
54
- def auth_url
55
- request_token.authorize_url
56
- end
81
+ # def auth_url
82
+ # request_token.authorize_url
83
+ # end
57
84
 
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
85
+ # def access_token
86
+ # @access_token ||= begin
87
+ # print 'OAuth Code: '
88
+ # code = $stdin.gets.strip
89
+ # request_token.get_access_token(:oauth_verifier => code)
90
+ # end
91
+ # end
65
92
 
66
- desc "Get a new OAuth Token"
67
- task :token do
68
- `open "#{auth_url}"`
93
+ # desc "Get a new OAuth Token"
94
+ # task :token do
95
+ # `open "#{auth_url}"`
69
96
 
70
- puts "Token: #{access_token.token}"
71
- puts "Secret: #{access_token.secret}"
72
- end
73
- end
97
+ # puts "Token: #{access_token.token}"
98
+ # puts "Secret: #{access_token.secret}"
99
+ # end
100
+ # end
@@ -4,7 +4,10 @@ require 'multi_json'
4
4
  require 'cgi'
5
5
  require 'ostruct'
6
6
 
7
- unless Object.const_defined?("ActiveSupport")
7
+ if Object.const_defined?("ActiveSupport")
8
+ require "active_support/core_ext/string"
9
+ require "active_support/core_ext/array"
10
+ else
8
11
  require "legato/core_ext/string"
9
12
  require "legato/core_ext/array"
10
13
  end
@@ -23,7 +23,7 @@ module Legato
23
23
 
24
24
  attr_reader :parent_klass
25
25
  attr_accessor :profile, :start_date, :end_date
26
- attr_accessor :sort, :limit, :offset#, :segment # individual, overwritten
26
+ attr_accessor :sort, :limit, :offset, :quota_user #, :segment # individual, overwritten
27
27
  attr_accessor :filters # appended to, may add :segments later for dynamic segments
28
28
 
29
29
  def initialize(klass)
@@ -75,14 +75,14 @@ module Legato
75
75
  end
76
76
 
77
77
  def apply_basic_options(options)
78
- [:sort, :limit, :offset, :start_date, :end_date].each do |key| #:segment
78
+ [:sort, :limit, :offset, :start_date, :end_date, :quota_user].each do |key| #:segment
79
79
  self.send("#{key}=".to_sym, options[key]) if options.has_key?(key)
80
80
  end
81
81
  end
82
82
 
83
83
  # def apply_filter_options(filter_options)
84
84
  # join_character = Legato.and_join_character
85
- #
85
+ #
86
86
  # Array.wrap(filter_options).compact.each do |filter|
87
87
  # filter.each do |key, value|
88
88
  # self.filters << hash_to_filter(key, value, join_character)
@@ -186,7 +186,8 @@ module Legato
186
186
  'start-index' => offset,
187
187
  # 'segment' => segment_id,
188
188
  'filters' => filters.to_params, # defaults to AND filtering
189
- 'fields' => REQUEST_FIELDS
189
+ 'fields' => REQUEST_FIELDS,
190
+ 'quotaUser' => quota_user
190
191
  }
191
192
 
192
193
  [metrics, dimensions, sort].each do |list|
@@ -1,3 +1,3 @@
1
1
  module Legato
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -248,6 +248,23 @@ describe Legato::Query do
248
248
  @query.offset.should == 200
249
249
  end
250
250
 
251
+ it "sets the quota_user" do
252
+ @query.apply_options({:quota_user => 'an id'})
253
+ @query.quota_user.should == 'an id'
254
+ end
255
+
256
+ it "replaces the quota_user" do
257
+ @query.quota_user = 'an id'
258
+ @query.apply_options({:quota_user => 'a different id'})
259
+ @query.quota_user.should == 'a different id'
260
+ end
261
+
262
+ it "does not replace quota_user if option is omitted" do
263
+ @query.quota_user = 'an id'
264
+ @query.apply_options({})
265
+ @query.quota_user.should == 'an id'
266
+ end
267
+
251
268
  context "with Time" do
252
269
  before :each do
253
270
  @now = Time.now
@@ -321,6 +338,15 @@ describe Legato::Query do
321
338
  @query.to_params['start-index'].should == 50
322
339
  end
323
340
 
341
+ it 'includes the quotaUser if quota_user is set' do
342
+ @query.quota_user = 'an id'
343
+ @query.to_params['quotaUser'].should == 'an id'
344
+ end
345
+
346
+ it 'excludes the quotaUser if quota_user is not set' do
347
+ @query.to_params.keys.should_not include('quotaUser')
348
+ end
349
+
324
350
  it 'includes filters' do
325
351
  filters = stub(:to_params => 'filter set parameters')
326
352
  @query.stubs(:filters).returns(filters)
@@ -1,5 +1,4 @@
1
- require 'bundler'
2
- Bundler.setup(:test)
1
+ require 'bundler/setup'
3
2
 
4
3
  require 'rspec'
5
4
  require 'mocha'
metadata CHANGED
@@ -1,151 +1,156 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: legato
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tony Pitale
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-05-17 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- prerelease: false
32
- type: :development
33
- requirement: *id001
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
34
15
  name: rake
35
- - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
45
- prerelease: false
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
46
22
  type: :development
47
- requirement: *id002
48
- name: rspec
49
- - !ruby/object:Gem::Dependency
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
59
23
  prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
60
38
  type: :development
61
- requirement: *id003
62
- name: mocha
63
- - !ruby/object:Gem::Dependency
64
- version_requirements: &id004 !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
73
39
  prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
74
54
  type: :development
75
- requirement: *id004
76
- name: bourne
77
- - !ruby/object:Gem::Dependency
78
- version_requirements: &id005 !ruby/object:Gem::Requirement
79
- none: false
80
- requirements:
81
- - - "="
82
- - !ruby/object:Gem::Version
83
- hash: -2540839718
84
- segments:
85
- - 2
86
- - 0
87
- - 0
88
- - beta
89
- - 2
90
- version: 2.0.0.beta2
91
55
  prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bourne
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
92
70
  type: :development
93
- requirement: *id005
94
- name: vcr
95
- - !ruby/object:Gem::Dependency
96
- version_requirements: &id006 !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
105
71
  prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: vcr
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.0.beta2
106
86
  type: :development
107
- requirement: *id006
108
- name: fakeweb
109
- - !ruby/object:Gem::Dependency
110
- version_requirements: &id007 !ruby/object:Gem::Requirement
111
- none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
119
87
  prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.0.0.beta2
94
+ - !ruby/object:Gem::Dependency
95
+ name: fakeweb
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
120
102
  type: :development
121
- requirement: *id007
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
122
111
  name: oauth2
123
- - !ruby/object:Gem::Dependency
124
- version_requirements: &id008 !ruby/object:Gem::Requirement
125
- none: false
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- hash: 3
130
- segments:
131
- - 0
132
- version: "0"
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
133
119
  prerelease: false
134
- type: :runtime
135
- requirement: *id008
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
136
127
  name: multi_json
137
- description: Access the Google Analytics Core Reporting and Management APIs with Ruby. Create models for metrics and dimensions. Filter your data to tell you what you need.
138
- email:
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Access the Google Analytics Core Reporting and Management APIs with Ruby.
143
+ Create models for metrics and dimensions. Filter your data to tell you what you
144
+ need.
145
+ email:
139
146
  - tpitale@gmail.com
140
147
  executables: []
141
-
142
148
  extensions: []
143
-
144
149
  extra_rdoc_files: []
145
-
146
- files:
150
+ files:
147
151
  - .gitignore
148
152
  - .rspec
153
+ - .ruby-version
149
154
  - .travis.yml
150
155
  - CHANGELOG.md
151
156
  - Gemfile
@@ -191,43 +196,31 @@ files:
191
196
  - spec/spec_helper.rb
192
197
  - spec/support/examples/management_finder.rb
193
198
  - spec/support/macros/oauth.rb
194
- has_rdoc: true
195
199
  homepage: http://github.com/tpitale/legato
196
200
  licenses: []
197
-
198
201
  post_install_message:
199
202
  rdoc_options: []
200
-
201
- require_paths:
203
+ require_paths:
202
204
  - lib
203
- required_ruby_version: !ruby/object:Gem::Requirement
205
+ required_ruby_version: !ruby/object:Gem::Requirement
204
206
  none: false
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- hash: 57
209
- segments:
210
- - 1
211
- - 8
212
- - 7
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
213
210
  version: 1.8.7
214
- required_rubygems_version: !ruby/object:Gem::Requirement
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
212
  none: false
216
- requirements:
217
- - - ">="
218
- - !ruby/object:Gem::Version
219
- hash: 3
220
- segments:
221
- - 0
222
- version: "0"
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
223
217
  requirements: []
224
-
225
218
  rubyforge_project: legato
226
- rubygems_version: 1.4.2
219
+ rubygems_version: 1.8.23
227
220
  signing_key:
228
221
  specification_version: 3
229
222
  summary: Access the Google Analytics API with Ruby
230
- test_files:
223
+ test_files:
231
224
  - spec/cassettes/management/accounts.json
232
225
  - spec/cassettes/management/profiles.json
233
226
  - spec/cassettes/management/web_properties.json