google-api-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.1.3
2
+
3
+ * added support for manual overrides of the discovery URI
4
+ * added support for manual overrides of the API base
5
+ * added support for xoauth_requestor_id
6
+
1
7
  == 0.1.2
2
8
 
3
9
  * added support for two-legged OAuth
@@ -132,11 +132,21 @@ HTML
132
132
  "Sets the URI to perform a request against") do |u|
133
133
  options[:uri] = u
134
134
  end
135
+ opts.on(
136
+ "--discovery-uri <uri>", String,
137
+ "Sets the URI to perform discovery") do |u|
138
+ options[:discovery_uri] = u
139
+ end
135
140
  opts.on(
136
141
  "-m", "--method <method>", String,
137
142
  "Sets the HTTP method to use for the request") do |m|
138
143
  options[:http_method] = m
139
144
  end
145
+ opts.on(
146
+ "--requestor-id <email>", String,
147
+ "Sets the email address of the requestor") do |e|
148
+ options[:requestor_id] = e
149
+ end
140
150
 
141
151
  opts.on("-v", "--verbose", "Run verbosely") do |v|
142
152
  options[:verbose] = v
@@ -259,10 +269,17 @@ HTML
259
269
 
260
270
  def list
261
271
  service_name = options[:service_name]
272
+ unless service_name
273
+ STDERR.puts('No service name supplied.')
274
+ exit(1)
275
+ end
262
276
  client = Google::APIClient.new(
263
277
  :service => service_name,
264
278
  :authorization => nil
265
279
  )
280
+ if options[:discovery_uri]
281
+ client.discovery_uri = options[:discovery_uri]
282
+ end
266
283
  service_version =
267
284
  options[:service_version] ||
268
285
  client.latest_service_version(service_name).version
@@ -277,6 +294,7 @@ HTML
277
294
  require 'yaml'
278
295
  config_file = File.expand_path('~/.google-api.yaml')
279
296
  signed = File.exist?(config_file)
297
+ authorization_type = :oauth_1
280
298
 
281
299
  # Setup HTTP request data
282
300
  request_body = ''
@@ -307,6 +325,9 @@ HTML
307
325
  config["token_credential_key"]
308
326
  client.authorization.token_credential_secret =
309
327
  config["token_credential_secret"]
328
+ if client.authorization.token_credential == nil
329
+ authorization_type = :two_legged_oauth_1
330
+ end
310
331
  end
311
332
 
312
333
  if options[:uri]
@@ -316,10 +337,18 @@ HTML
316
337
  STDERR.puts('URI may not be relative.')
317
338
  exit(1)
318
339
  end
340
+ if options[:requestor_id]
341
+ uri.query_values = uri.query_values.merge(
342
+ 'xoauth_requestor_id' => options[:requestor_id]
343
+ )
344
+ end
319
345
  method = options[:http_method]
320
346
  method ||= request_body == '' ? 'GET' : 'POST'
321
347
  method.upcase!
322
- client = Google::APIClient.new(:authorization => :two_legged_oauth_1)
348
+ client = Google::APIClient.new(:authorization => authorization_type)
349
+ if options[:discovery_uri]
350
+ client.discovery_uri = options[:discovery_uri]
351
+ end
323
352
  configure_authorization.call(client) if signed
324
353
  request = [method, uri.to_str, headers, [request_body]]
325
354
  request = client.sign_request(request)
@@ -337,8 +366,11 @@ HTML
337
366
  options[:service_name] || self.rpcname[/^([^\.]+)\./, 1]
338
367
  client = Google::APIClient.new(
339
368
  :service => service_name,
340
- :authorization => :oauth_1
369
+ :authorization => authorization_type
341
370
  )
371
+ if options[:discovery_uri]
372
+ client.discovery_uri = options[:discovery_uri]
373
+ end
342
374
  configure_authorization.call(client) if signed
343
375
  service_version =
344
376
  options[:service_version] ||
@@ -357,6 +389,9 @@ HTML
357
389
  accu[name] = value
358
390
  accu
359
391
  end
392
+ if options[:requestor_id]
393
+ parameters['xoauth_requestor_id'] = options[:requestor_id]
394
+ end
360
395
  begin
361
396
  response = client.execute(
362
397
  method, parameters, request_body, headers, {:signed => signed}
@@ -131,6 +131,15 @@ module Google
131
131
  end)
132
132
  end
133
133
 
134
+ ##
135
+ # Sets the discovery URI for the client.
136
+ #
137
+ # @param [Addressable::URI, #to_str, String] new_discovery_uri
138
+ # The new discovery URI.
139
+ def discovery_uri=(new_discovery_uri)
140
+ @options[:discovery_uri] = Addressable::URI.parse(new_discovery_uri)
141
+ end
142
+
134
143
  ##
135
144
  # Returns the parsed discovery document.
136
145
  #
@@ -89,6 +89,21 @@ module Google
89
89
  return @base ||= Addressable::URI.parse(self.description['baseUrl'])
90
90
  end
91
91
 
