google-api-client 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/CHANGELOG.md +14 -0
- data/Gemfile +0 -36
- data/README.md +12 -1
- data/Rakefile +1 -8
- data/google-api-client.gemspec +40 -0
- data/lib/google/api_client.rb +98 -30
- data/lib/google/api_client/auth/compute_service_account.rb +1 -1
- data/lib/google/api_client/auth/file_storage.rb +19 -44
- data/lib/google/api_client/auth/installed_app.rb +11 -7
- data/lib/google/api_client/auth/storage.rb +101 -0
- data/lib/google/api_client/auth/storages/file_store.rb +58 -0
- data/lib/google/api_client/auth/storages/redis_store.rb +54 -0
- data/lib/google/api_client/batch.rb +13 -11
- data/lib/google/api_client/charset.rb +33 -0
- data/lib/google/api_client/client_secrets.rb +9 -6
- data/lib/google/api_client/discovery/api.rb +3 -3
- data/lib/google/api_client/discovery/resource.rb +3 -3
- data/lib/google/api_client/discovery/schema.rb +3 -5
- data/lib/google/api_client/errors.rb +5 -0
- data/lib/google/api_client/railtie.rb +2 -1
- data/lib/google/api_client/request.rb +1 -2
- data/lib/google/api_client/result.rb +4 -2
- data/lib/google/api_client/service.rb +2 -2
- data/lib/google/api_client/service/batch.rb +7 -0
- data/lib/google/api_client/service/stub_generator.rb +4 -2
- data/lib/google/api_client/service_account.rb +3 -0
- data/lib/google/api_client/version.rb +8 -13
- data/spec/google/api_client/auth/storage_spec.rb +122 -0
- data/spec/google/api_client/auth/storages/file_store_spec.rb +40 -0
- data/spec/google/api_client/auth/storages/redis_store_spec.rb +70 -0
- data/spec/google/api_client/batch_spec.rb +29 -30
- data/spec/google/api_client/client_secrets_spec.rb +53 -0
- data/spec/google/api_client/discovery_spec.rb +101 -91
- data/spec/google/api_client/gzip_spec.rb +21 -9
- data/spec/google/api_client/media_spec.rb +31 -32
- data/spec/google/api_client/request_spec.rb +3 -4
- data/spec/google/api_client/result_spec.rb +51 -47
- data/spec/google/api_client/service_account_spec.rb +40 -35
- data/spec/google/api_client/service_spec.rb +144 -112
- data/spec/google/api_client/simple_file_store_spec.rb +30 -34
- data/spec/google/api_client_spec.rb +139 -40
- data/spec/spec_helper.rb +9 -1
- metadata +111 -88
- data/CONTRIBUTING.md +0 -32
- data/lib/cacerts.pem +0 -2183
- data/lib/google/inflection.rb +0 -28
- data/spec/fixtures/files/privatekey.p12 +0 -0
- data/spec/fixtures/files/sample.txt +0 -33
- data/spec/fixtures/files/secret.pem +0 -19
- data/tasks/gem.rake +0 -97
- data/tasks/git.rake +0 -45
- data/tasks/metrics.rake +0 -22
- data/tasks/spec.rake +0 -57
- data/tasks/wiki.rake +0 -82
- data/tasks/yard.rake +0 -29
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding:utf-8
|
2
|
+
|
3
|
+
# Copyright 2013 Google Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
require 'google/api_client/client_secrets'
|
20
|
+
|
21
|
+
FIXTURES_PATH = File.expand_path('../../../fixtures', __FILE__)
|
22
|
+
|
23
|
+
RSpec.describe Google::APIClient::ClientSecrets do
|
24
|
+
|
25
|
+
context 'with JSON file' do
|
26
|
+
let(:file) { File.join(FIXTURES_PATH, 'files', 'client_secrets.json') }
|
27
|
+
subject(:secrets) { Google::APIClient::ClientSecrets.load(file)}
|
28
|
+
|
29
|
+
it 'should load the correct client ID' do
|
30
|
+
expect(secrets.client_id).to be == '898243283568.apps.googleusercontent.com'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should load the correct client secret' do
|
34
|
+
expect(secrets.client_secret).to be == 'i8YaXdGgiQ4_KrTVNGsB7QP1'
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'serialzed to hash' do
|
38
|
+
subject(:hash) { secrets.to_hash }
|
39
|
+
it 'should contain the flow as the first key' do
|
40
|
+
expect(hash).to have_key "installed"
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should contain the client ID' do
|
44
|
+
expect(hash["installed"]["client_id"]).to be == '898243283568.apps.googleusercontent.com'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should contain the client secret' do
|
48
|
+
expect(hash["installed"]["client_secret"]).to be == 'i8YaXdGgiQ4_KrTVNGsB7QP1'
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -22,9 +22,10 @@ require 'multi_json'
|
|
22
22
|
require 'compat/multi_json'
|
23
23
|
require 'signet/oauth_1/client'
|
24
24
|
require 'google/api_client'
|
25
|
-
require 'google/api_client/version'
|
26
25
|
|
27
|
-
|
26
|
+
fixtures_path = File.expand_path('../../../fixtures', __FILE__)
|
27
|
+
|
28
|
+
RSpec.describe Google::APIClient do
|
28
29
|
include ConnectionHelpers
|
29
30
|
CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
|
30
31
|
|
@@ -35,42 +36,51 @@ describe Google::APIClient do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
it 'should raise a type error for bogus authorization' do
|
38
|
-
(lambda do
|
39
|
+
expect(lambda do
|
39
40
|
Google::APIClient.new(:application_name => 'API Client Tests', :authorization => 42)
|
40
|
-
end).
|
41
|
+
end).to raise_error(TypeError)
|
41
42
|
end
|
42
43
|
|
43
44
|
it 'should not be able to retrieve the discovery document for a bogus API' do
|
44
|
-
(lambda do
|
45
|
+
expect(lambda do
|
45
46
|
CLIENT.discovery_document('bogus')
|
46
|
-
end).
|
47
|
-
(lambda do
|
47
|
+
end).to raise_error(Google::APIClient::TransmissionError)
|
48
|
+
expect(lambda do
|
48
49
|
CLIENT.discovered_api('bogus')
|
49
|
-
end).
|
50
|
+
end).to raise_error(Google::APIClient::TransmissionError)
|
50
51
|
end
|
51
52
|
|
52
53
|
it 'should raise an error for bogus services' do
|
53
|
-
(lambda do
|
54
|
+
expect(lambda do
|
54
55
|
CLIENT.discovered_api(42)
|
55
|
-
end).
|
56
|
+
end).to raise_error(TypeError)
|
56
57
|
end
|
57
58
|
|
58
59
|
it 'should raise an error for bogus services' do
|
59
|
-
(lambda do
|
60
|
+
expect(lambda do
|
60
61
|
CLIENT.preferred_version(42)
|
61
|
-
end).
|
62
|
+
end).to raise_error(TypeError)
|
62
63
|
end
|
63
64
|
|
64
65
|
it 'should raise an error for bogus methods' do
|
65
|
-
(lambda do
|
66
|
+
expect(lambda do
|
66
67
|
CLIENT.execute(42)
|
67
|
-
end).
|
68
|
+
end).to raise_error(TypeError)
|
68
69
|
end
|
69
70
|
|
70
71
|
it 'should not return a preferred version for bogus service names' do
|
71
|
-
CLIENT.preferred_version('bogus').
|
72
|
+
expect(CLIENT.preferred_version('bogus')).to eq(nil)
|
72
73
|
end
|
73
74
|
|
75
|
+
describe 'with zoo API' do
|
76
|
+
it 'should return API instance registered from file' do
|
77
|
+
zoo_json = File.join(fixtures_path, 'files', 'zoo.json')
|
78
|
+
contents = File.open(zoo_json, 'rb') { |io| io.read }
|
79
|
+
api = CLIENT.register_discovery_document('zoo', 'v1', contents)
|
80
|
+
expect(api).to be_kind_of(Google::APIClient::API)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
74
84
|
describe 'with the prediction API' do
|
75
85
|
before do
|
76
86
|
CLIENT.authorization = nil
|
@@ -80,7 +90,7 @@ describe Google::APIClient do
|
|
80
90
|
end
|
81
91
|
|
82
92
|
it 'should correctly determine the discovery URI' do
|
83
|
-
CLIENT.discovery_uri('prediction').
|
93
|
+
expect(CLIENT.discovery_uri('prediction')).to be ===
|
84
94
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
|
85
95
|
end
|
86
96
|
|
@@ -135,61 +145,61 @@ describe Google::APIClient do
|
|
135
145
|
end
|
136
146
|
|
137
147
|
it 'should correctly generate API objects' do
|
138
|
-
CLIENT.discovered_api('prediction', 'v1.2').name.
|
139
|
-
CLIENT.discovered_api('prediction', 'v1.2').version.
|
140
|
-
CLIENT.discovered_api(:prediction, 'v1.2').name.
|
141
|
-
CLIENT.discovered_api(:prediction, 'v1.2').version.
|
148
|
+
expect(CLIENT.discovered_api('prediction', 'v1.2').name).to eq('prediction')
|
149
|
+
expect(CLIENT.discovered_api('prediction', 'v1.2').version).to eq('v1.2')
|
150
|
+
expect(CLIENT.discovered_api(:prediction, 'v1.2').name).to eq('prediction')
|
151
|
+
expect(CLIENT.discovered_api(:prediction, 'v1.2').version).to eq('v1.2')
|
142
152
|
end
|
143
153
|
|
144
154
|
it 'should discover methods' do
|
145
|
-
CLIENT.discovered_method(
|
155
|
+
expect(CLIENT.discovered_method(
|
146
156
|
'prediction.training.insert', 'prediction', 'v1.2'
|
147
|
-
).name.
|
148
|
-
CLIENT.discovered_method(
|
157
|
+
).name).to eq('insert')
|
158
|
+
expect(CLIENT.discovered_method(
|
149
159
|
:'prediction.training.insert', :prediction, 'v1.2'
|
150
|
-
).name.
|
151
|
-
CLIENT.discovered_method(
|
160
|
+
).name).to eq('insert')
|
161
|
+
expect(CLIENT.discovered_method(
|
152
162
|
'prediction.training.delete', 'prediction', 'v1.2'
|
153
|
-
).name.
|
163
|
+
).name).to eq('delete')
|
154
164
|
end
|
155
165
|
|
156
166
|
it 'should define the origin API in discovered methods' do
|
157
|
-
CLIENT.discovered_method(
|
167
|
+
expect(CLIENT.discovered_method(
|
158
168
|
'prediction.training.insert', 'prediction', 'v1.2'
|
159
|
-
).api.name.
|
169
|
+
).api.name).to eq('prediction')
|
160
170
|
end
|
161
171
|
|
162
172
|
it 'should not find methods that are not in the discovery document' do
|
163
|
-
CLIENT.discovered_method(
|
173
|
+
expect(CLIENT.discovered_method(
|
164
174
|
'prediction.bogus', 'prediction', 'v1.2'
|
165
|
-
).
|
175
|
+
)).to eq(nil)
|
166
176
|
end
|
167
177
|
|
168
178
|
it 'should raise an error for bogus methods' do
|
169
|
-
(lambda do
|
179
|
+
expect(lambda do
|
170
180
|
CLIENT.discovered_method(42, 'prediction', 'v1.2')
|
171
|
-
end).
|
181
|
+
end).to raise_error(TypeError)
|
172
182
|
end
|
173
183
|
|
174
184
|
it 'should raise an error for bogus methods' do
|
175
|
-
(lambda do
|
185
|
+
expect(lambda do
|
176
186
|
CLIENT.execute(:api_method => CLIENT.discovered_api('prediction', 'v1.2'))
|
177
|
-
end).
|
187
|
+
end).to raise_error(TypeError)
|
178
188
|
end
|
179
189
|
|
180
190
|
it 'should correctly determine the preferred version' do
|
181
|
-
CLIENT.preferred_version('prediction').version.
|
182
|
-
CLIENT.preferred_version(:prediction).version.
|
191
|
+
expect(CLIENT.preferred_version('prediction').version).not_to eq('v1')
|
192
|
+
expect(CLIENT.preferred_version(:prediction).version).not_to eq('v1')
|
183
193
|
end
|
184
194
|
|
185
195
|
it 'should return a batch path' do
|
186
|
-
CLIENT.discovered_api('prediction', 'v1.2').batch_path.
|
196
|
+
expect(CLIENT.discovered_api('prediction', 'v1.2').batch_path).not_to be_nil
|
187
197
|
end
|
188
198
|
|
189
199
|
it 'should generate valid requests' do
|
190
200
|
conn = stub_connection do |stub|
|
191
201
|
stub.post('/prediction/v1.2/training?data=12345') do |env|
|
192
|
-
env[:body].
|
202
|
+
expect(env[:body]).to eq('')
|
193
203
|
[200, {}, '{}']
|
194
204
|
end
|
195
205
|
end
|
@@ -207,7 +217,7 @@ describe Google::APIClient do
|
|
207
217
|
# bare ampersand (&) in 0.4.7. ensure that it gets converted
|
208
218
|
# to a CGI-escaped semicolon (%3B) instead.
|
209
219
|
stub.post('/prediction/v1.2/training?data=12345%3B67890') do |env|
|
210
|
-
env[:body].
|
220
|
+
expect(env[:body]).to eq('')
|
211
221
|
[200, {}, '{}']
|
212
222
|
end
|
213
223
|
end
|
@@ -222,7 +232,7 @@ describe Google::APIClient do
|
|
222
232
|
it 'should generate valid requests when multivalued parameters are passed' do
|
223
233
|
conn = stub_connection do |stub|
|
224
234
|
stub.post('/prediction/v1.2/training?data=1&data=2') do |env|
|
225
|
-
env.params['data'].
|
235
|
+
expect(env.params['data']).to include('1', '2')
|
226
236
|
[200, {}, '{}']
|
227
237
|
end
|
228
238
|
end
|
@@ -271,7 +281,7 @@ describe Google::APIClient do
|
|
271
281
|
|
272
282
|
conn = stub_connection do |stub|
|
273
283
|
stub.post('/prediction/v1.2/training') do |env|
|
274
|
-
env[:url].host.
|
284
|
+
expect(env[:url].host).to eq('testing-domain.example.com')
|
275
285
|
[200, {}, '{}']
|
276
286
|
end
|
277
287
|
end
|
@@ -291,8 +301,8 @@ describe Google::APIClient do
|
|
291
301
|
|
292
302
|
conn = stub_connection do |stub|
|
293
303
|
stub.post('/prediction/v1.2/training?data=12345') do |env|
|
294
|
-
env[:request_headers].
|
295
|
-
env[:request_headers]['Authorization'].
|
304
|
+
expect(env[:request_headers]).to have_key('Authorization')
|
305
|
+
expect(env[:request_headers]['Authorization']).to match(/^OAuth/)
|
296
306
|
[200, {}, '{}']
|
297
307
|
end
|
298
308
|
end
|
@@ -311,8 +321,8 @@ describe Google::APIClient do
|
|
311
321
|
|
312
322
|
conn = stub_connection do |stub|
|
313
323
|
stub.post('/prediction/v1.2/training?data=12345') do |env|
|
314
|
-
env[:request_headers].
|
315
|
-
env[:request_headers]['Authorization'].
|
324
|
+
expect(env[:request_headers]).to have_key('Authorization')
|
325
|
+
expect(env[:request_headers]['Authorization']).to match(/^Bearer/)
|
316
326
|
[200, {}, '{}']
|
317
327
|
end
|
318
328
|
end
|
@@ -333,7 +343,7 @@ describe Google::APIClient do
|
|
333
343
|
@prediction.training.insert,
|
334
344
|
{'data' => '12345'}
|
335
345
|
)
|
336
|
-
result.response.status.
|
346
|
+
expect(result.response.status).to eq(401)
|
337
347
|
end
|
338
348
|
|
339
349
|
it 'should not be able to execute improperly authorized requests' do
|
@@ -343,11 +353,11 @@ describe Google::APIClient do
|
|
343
353
|
@prediction.training.insert,
|
344
354
|
{'data' => '12345'}
|
345
355
|
)
|
346
|
-
result.response.status.
|
356
|
+
expect(result.response.status).to eq(401)
|
347
357
|
end
|
348
358
|
|
349
359
|
it 'should not be able to execute improperly authorized requests' do
|
350
|
-
(lambda do
|
360
|
+
expect(lambda do
|
351
361
|
CLIENT.authorization = :oauth_1
|
352
362
|
CLIENT.authorization.token_credential_key = '12345'
|
353
363
|
CLIENT.authorization.token_credential_secret = '12345'
|
@@ -355,25 +365,25 @@ describe Google::APIClient do
|
|
355
365
|
@prediction.training.insert,
|
356
366
|
{'data' => '12345'}
|
357
367
|
)
|
358
|
-
end).
|
368
|
+
end).to raise_error(Google::APIClient::ClientError)
|
359
369
|
end
|
360
370
|
|
361
371
|
it 'should not be able to execute improperly authorized requests' do
|
362
|
-
(lambda do
|
372
|
+
expect(lambda do
|
363
373
|
CLIENT.authorization = :oauth_2
|
364
374
|
CLIENT.authorization.access_token = '12345'
|
365
375
|
result = CLIENT.execute!(
|
366
376
|
@prediction.training.insert,
|
367
377
|
{'data' => '12345'}
|
368
378
|
)
|
369
|
-
end).
|
379
|
+
end).to raise_error(Google::APIClient::ClientError)
|
370
380
|
end
|
371
381
|
|
372
382
|
it 'should correctly handle unnamed parameters' do
|
373
383
|
conn = stub_connection do |stub|
|
374
384
|
stub.post('/prediction/v1.2/training') do |env|
|
375
|
-
env[:request_headers].
|
376
|
-
env[:request_headers]['Content-Type'].
|
385
|
+
expect(env[:request_headers]).to have_key('Content-Type')
|
386
|
+
expect(env[:request_headers]['Content-Type']).to eq('application/json')
|
377
387
|
[200, {}, '{}']
|
378
388
|
end
|
379
389
|
end
|
@@ -396,32 +406,32 @@ describe Google::APIClient do
|
|
396
406
|
end
|
397
407
|
|
398
408
|
it 'should correctly determine the discovery URI' do
|
399
|
-
CLIENT.discovery_uri('plus').
|
409
|
+
expect(CLIENT.discovery_uri('plus')).to be ===
|
400
410
|
'https://www.googleapis.com/discovery/v1/apis/plus/v1/rest'
|
401
411
|
end
|
402
412
|
|
403
413
|
it 'should find APIs that are in the discovery document' do
|
404
|
-
CLIENT.discovered_api('plus').name.
|
405
|
-
CLIENT.discovered_api('plus').version.
|
406
|
-
CLIENT.discovered_api(:plus).name.
|
407
|
-
CLIENT.discovered_api(:plus).version.
|
414
|
+
expect(CLIENT.discovered_api('plus').name).to eq('plus')
|
415
|
+
expect(CLIENT.discovered_api('plus').version).to eq('v1')
|
416
|
+
expect(CLIENT.discovered_api(:plus).name).to eq('plus')
|
417
|
+
expect(CLIENT.discovered_api(:plus).version).to eq('v1')
|
408
418
|
end
|
409
419
|
|
410
420
|
it 'should find methods that are in the discovery document' do
|
411
421
|
# TODO(bobaman) Fix this when the RPC names are correct
|
412
|
-
CLIENT.discovered_method(
|
422
|
+
expect(CLIENT.discovered_method(
|
413
423
|
'plus.activities.list', 'plus'
|
414
|
-
).name.
|
424
|
+
).name).to eq('list')
|
415
425
|
end
|
416
426
|
|
417
427
|
it 'should define the origin API in discovered methods' do
|
418
|
-
CLIENT.discovered_method(
|
428
|
+
expect(CLIENT.discovered_method(
|
419
429
|
'plus.activities.list', 'plus'
|
420
|
-
).api.name.
|
430
|
+
).api.name).to eq('plus')
|
421
431
|
end
|
422
432
|
|
423
433
|
it 'should not find methods that are not in the discovery document' do
|
424
|
-
CLIENT.discovered_method('plus.bogus', 'plus').
|
434
|
+
expect(CLIENT.discovered_method('plus.bogus', 'plus')).to eq(nil)
|
425
435
|
end
|
426
436
|
|
427
437
|
it 'should generate requests against the correct URIs' do
|
@@ -443,17 +453,17 @@ describe Google::APIClient do
|
|
443
453
|
end
|
444
454
|
|
445
455
|
it 'should correctly validate parameters' do
|
446
|
-
(lambda do
|
456
|
+
expect(lambda do
|
447
457
|
CLIENT.execute(
|
448
458
|
:api_method => @plus.activities.list,
|
449
459
|
:parameters => {'alt' => 'json'},
|
450
460
|
:authenticated => false
|
451
461
|
)
|
452
|
-
end).
|
462
|
+
end).to raise_error(ArgumentError)
|
453
463
|
end
|
454
464
|
|
455
465
|
it 'should correctly validate parameters' do
|
456
|
-
(lambda do
|
466
|
+
expect(lambda do
|
457
467
|
CLIENT.execute(
|
458
468
|
:api_method => @plus.activities.list,
|
459
469
|
:parameters => {
|
@@ -461,7 +471,7 @@ describe Google::APIClient do
|
|
461
471
|
},
|
462
472
|
:authenticated => false
|
463
473
|
).to_env(CLIENT.connection)
|
464
|
-
end).
|
474
|
+
end).to raise_error(ArgumentError)
|
465
475
|
end
|
466
476
|
end
|
467
477
|
|
@@ -472,27 +482,27 @@ describe Google::APIClient do
|
|
472
482
|
end
|
473
483
|
|
474
484
|
it 'should correctly determine the discovery URI' do
|
475
|
-
CLIENT.discovery_uri('adsense', 'v1.3').to_s.
|
485
|
+
expect(CLIENT.discovery_uri('adsense', 'v1.3').to_s).to be ===
|
476
486
|
'https://www.googleapis.com/discovery/v1/apis/adsense/v1.3/rest'
|
477
487
|
end
|
478
488
|
|
479
489
|
it 'should find APIs that are in the discovery document' do
|
480
|
-
CLIENT.discovered_api('adsense', 'v1.3').name.
|
481
|
-
CLIENT.discovered_api('adsense', 'v1.3').version.
|
490
|
+
expect(CLIENT.discovered_api('adsense', 'v1.3').name).to eq('adsense')
|
491
|
+
expect(CLIENT.discovered_api('adsense', 'v1.3').version).to eq('v1.3')
|
482
492
|
end
|
483
493
|
|
484
494
|
it 'should return a batch path' do
|
485
|
-
CLIENT.discovered_api('adsense', 'v1.3').batch_path.
|
495
|
+
expect(CLIENT.discovered_api('adsense', 'v1.3').batch_path).not_to be_nil
|
486
496
|
end
|
487
497
|
|
488
498
|
it 'should find methods that are in the discovery document' do
|
489
|
-
CLIENT.discovered_method(
|
499
|
+
expect(CLIENT.discovered_method(
|
490
500
|
'adsense.reports.generate', 'adsense', 'v1.3'
|
491
|
-
).name.
|
501
|
+
).name).to eq('generate')
|
492
502
|
end
|
493
503
|
|
494
504
|
it 'should not find methods that are not in the discovery document' do
|
495
|
-
CLIENT.discovered_method('adsense.bogus', 'adsense', 'v1.3').
|
505
|
+
expect(CLIENT.discovered_method('adsense.bogus', 'adsense', 'v1.3')).to eq(nil)
|
496
506
|
end
|
497
507
|
|
498
508
|
it 'should generate requests against the correct URIs' do
|
@@ -514,16 +524,16 @@ describe Google::APIClient do
|
|
514
524
|
:api_method => @adsense.adclients.list,
|
515
525
|
:authenticated => false
|
516
526
|
)
|
517
|
-
result.response.status.
|
527
|
+
expect(result.response.status).to eq(401)
|
518
528
|
end
|
519
529
|
|
520
530
|
it 'should fail when validating missing required parameters' do
|
521
|
-
(lambda do
|
531
|
+
expect(lambda do
|
522
532
|
CLIENT.execute(
|
523
533
|
:api_method => @adsense.reports.generate,
|
524
534
|
:authenticated => false
|
525
535
|
)
|
526
|
-
end).
|
536
|
+
end).to raise_error(ArgumentError)
|
527
537
|
end
|
528
538
|
|
529
539
|
it 'should succeed when validating parameters in a correct call' do
|
@@ -532,7 +542,7 @@ describe Google::APIClient do
|
|
532
542
|
[200, {}, '{}']
|
533
543
|
end
|
534
544
|
end
|
535
|
-
(lambda do
|
545
|
+
expect(lambda do
|
536
546
|
CLIENT.execute(
|
537
547
|
:api_method => @adsense.reports.generate,
|
538
548
|
:parameters => {
|
@@ -544,12 +554,12 @@ describe Google::APIClient do
|
|
544
554
|
:authenticated => false,
|
545
555
|
:connection => conn
|
546
556
|
)
|
547
|
-
end).
|
557
|
+
end).not_to raise_error
|
548
558
|
conn.verify
|
549
559
|
end
|
550
560
|
|
551
561
|
it 'should fail when validating parameters with invalid values' do
|
552
|
-
(lambda do
|
562
|
+
expect(lambda do
|
553
563
|
CLIENT.execute(
|
554
564
|
:api_method => @adsense.reports.generate,
|
555
565
|
:parameters => {
|
@@ -560,7 +570,7 @@ describe Google::APIClient do
|
|
560
570
|
},
|
561
571
|
:authenticated => false
|
562
572
|
)
|
563
|
-
end).
|
573
|
+
end).to raise_error(ArgumentError)
|
564
574
|
end
|
565
575
|
|
566
576
|
it 'should succeed when validating repeated parameters in a correct call' do
|
@@ -571,7 +581,7 @@ describe Google::APIClient do
|
|
571
581
|
[200, {}, '{}']
|
572
582
|
end
|
573
583
|
end
|
574
|
-
(lambda do
|
584
|
+
expect(lambda do
|
575
585
|
CLIENT.execute(
|
576
586
|
:api_method => @adsense.reports.generate,
|
577
587
|
:parameters => {
|
@@ -583,12 +593,12 @@ describe Google::APIClient do
|
|
583
593
|
:authenticated => false,
|
584
594
|
:connection => conn
|
585
595
|
)
|
586
|
-
end).
|
596
|
+
end).not_to raise_error
|
587
597
|
conn.verify
|
588
598
|
end
|
589
599
|
|
590
600
|
it 'should fail when validating incorrect repeated parameters' do
|
591
|
-
(lambda do
|
601
|
+
expect(lambda do
|
592
602
|
CLIENT.execute(
|
593
603
|
:api_method => @adsense.reports.generate,
|
594
604
|
:parameters => {
|
@@ -599,7 +609,7 @@ describe Google::APIClient do
|
|
599
609
|
},
|
600
610
|
:authenticated => false
|
601
611
|
)
|
602
|
-
end).
|
612
|
+
end).to raise_error(ArgumentError)
|
603
613
|
end
|
604
614
|
|
605
615
|
it 'should generate valid requests when multivalued parameters are passed' do
|
@@ -607,8 +617,8 @@ describe Google::APIClient do
|
|
607
617
|
stub.get('/adsense/v1.3/reports?dimension=DATE&dimension=PRODUCT_CODE'+
|
608
618
|
'&endDate=2010-01-01&metric=CLICKS&metric=PAGE_VIEWS&'+
|
609
619
|
'startDate=2000-01-01') do |env|
|
610
|
-
env.params['dimension'].
|
611
|
-
env.params['metric'].
|
620
|
+
expect(env.params['dimension']).to include('DATE', 'PRODUCT_CODE')
|
621
|
+
expect(env.params['metric']).to include('CLICKS', 'PAGE_VIEWS')
|
612
622
|
[200, {}, '{}']
|
613
623
|
end
|
614
624
|
end
|
@@ -634,19 +644,19 @@ describe Google::APIClient do
|
|
634
644
|
end
|
635
645
|
|
636
646
|
it 'should include media upload info methods' do
|
637
|
-
@drive.files.insert.media_upload.
|
647
|
+
expect(@drive.files.insert.media_upload).not_to eq(nil)
|
638
648
|
end
|
639
649
|
|
640
650
|
it 'should include accepted media types' do
|
641
|
-
@drive.files.insert.media_upload.accepted_types.
|
651
|
+
expect(@drive.files.insert.media_upload.accepted_types).not_to be_empty
|
642
652
|
end
|
643
653
|
|
644
654
|
it 'should have an upload path' do
|
645
|
-
@drive.files.insert.media_upload.uri_template.
|
655
|
+
expect(@drive.files.insert.media_upload.uri_template).not_to eq(nil)
|
646
656
|
end
|
647
657
|
|
648
658
|
it 'should have a max file size' do
|
649
|
-
@drive.files.insert.media_upload.max_size.
|
659
|
+
expect(@drive.files.insert.media_upload.max_size).not_to eq(nil)
|
650
660
|
end
|
651
661
|
end
|
652
662
|
end
|