google-api-client 0.7.1 → 0.8.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 +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
@@ -18,38 +18,42 @@ require 'google/api_client'
|
|
18
18
|
|
19
19
|
fixtures_path = File.expand_path('../../../fixtures', __FILE__)
|
20
20
|
|
21
|
-
describe Google::APIClient::KeyUtils do
|
21
|
+
RSpec.describe Google::APIClient::KeyUtils do
|
22
22
|
it 'should read PKCS12 files from the filesystem' do
|
23
|
-
|
23
|
+
if RUBY_PLATFORM == 'java' && RUBY_VERSION.start_with?('1.8')
|
24
|
+
pending "Reading from PKCS12 not supported on jruby 1.8.x"
|
25
|
+
end
|
24
26
|
path = File.expand_path('files/privatekey.p12', fixtures_path)
|
25
27
|
key = Google::APIClient::KeyUtils.load_from_pkcs12(path, 'notasecret')
|
26
|
-
key.
|
28
|
+
expect(key).not_to eq(nil)
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'should read PKCS12 files from loaded files' do
|
30
|
-
|
32
|
+
if RUBY_PLATFORM == 'java' && RUBY_VERSION.start_with?('1.8')
|
33
|
+
pending "Reading from PKCS12 not supported on jruby 1.8.x"
|
34
|
+
end
|
31
35
|
path = File.expand_path('files/privatekey.p12', fixtures_path)
|
32
36
|
content = File.read(path)
|
33
37
|
key = Google::APIClient::KeyUtils.load_from_pkcs12(content, 'notasecret')
|
34
|
-
key.
|
38
|
+
expect(key).not_to eq(nil)
|
35
39
|
end
|
36
40
|
|
37
41
|
it 'should read PEM files from the filesystem' do
|
38
42
|
path = File.expand_path('files/secret.pem', fixtures_path)
|
39
43
|
key = Google::APIClient::KeyUtils.load_from_pem(path, 'notasecret')
|
40
|
-
key.
|
44
|
+
expect(key).not_to eq(nil)
|
41
45
|
end
|
42
46
|
|
43
47
|
it 'should read PEM files from loaded files' do
|
44
48
|
path = File.expand_path('files/secret.pem', fixtures_path)
|
45
49
|
content = File.read(path)
|
46
50
|
key = Google::APIClient::KeyUtils.load_from_pem(content, 'notasecret')
|
47
|
-
key.
|
51
|
+
expect(key).not_to eq(nil)
|
48
52
|
end
|
49
53
|
|
50
54
|
end
|
51
55
|
|
52
|
-
describe Google::APIClient::JWTAsserter do
|
56
|
+
RSpec.describe Google::APIClient::JWTAsserter do
|
53
57
|
include ConnectionHelpers
|
54
58
|
|
55
59
|
before do
|
@@ -59,11 +63,12 @@ describe Google::APIClient::JWTAsserter do
|
|
59
63
|
it 'should generate valid JWTs' do
|
60
64
|
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
|
61
65
|
jwt = asserter.to_authorization.to_jwt
|
62
|
-
jwt.
|
66
|
+
expect(jwt).not_to eq(nil)
|
63
67
|
|
64
68
|
claim = JWT.decode(jwt, @key.public_key, true)
|
65
|
-
claim[
|
66
|
-
claim["
|
69
|
+
claim = claim[0] if claim[0]
|
70
|
+
expect(claim["iss"]).to eq('client1')
|
71
|
+
expect(claim["scope"]).to eq('scope1 scope2')
|
67
72
|
end
|
68
73
|
|
69
74
|
it 'should allow impersonation' do
|
@@ -71,8 +76,8 @@ describe Google::APIClient::JWTAsserter do
|
|
71
76
|
stub.post('/o/oauth2/token') do |env|
|
72
77
|
params = Addressable::URI.form_unencode(env[:body])
|
73
78
|
JWT.decode(params.assoc("assertion").last, @key.public_key)
|
74
|
-
params.assoc("grant_type").
|
75
|
-
[200, {}, '{
|
79
|
+
expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
|
80
|
+
[200, {'content-type' => 'application/json'}, '{
|
76
81
|
"access_token" : "1/abcdef1234567890",
|
77
82
|
"token_type" : "Bearer",
|
78
83
|
"expires_in" : 3600
|
@@ -81,8 +86,8 @@ describe Google::APIClient::JWTAsserter do
|
|
81
86
|
end
|
82
87
|
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
|
83
88
|
auth = asserter.authorize('user1@email.com', { :connection => conn })
|
84
|
-
auth.
|
85
|
-
auth.person.
|
89
|
+
expect(auth).not_to eq(nil?)
|
90
|
+
expect(auth.person).to eq('user1@email.com')
|
86
91
|
conn.verify
|
87
92
|
end
|
88
93
|
|
@@ -91,8 +96,8 @@ describe Google::APIClient::JWTAsserter do
|
|
91
96
|
stub.post('/o/oauth2/token') do |env|
|
92
97
|
params = Addressable::URI.form_unencode(env[:body])
|
93
98
|
JWT.decode(params.assoc("assertion").last, @key.public_key)
|
94
|
-
params.assoc("grant_type").
|
95
|
-
[200, {}, '{
|
99
|
+
expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
|
100
|
+
[200, {'content-type' => 'application/json'}, '{
|
96
101
|
"access_token" : "1/abcdef1234567890",
|
97
102
|
"token_type" : "Bearer",
|
98
103
|
"expires_in" : 3600
|
@@ -101,18 +106,18 @@ describe Google::APIClient::JWTAsserter do
|
|
101
106
|
end
|
102
107
|
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
|
103
108
|
auth = asserter.authorize(nil, { :connection => conn })
|
104
|
-
auth.
|
105
|
-
auth.access_token.
|
109
|
+
expect(auth).not_to eq(nil?)
|
110
|
+
expect(auth.access_token).to eq("1/abcdef1234567890")
|
106
111
|
conn.verify
|
107
112
|
end
|
108
|
-
|
113
|
+
|
109
114
|
it 'should be refreshable' do
|
110
115
|
conn = stub_connection do |stub|
|
111
116
|
stub.post('/o/oauth2/token') do |env|
|
112
117
|
params = Addressable::URI.form_unencode(env[:body])
|
113
118
|
JWT.decode(params.assoc("assertion").last, @key.public_key)
|
114
|
-
params.assoc("grant_type").
|
115
|
-
[200, {}, '{
|
119
|
+
expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
|
120
|
+
[200, {'content-type' => 'application/json'}, '{
|
116
121
|
"access_token" : "1/abcdef1234567890",
|
117
122
|
"token_type" : "Bearer",
|
118
123
|
"expires_in" : 3600
|
@@ -121,8 +126,8 @@ describe Google::APIClient::JWTAsserter do
|
|
121
126
|
stub.post('/o/oauth2/token') do |env|
|
122
127
|
params = Addressable::URI.form_unencode(env[:body])
|
123
128
|
JWT.decode(params.assoc("assertion").last, @key.public_key)
|
124
|
-
params.assoc("grant_type").
|
125
|
-
[200, {}, '{
|
129
|
+
expect(params.assoc("grant_type")).to eq(['grant_type','urn:ietf:params:oauth:grant-type:jwt-bearer'])
|
130
|
+
[200, {'content-type' => 'application/json'}, '{
|
126
131
|
"access_token" : "1/0987654321fedcba",
|
127
132
|
"token_type" : "Bearer",
|
128
133
|
"expires_in" : 3600
|
@@ -131,24 +136,24 @@ describe Google::APIClient::JWTAsserter do
|
|
131
136
|
end
|
132
137
|
asserter = Google::APIClient::JWTAsserter.new('client1', 'scope1 scope2', @key)
|
133
138
|
auth = asserter.authorize(nil, { :connection => conn })
|
134
|
-
auth.
|
135
|
-
auth.access_token.
|
136
|
-
|
139
|
+
expect(auth).not_to eq(nil?)
|
140
|
+
expect(auth.access_token).to eq("1/abcdef1234567890")
|
141
|
+
|
137
142
|
auth.fetch_access_token!(:connection => conn)
|
138
|
-
auth.access_token.
|
139
|
-
|
143
|
+
expect(auth.access_token).to eq("1/0987654321fedcba")
|
144
|
+
|
140
145
|
conn.verify
|
141
|
-
end
|
146
|
+
end
|
142
147
|
end
|
143
148
|
|
144
|
-
describe Google::APIClient::ComputeServiceAccount do
|
149
|
+
RSpec.describe Google::APIClient::ComputeServiceAccount do
|
145
150
|
include ConnectionHelpers
|
146
151
|
|
147
152
|
it 'should query metadata server' do
|
148
153
|
conn = stub_connection do |stub|
|
149
154
|
stub.get('/computeMetadata/v1beta1/instance/service-accounts/default/token') do |env|
|
150
|
-
env.url.host.
|
151
|
-
[200, {}, '{
|
155
|
+
expect(env.url.host).to eq('metadata')
|
156
|
+
[200, {'content-type' => 'application/json'}, '{
|
152
157
|
"access_token" : "1/abcdef1234567890",
|
153
158
|
"token_type" : "Bearer",
|
154
159
|
"expires_in" : 3600
|
@@ -157,8 +162,8 @@ describe Google::APIClient::ComputeServiceAccount do
|
|
157
162
|
end
|
158
163
|
service_account = Google::APIClient::ComputeServiceAccount.new
|
159
164
|
auth = service_account.fetch_access_token!({ :connection => conn })
|
160
|
-
auth.
|
161
|
-
auth["access_token"].
|
165
|
+
expect(auth).not_to eq(nil?)
|
166
|
+
expect(auth["access_token"]).to eq("1/abcdef1234567890")
|
162
167
|
conn.verify
|
163
168
|
end
|
164
169
|
end
|
@@ -21,27 +21,27 @@ require 'google/api_client/service'
|
|
21
21
|
|
22
22
|
fixtures_path = File.expand_path('../../../fixtures', __FILE__)
|
23
23
|
|
24
|
-
describe Google::APIClient::Service do
|
24
|
+
RSpec.describe Google::APIClient::Service do
|
25
25
|
include ConnectionHelpers
|
26
26
|
|
27
27
|
APPLICATION_NAME = 'API Client Tests'
|
28
28
|
|
29
29
|
it 'should error out when called without an API name or version' do
|
30
|
-
(lambda do
|
30
|
+
expect(lambda do
|
31
31
|
Google::APIClient::Service.new
|
32
|
-
end).
|
32
|
+
end).to raise_error(ArgumentError)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should error out when called without an API version' do
|
36
|
-
(lambda do
|
36
|
+
expect(lambda do
|
37
37
|
Google::APIClient::Service.new('foo')
|
38
|
-
end).
|
38
|
+
end).to raise_error(ArgumentError)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should error out when the options hash is not a hash' do
|
42
|
-
(lambda do
|
42
|
+
expect(lambda do
|
43
43
|
Google::APIClient::Service.new('foo', 'v1', 42)
|
44
|
-
end).
|
44
|
+
end).to raise_error(ArgumentError)
|
45
45
|
end
|
46
46
|
|
47
47
|
describe 'with the AdSense Management API' do
|
@@ -112,34 +112,34 @@ describe Google::APIClient::Service do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'should return a resource when using a valid resource name' do
|
115
|
-
@adsense.accounts.
|
115
|
+
expect(@adsense.accounts).to be_a(Google::APIClient::Service::Resource)
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'should throw an error when using an invalid resource name' do
|
119
|
-
(lambda do
|
119
|
+
expect(lambda do
|
120
120
|
@adsense.invalid_resource
|
121
|
-
end).
|
121
|
+
end).to raise_error
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should return a request when using a valid method name' do
|
125
125
|
req = @adsense.adclients.list
|
126
|
-
req.
|
127
|
-
req.method.id.
|
128
|
-
req.parameters.
|
126
|
+
expect(req).to be_a(Google::APIClient::Service::Request)
|
127
|
+
expect(req.method.id).to eq('adsense.adclients.list')
|
128
|
+
expect(req.parameters).to be_nil
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'should throw an error when using an invalid method name' do
|
132
|
-
(lambda do
|
132
|
+
expect(lambda do
|
133
133
|
@adsense.adclients.invalid_method
|
134
|
-
end).
|
134
|
+
end).to raise_error
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'should return a valid request with parameters' do
|
138
138
|
req = @adsense.adunits.list(:adClientId => '1')
|
139
|
-
req.
|
140
|
-
req.method.id.
|
141
|
-
req.parameters.
|
142
|
-
req.parameters[:adClientId].
|
139
|
+
expect(req).to be_a(Google::APIClient::Service::Request)
|
140
|
+
expect(req.method.id).to eq('adsense.adunits.list')
|
141
|
+
expect(req.parameters).not_to be_nil
|
142
|
+
expect(req.parameters[:adClientId]).to eq('1')
|
143
143
|
end
|
144
144
|
end
|
145
145
|
end
|
@@ -149,7 +149,7 @@ describe Google::APIClient::Service do
|
|
149
149
|
it 'should make a valid call with an object body' do
|
150
150
|
conn = stub_connection do |stub|
|
151
151
|
stub.post('/prediction/v1.5/trainedmodels?project=1') do |env|
|
152
|
-
env.body.
|
152
|
+
expect(env.body).to eq('{"id":"1"}')
|
153
153
|
[200, {}, '{}']
|
154
154
|
end
|
155
155
|
end
|
@@ -170,7 +170,7 @@ describe Google::APIClient::Service do
|
|
170
170
|
it 'should make a valid call with a text body' do
|
171
171
|
conn = stub_connection do |stub|
|
172
172
|
stub.post('/prediction/v1.5/trainedmodels?project=1') do |env|
|
173
|
-
env.body.
|
173
|
+
expect(env.body).to eq('{"id":"1"}')
|
174
174
|
[200, {}, '{}']
|
175
175
|
end
|
176
176
|
end
|
@@ -196,20 +196,20 @@ describe Google::APIClient::Service do
|
|
196
196
|
|
197
197
|
it 'should return a valid request with a body' do
|
198
198
|
req = @prediction.trainedmodels.insert(:project => '1').body({'id' => '1'})
|
199
|
-
req.
|
200
|
-
req.method.id.
|
201
|
-
req.body.
|
202
|
-
req.parameters.
|
203
|
-
req.parameters[:project].
|
199
|
+
expect(req).to be_a(Google::APIClient::Service::Request)
|
200
|
+
expect(req.method.id).to eq('prediction.trainedmodels.insert')
|
201
|
+
expect(req.body).to eq({'id' => '1'})
|
202
|
+
expect(req.parameters).not_to be_nil
|
203
|
+
expect(req.parameters[:project]).to eq('1')
|
204
204
|
end
|
205
205
|
|
206
206
|
it 'should return a valid request with a body when using resource name' do
|
207
207
|
req = @prediction.trainedmodels.insert(:project => '1').training({'id' => '1'})
|
208
|
-
req.
|
209
|
-
req.method.id.
|
210
|
-
req.training.
|
211
|
-
req.parameters.
|
212
|
-
req.parameters[:project].
|
208
|
+
expect(req).to be_a(Google::APIClient::Service::Request)
|
209
|
+
expect(req.method.id).to eq('prediction.trainedmodels.insert')
|
210
|
+
expect(req.training).to eq({'id' => '1'})
|
211
|
+
expect(req.parameters).not_to be_nil
|
212
|
+
expect(req.parameters[:project]).to eq('1')
|
213
213
|
end
|
214
214
|
end
|
215
215
|
end
|
@@ -228,7 +228,7 @@ describe Google::APIClient::Service do
|
|
228
228
|
it 'should make a valid call with an object body and media upload' do
|
229
229
|
conn = stub_connection do |stub|
|
230
230
|
stub.post('/upload/drive/v1/files?uploadType=multipart') do |env|
|
231
|
-
env.body.
|
231
|
+
expect(env.body).to be_a Faraday::CompositeReadIO
|
232
232
|
[200, {}, '{}']
|
233
233
|
end
|
234
234
|
end
|
@@ -254,22 +254,22 @@ describe Google::APIClient::Service do
|
|
254
254
|
|
255
255
|
it 'should return a valid request with a body and media upload' do
|
256
256
|
req = @drive.files.insert(:uploadType => 'multipart').body(@metadata).media(@media)
|
257
|
-
req.
|
258
|
-
req.method.id.
|
259
|
-
req.body.
|
260
|
-
req.media.
|
261
|
-
req.parameters.
|
262
|
-
req.parameters[:uploadType].
|
257
|
+
expect(req).to be_a(Google::APIClient::Service::Request)
|
258
|
+
expect(req.method.id).to eq('drive.files.insert')
|
259
|
+
expect(req.body).to eq(@metadata)
|
260
|
+
expect(req.media).to eq(@media)
|
261
|
+
expect(req.parameters).not_to be_nil
|
262
|
+
expect(req.parameters[:uploadType]).to eq('multipart')
|
263
263
|
end
|
264
264
|
|
265
265
|
it 'should return a valid request with a body and media upload when using resource name' do
|
266
266
|
req = @drive.files.insert(:uploadType => 'multipart').file(@metadata).media(@media)
|
267
|
-
req.
|
268
|
-
req.method.id.
|
269
|
-
req.file.
|
270
|
-
req.media.
|
271
|
-
req.parameters.
|
272
|
-
req.parameters[:uploadType].
|
267
|
+
expect(req).to be_a(Google::APIClient::Service::Request)
|
268
|
+
expect(req.method.id).to eq('drive.files.insert')
|
269
|
+
expect(req.file).to eq(@metadata)
|
270
|
+
expect(req.media).to eq(@media)
|
271
|
+
expect(req.parameters).not_to be_nil
|
272
|
+
expect(req.parameters[:uploadType]).to eq('multipart')
|
273
273
|
end
|
274
274
|
end
|
275
275
|
end
|
@@ -280,15 +280,15 @@ describe Google::APIClient::Service do
|
|
280
280
|
{:application_name => APPLICATION_NAME, :authenticated => false,
|
281
281
|
:cache_store => nil})
|
282
282
|
result = discovery.apis.get_rest(:api => 'discovery', :version => 'v1').execute
|
283
|
-
result.
|
284
|
-
result.data.name.
|
285
|
-
result.data.version.
|
283
|
+
expect(result).not_to be_nil
|
284
|
+
expect(result.data.name).to eq('discovery')
|
285
|
+
expect(result.data.version).to eq('v1')
|
286
286
|
end
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
290
290
|
|
291
|
-
describe Google::APIClient::Service::Result do
|
291
|
+
RSpec.describe Google::APIClient::Service::Result do
|
292
292
|
|
293
293
|
describe 'with the plus API' do
|
294
294
|
before do
|
@@ -307,8 +307,8 @@ describe Google::APIClient::Service::Result do
|
|
307
307
|
|
308
308
|
# Response double
|
309
309
|
@response = double("response")
|
310
|
-
@response.
|
311
|
-
@response.
|
310
|
+
allow(@response).to receive(:status).and_return(200)
|
311
|
+
allow(@response).to receive(:headers).and_return({
|
312
312
|
'etag' => '12345',
|
313
313
|
'x-google-apiary-auth-scopes' =>
|
314
314
|
'https://www.googleapis.com/auth/plus.me',
|
@@ -335,51 +335,54 @@ describe Google::APIClient::Service::Result do
|
|
335
335
|
"items": []
|
336
336
|
}
|
337
337
|
END_OF_STRING
|
338
|
-
@response.
|
338
|
+
allow(@response).to receive(:body).and_return(@body)
|
339
339
|
base_result = Google::APIClient::Result.new(@reference, @response)
|
340
340
|
@result = Google::APIClient::Service::Result.new(@request, base_result)
|
341
341
|
end
|
342
342
|
|
343
343
|
it 'should indicate a successful response' do
|
344
|
-
@result.error
|
344
|
+
expect(@result.error?).to be_falsey
|
345
345
|
end
|
346
346
|
|
347
347
|
it 'should return the correct next page token' do
|
348
|
-
@result.next_page_token.
|
348
|
+
expect(@result.next_page_token).to eq('NEXT+PAGE+TOKEN')
|
349
349
|
end
|
350
350
|
|
351
351
|
it 'generate a correct request when calling next_page' do
|
352
352
|
next_page_request = @result.next_page
|
353
|
-
next_page_request.parameters.
|
354
|
-
next_page_request.parameters['pageToken'].
|
353
|
+
expect(next_page_request.parameters).to include('pageToken')
|
354
|
+
expect(next_page_request.parameters['pageToken']).to eq('NEXT+PAGE+TOKEN')
|
355
355
|
@request.parameters.each_pair do |param, value|
|
356
|
-
next_page_request.parameters[param].
|
356
|
+
expect(next_page_request.parameters[param]).to eq(value)
|
357
357
|
end
|
358
358
|
end
|
359
359
|
|
360
360
|
it 'should return content type correctly' do
|
361
|
-
@result.media_type.
|
361
|
+
expect(@result.media_type).to eq('application/json')
|
362
362
|
end
|
363
363
|
|
364
364
|
it 'should return the body correctly' do
|
365
|
-
@result.body.
|
365
|
+
expect(@result.body).to eq(@body)
|
366
366
|
end
|
367
367
|
|
368
368
|
it 'should return the result data correctly' do
|
369
|
-
@result.data
|
370
|
-
@result.data.class.to_s.
|
369
|
+
expect(@result.data?).to be_truthy
|
370
|
+
expect(@result.data.class.to_s).to eq(
|
371
371
|
'Google::APIClient::Schema::Plus::V1::ActivityFeed'
|
372
|
-
|
373
|
-
@result.data.
|
374
|
-
@result.data.
|
375
|
-
@result.data.
|
372
|
+
)
|
373
|
+
expect(@result.data.kind).to eq('plus#activityFeed')
|
374
|
+
expect(@result.data.etag).to eq('FOO')
|
375
|
+
expect(@result.data.nextPageToken).to eq('NEXT+PAGE+TOKEN')
|
376
|
+
expect(@result.data.selfLink).to eq(
|
376
377
|
'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
|
377
|
-
|
378
|
+
)
|
379
|
+
expect(@result.data.nextLink).to eq(
|
378
380
|
'https://www.googleapis.com/plus/v1/people/foo/activities/public?' +
|
379
381
|
'maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN'
|
380
|
-
|
381
|
-
@result.data.
|
382
|
-
@result.data.
|
382
|
+
)
|
383
|
+
expect(@result.data.title).to eq('Plus Public Activity Feed for ')
|
384
|
+
expect(@result.data.id).to eq("123456790")
|
385
|
+
expect(@result.data.items).to be_empty
|
383
386
|
end
|
384
387
|
end
|
385
388
|
|
@@ -396,34 +399,36 @@ describe Google::APIClient::Service::Result do
|
|
396
399
|
"items": []
|
397
400
|
}
|
398
401
|
END_OF_STRING
|
399
|
-
@response.
|
402
|
+
allow(@response).to receive(:body).and_return(@body)
|
400
403
|
base_result = Google::APIClient::Result.new(@reference, @response)
|
401
404
|
@result = Google::APIClient::Service::Result.new(@request, base_result)
|
402
405
|
end
|
403
406
|
|
404
407
|
it 'should not return a next page token' do
|
405
|
-
@result.next_page_token.
|
408
|
+
expect(@result.next_page_token).to eq(nil)
|
406
409
|
end
|
407
410
|
|
408
411
|
it 'should return content type correctly' do
|
409
|
-
@result.media_type.
|
412
|
+
expect(@result.media_type).to eq('application/json')
|
410
413
|
end
|
411
414
|
|
412
415
|
it 'should return the body correctly' do
|
413
|
-
@result.body.
|
416
|
+
expect(@result.body).to eq(@body)
|
414
417
|
end
|
415
418
|
|
416
419
|
it 'should return the result data correctly' do
|
417
|
-
@result.data
|
418
|
-
@result.data.class.to_s.
|
420
|
+
expect(@result.data?).to be_truthy
|
421
|
+
expect(@result.data.class.to_s).to eq(
|
419
422
|
'Google::APIClient::Schema::Plus::V1::ActivityFeed'
|
420
|
-
|
421
|
-
@result.data.
|
422
|
-
@result.data.
|
423
|
+
)
|
424
|
+
expect(@result.data.kind).to eq('plus#activityFeed')
|
425
|
+
expect(@result.data.etag).to eq('FOO')
|
426
|
+
expect(@result.data.selfLink).to eq(
|
423
427
|
'https://www.googleapis.com/plus/v1/people/foo/activities/public?'
|
424
|
-
|
425
|
-
@result.data.
|
426
|
-
@result.data.
|
428
|
+
)
|
429
|
+
expect(@result.data.title).to eq('Plus Public Activity Feed for ')
|
430
|
+
expect(@result.data.id).to eq("123456790")
|
431
|
+
expect(@result.data.items).to be_empty
|
427
432
|
end
|
428
433
|
end
|
429
434
|
|
@@ -444,50 +449,77 @@ describe Google::APIClient::Service::Result do
|
|
444
449
|
}
|
445
450
|
}
|
446
451
|
END_OF_STRING
|
447
|
-
@response.
|
448
|
-
@response.
|
452
|
+
allow(@response).to receive(:body).and_return(@body)
|
453
|
+
allow(@response).to receive(:status).and_return(400)
|
449
454
|
base_result = Google::APIClient::Result.new(@reference, @response)
|
450
455
|
@result = Google::APIClient::Service::Result.new(@request, base_result)
|
451
456
|
end
|
452
457
|
|
453
458
|
it 'should return error status correctly' do
|
454
|
-
@result.error
|
459
|
+
expect(@result.error?).to be_truthy
|
455
460
|
end
|
456
461
|
|
457
462
|
it 'should return the correct error message' do
|
458
|
-
@result.error_message.
|
463
|
+
expect(@result.error_message).to eq('Parse Error')
|
459
464
|
end
|
460
465
|
|
461
466
|
it 'should return the body correctly' do
|
462
|
-
@result.body.
|
467
|
+
expect(@result.body).to eq(@body)
|
463
468
|
end
|
464
469
|
end
|
465
470
|
|
466
471
|
describe 'with 204 No Content response' do
|
467
472
|
before do
|
468
|
-
@response.
|
469
|
-
@response.
|
470
|
-
@response.
|
473
|
+
allow(@response).to receive(:body).and_return('')
|
474
|
+
allow(@response).to receive(:status).and_return(204)
|
475
|
+
allow(@response).to receive(:headers).and_return({})
|
471
476
|
base_result = Google::APIClient::Result.new(@reference, @response)
|
472
477
|
@result = Google::APIClient::Service::Result.new(@request, base_result)
|
473
478
|
end
|
474
479
|
|
475
480
|
it 'should indicate no data is available' do
|
476
|
-
@result.data
|
481
|
+
expect(@result.data?).to be_falsey
|
477
482
|
end
|
478
483
|
|
479
484
|
it 'should return nil for data' do
|
480
|
-
@result.data.
|
485
|
+
expect(@result.data).to eq(nil)
|
481
486
|
end
|
482
487
|
|
483
488
|
it 'should return nil for media_type' do
|
484
|
-
@result.media_type.
|
489
|
+
expect(@result.media_type).to eq(nil)
|
485
490
|
end
|
486
491
|
end
|
487
492
|
end
|
488
493
|
end
|
489
494
|
|
490
|
-
describe Google::APIClient::Service::BatchRequest do
|
495
|
+
RSpec.describe Google::APIClient::Service::BatchRequest do
|
496
|
+
|
497
|
+
include ConnectionHelpers
|
498
|
+
|
499
|
+
context 'with a service connection' do
|
500
|
+
before do
|
501
|
+
@conn = stub_connection do |stub|
|
502
|
+
stub.post('/batch') do |env|
|
503
|
+
[500, {'Content-Type' => 'application/json'}, '{}']
|
504
|
+
end
|
505
|
+
end
|
506
|
+
@discovery = Google::APIClient::Service.new('discovery', 'v1',
|
507
|
+
{:application_name => APPLICATION_NAME, :authorization => nil,
|
508
|
+
:cache_store => nil, :connection => @conn})
|
509
|
+
@calls = [
|
510
|
+
@discovery.apis.get_rest(:api => 'plus', :version => 'v1'),
|
511
|
+
@discovery.apis.get_rest(:api => 'discovery', :version => 'v1')
|
512
|
+
]
|
513
|
+
end
|
514
|
+
|
515
|
+
it 'should use the service connection' do
|
516
|
+
batch = @discovery.batch(@calls) do
|
517
|
+
end
|
518
|
+
batch.execute
|
519
|
+
@conn.verify
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
491
523
|
describe 'with the discovery API' do
|
492
524
|
before do
|
493
525
|
@discovery = Google::APIClient::Service.new('discovery', 'v1',
|
@@ -507,11 +539,11 @@ describe Google::APIClient::Service::BatchRequest do
|
|
507
539
|
block_called = 0
|
508
540
|
batch = @discovery.batch(@calls) do |result|
|
509
541
|
block_called += 1
|
510
|
-
result.status.
|
542
|
+
expect(result.status).to eq(200)
|
511
543
|
end
|
512
544
|
|
513
545
|
batch.execute
|
514
|
-
block_called.
|
546
|
+
expect(block_called).to eq(2)
|
515
547
|
end
|
516
548
|
|
517
549
|
it 'should execute both when using individual callbacks' do
|
@@ -520,19 +552,19 @@ describe Google::APIClient::Service::BatchRequest do
|
|
520
552
|
|
521
553
|
batch.add(@calls[0]) do |result|
|
522
554
|
call1_returned = true
|
523
|
-
result.status.
|
524
|
-
result.call_index.
|
555
|
+
expect(result.status).to eq(200)
|
556
|
+
expect(result.call_index).to eq(0)
|
525
557
|
end
|
526
558
|
|
527
559
|
batch.add(@calls[1]) do |result|
|
528
560
|
call2_returned = true
|
529
|
-
result.status.
|
530
|
-
result.call_index.
|
561
|
+
expect(result.status).to eq(200)
|
562
|
+
expect(result.call_index).to eq(1)
|
531
563
|
end
|
532
564
|
|
533
565
|
batch.execute
|
534
|
-
call1_returned.
|
535
|
-
call2_returned.
|
566
|
+
expect(call1_returned).to eq(true)
|
567
|
+
expect(call2_returned).to eq(true)
|
536
568
|
end
|
537
569
|
end
|
538
570
|
|
@@ -549,15 +581,15 @@ describe Google::APIClient::Service::BatchRequest do
|
|
549
581
|
batch = @discovery.batch(@calls) do |result|
|
550
582
|
block_called += 1
|
551
583
|
if result.call_index == 0
|
552
|
-
result.status.
|
584
|
+
expect(result.status).to eq(200)
|
553
585
|
else
|
554
|
-
result.status.
|
555
|
-
result.status.
|
586
|
+
expect(result.status).to be >= 400
|
587
|
+
expect(result.status).to be < 500
|
556
588
|
end
|
557
589
|
end
|
558
590
|
|
559
591
|
batch.execute
|
560
|
-
block_called.
|
592
|
+
expect(block_called).to eq(2)
|
561
593
|
end
|
562
594
|
|
563
595
|
it 'should execute both when using individual callbacks' do
|
@@ -566,21 +598,21 @@ describe Google::APIClient::Service::BatchRequest do
|
|
566
598
|
|
567
599
|
batch.add(@calls[0]) do |result|
|
568
600
|
call1_returned = true
|
569
|
-
result.status.
|
570
|
-
result.call_index.
|
601
|
+
expect(result.status).to eq(200)
|
602
|
+
expect(result.call_index).to eq(0)
|
571
603
|
end
|
572
604
|
|
573
605
|
batch.add(@calls[1]) do |result|
|
574
606
|
call2_returned = true
|
575
|
-
result.status.
|
576
|
-
result.status.
|
577
|
-
result.call_index.
|
607
|
+
expect(result.status).to be >= 400
|
608
|
+
expect(result.status).to be < 500
|
609
|
+
expect(result.call_index).to eq(1)
|
578
610
|
end
|
579
611
|
|
580
612
|
batch.execute
|
581
|
-
call1_returned.
|
582
|
-
call2_returned.
|
583
|
-
end
|
613
|
+
expect(call1_returned).to eq(true)
|
614
|
+
expect(call2_returned).to eq(true)
|
615
|
+
end
|
584
616
|
end
|
585
617
|
end
|
586
618
|
end
|