92
+ ##
93
+ # Updates the hierarchy of resources and methods with the new base.
94
+ #
95
+ # @param [Addressable::URI, #to_str, String] new_base
96
+ # The new base URI to use for the service.
97
+ def base=(new_base)
98
+ @base = Addressable::URI.parse(new_base)
99
+ self.resources.each do |resource|
100
+ resource.base = @base
101
+ end
102
+ self.methods.each do |method|
103
+ method.base = @base
104
+ end
105
+ end
106
+
92
107
  ##
93
108
  # A list of resources available at the root level of this version of the
94
109
  # service.
@@ -155,7 +170,11 @@ module Google
155
170
  split_version = lambda do |version|
156
171
  dotted_version = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 1]
157
172
  suffix = version[/^v?(\d+(.\d+)*)-?(.*?)?$/, 3]
158
- [dotted_version.split('.').map { |v| v.to_i }, suffix]
173
+ if dotted_version && suffix
174
+ [dotted_version.split('.').map { |v| v.to_i }, suffix]
175
+ else
176
+ [[-1], version]
177
+ end
159
178
  end
160
179
  self_sortable, self_suffix = split_version.call(self.version)
161
180
  other_sortable, other_suffix = split_version.call(other.version)
@@ -240,6 +259,21 @@ module Google
240
259
  # @return [Addressable::URI] The base URI that methods are joined to.
241
260
  attr_reader :base
242
261
 
262
+ ##
263
+ # Updates the hierarchy of resources and methods with the new base.
264
+ #
265
+ # @param [Addressable::URI, #to_str, String] new_base
266
+ # The new base URI to use for the resource.
267
+ def base=(new_base)
268
+ @base = Addressable::URI.parse(new_base)
269
+ self.resources.each do |resource|
270
+ resource.base = @base
271
+ end
272
+ self.methods.each do |method|
273
+ method.base = @base
274
+ end
275
+ end
276
+
243
277
  ##
244
278
  # A list of sub-resources available on this resource.
245
279
  #
@@ -336,6 +370,16 @@ module Google
336
370
  # The base URI that this method will be joined to.
337
371
  attr_reader :base
338
372
 
373
+ ##
374
+ # Updates the method with the new base.
375
+ #
376
+ # @param [Addressable::URI, #to_str, String] new_base
377
+ # The new base URI to use for the method.
378
+ def base=(new_base)
379
+ @base = Addressable::URI.parse(new_base)
380
+ @uri_template = nil
381
+ end
382
+
339
383
  ##
340
384
  # Returns the RPC name for the method.
341
385
  #
@@ -17,7 +17,7 @@ module Google
17
17
  module VERSION
18
18
  MAJOR = 0
19
19
  MINOR = 1
20
- TINY = 2
20
+ TINY = 3
21
21
 
22
22
  STRING = [MAJOR, MINOR, TINY].join('.')
23
23
  end
@@ -156,6 +156,8 @@ describe Google::APIClient, 'configured for the prediction API' do
156
156
  Google::APIClient::Service.new('two', 'v2', {})
157
157
  @client.discovered_services <<
158
158
  Google::APIClient::Service.new('two', 'v2beta1', {})
159
+ @client.discovered_services <<
160
+ Google::APIClient::Service.new('two', 'test2', {})
159
161
  @client.latest_service_version('two').version.should == 'v2'
160
162
  end
161
163
 
@@ -198,6 +200,18 @@ describe Google::APIClient, 'configured for the prediction API' do
198
200
  'https://www.googleapis.com/prediction/v1/training?query=12345'
199
201
  end
200
202
 
203
+ it 'should allow modification to the base URIs for testing purposes' do
204
+ prediction = @client.discovered_service('prediction', 'v1')
205
+ prediction.base = 'https://testing-domain.googleapis.com/prediction/v1/'
206
+ request = @client.generate_request(
207
+ prediction.training.insert,
208
+ {'query' => '123'}
209
+ )
210
+ method, uri, headers, body = request
211
+ uri.should ==
212
+ 'https://testing-domain.googleapis.com/prediction/v1/training?query=123'
213
+ end
214
+
201
215
  it 'should generate signed requests' do
202
216
  @client.authorization = :oauth_1
203
217
  @client.authorization.token_credential_key = '12345'
@@ -6,10 +6,10 @@ namespace :spec do
6
6
  t.spec_opts = ['--require', 'rubygems', '--color', '--format', 'specdoc']
7
7
  if RCOV_ENABLED
8
8
  if `which rcov`.strip == ""
9
- STDERR.puts "Please install rcov:"
10
9
  STDERR.puts(
11
- "sudo gem install relevance-rcov --source http://gems.github.com/"
10
+ "Please install rcov and ensure that its binary is in the PATH:"
12
11
  )
12
+ STDERR.puts("sudo gem install rcov")
13
13
  exit(1)
14
14
  end
15
15
  t.rcov = true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-api-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors: []
13
13
 
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-22 00:00:00 -07:00
18
+ date: 2010-11-04 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency