google-api-client 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/google-api-client.gemspec +4 -3
  4. data/lib/google/api_client/client_secrets.rb +1 -1
  5. data/lib/google/apis/core/download.rb +10 -1
  6. data/lib/google/apis/core/json_representation.rb +2 -2
  7. data/lib/google/apis/version.rb +1 -1
  8. data/samples/cli/.env +4 -0
  9. data/samples/web/.env +2 -0
  10. data/samples/web/views/home.erb +0 -1
  11. metadata +5 -71
  12. data/api_names_out.yaml +0 -28434
  13. data/generated/google/apis/sheets_v1.rb +0 -43
  14. data/generated/google/apis/sheets_v1/classes.rb +0 -4542
  15. data/generated/google/apis/sheets_v1/representations.rb +0 -1703
  16. data/generated/google/apis/sheets_v1/service.rb +0 -363
  17. data/script/generate +0 -105
  18. data/script/package +0 -8
  19. data/script/release +0 -15
  20. data/spec/fixtures/files/api_names.yaml +0 -3
  21. data/spec/fixtures/files/auth_stored_credentials.json +0 -8
  22. data/spec/fixtures/files/child/.gitignore +0 -0
  23. data/spec/fixtures/files/client_secrets.json +0 -1
  24. data/spec/fixtures/files/invalid.json +0 -1
  25. data/spec/fixtures/files/test.blah +0 -1
  26. data/spec/fixtures/files/test.txt +0 -1
  27. data/spec/fixtures/files/test_api.json +0 -440
  28. data/spec/google/api_client/auth/storage_spec.rb +0 -120
  29. data/spec/google/api_client/auth/storages/file_store_spec.rb +0 -39
  30. data/spec/google/api_client/auth/storages/redis_store_spec.rb +0 -68
  31. data/spec/google/api_client/client_secrets_spec.rb +0 -389
  32. data/spec/google/apis/core/api_command_spec.rb +0 -209
  33. data/spec/google/apis/core/batch_spec.rb +0 -142
  34. data/spec/google/apis/core/download_spec.rb +0 -103
  35. data/spec/google/apis/core/hashable_spec.rb +0 -60
  36. data/spec/google/apis/core/http_command_spec.rb +0 -303
  37. data/spec/google/apis/core/json_representation_spec.rb +0 -199
  38. data/spec/google/apis/core/service_spec.rb +0 -313
  39. data/spec/google/apis/core/upload_spec.rb +0 -300
  40. data/spec/google/apis/generated_spec.rb +0 -27
  41. data/spec/google/apis/generator/generator_spec.rb +0 -324
  42. data/spec/google/apis/logging_spec.rb +0 -100
  43. data/spec/google/apis/options_spec.rb +0 -40
  44. data/spec/integration_tests/adsense_spec.rb +0 -29
  45. data/spec/integration_tests/drive_spec.rb +0 -35
  46. data/spec/integration_tests/pubsub_spec.rb +0 -48
  47. data/spec/integration_tests/url_shortener_spec.rb +0 -45
  48. data/spec/spec_helper.rb +0 -153
  49. data/spec/spec_helper/load_path_spec.rb +0 -33
@@ -1,60 +0,0 @@
1
- # Copyright 2015 Google Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'spec_helper'
16
- require 'google/apis/core/hashable'
17
-
18
- RSpec.describe Google::Apis::Core::Hashable do
19
- let(:child_class) do
20
- Class.new do
21
- include Google::Apis::Core::Hashable
22
- attr_accessor :value
23
- end
24
- end
25
-
26
- let(:model_class) do
27
- Class.new do
28
- include Google::Apis::Core::Hashable
29
- attr_accessor :value
30
- attr_accessor :value2
31
- attr_accessor :children
32
- end
33
- end
34
-
35
- let(:model) do
36
- obj = model_class.new
37
- obj.value = 'hello'
38
- obj.value2 = {
39
- a: 'a'
40
- }
41
- child = child_class.new
42
- child.value = 'goodbye'
43
- obj.children = [child]
44
- obj
45
- end
46
-
47
- let(:hash) { model.to_h }
48
-
49
- it 'should serialize attributes' do
50
- expect(hash).to include(value: 'hello')
51
- end
52
-
53
- it 'should serialize collections' do
54
- expect(hash).to include(children: [{ value: 'goodbye' }])
55
- end
56
-
57
- it 'should serialize hashes' do
58
- expect(hash[:value2]).to include(a: 'a')
59
- end
60
- end
@@ -1,303 +0,0 @@
1
- # Copyright 2015 Google Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'spec_helper'
16
- require 'google/apis/core/http_command'
17
- require 'hurley/test'
18
-
19
- RSpec.describe Google::Apis::Core::HttpCommand do
20
- include TestHelpers
21
- include_context 'HTTP client'
22
-
23
- context('with credentials') do
24
- let(:command) do
25
- command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
26
- command.options.authorization = authorization
27
- command
28
- end
29
-
30
- context('that are refreshable') do
31
- let(:authorization) do
32
- calls = 0
33
- auth = object_double(Signet::OAuth2::Client.new)
34
- allow(auth).to receive(:apply!) do |header|
35
- header['Authorization'] = sprintf('Bearer a_token_value_%d', calls)
36
- calls += 1
37
- end
38
- auth
39
- end
40
-
41
- it 'should send credentials' do
42
- stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_return(body: %(Hello world))
43
- result = command.execute(client)
44
- expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
45
- .with { |req| req.headers['Authorization'] == 'Bearer a_token_value_0' }).to have_been_made
46
- end
47
-
48
- context('with authorizaton error') do
49
- before(:example) do
50
- stub_request(:get, 'https://www.googleapis.com/zoo/animals')
51
- .to_return(status: [401, 'Unauthorized'])
52
- .to_return(body: %(Hello world))
53
- end
54
-
55
- it 'should refresh if auth error received' do
56
- result = command.execute(client)
57
- expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
58
- .with { |req| req.headers['Authorization'] == 'Bearer a_token_value_1' }).to have_been_made
59
- end
60
-
61
- it 'should ignore retry count' do
62
- command.options.retries = 0
63
- result = command.execute(client)
64
- expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
65
- .with { |req| req.headers['Authorization'] == 'Bearer a_token_value_1' }).to have_been_made
66
- end
67
- end
68
- end
69
-
70
- context('that are bare tokens`') do
71
- let(:authorization) { 'a_token_value' }
72
-
73
- it 'should send credentials' do
74
- stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_return(body: %(Hello world))
75
- result = command.execute(client)
76
- expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
77
- .with { |req| expect(req.headers['Authorization']).to eql 'Bearer a_token_value' }).to have_been_made
78
- end
79
-
80
- it 'should send not refresh' do
81
- stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_return(status: [401, 'Unauthorized'])
82
- expect { command.execute(client) }.to raise_error(Google::Apis::AuthorizationError)
83
- end
84
- end
85
- end
86
-
87
- context('with a successful response') do
88
- let(:command) do
89
- Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
90
- end
91
-
92
- before(:example) do
93
- stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_return(body: %(Hello world))
94
- end
95
-
96
- it 'should return the response body if block not present' do
97
- result = command.execute(client)
98
- expect(result).to eql 'Hello world'
99
- end
100
-
101
- it 'should call block if present' do
102
- expect { |b| command.execute(client, &b) }.to yield_with_args('Hello world', nil)
103
- end
104
- end
105
-
106
- context('with server errors') do
107
- let(:command) do
108
- Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
109
- end
110
-
111
- before(:example) do
112
- stub_request(:get, 'https://www.googleapis.com/zoo/animals')
113
- .to_return(status: [500, 'Server error']).times(2)
114
- .to_return(body: %(Hello world))
115
- end
116
-
117
- it 'should return the response body' do
118
- result = command.execute(client)
119
- expect(result).to eql 'Hello world'
120
- end
121
-
122
- it 'should raise error if retries exceeded' do
123
- command.options.retries = 1
124
- expect { command.execute(client) }.to raise_error(Google::Apis::ServerError)
125
- end
126
-
127
-
128
- context('with retries exceeded') do
129
- before(:example) do
130
- command.options.retries = 1
131
- end
132
-
133
- let(:err) do
134
- begin
135
- command.execute(client)
136
- rescue Google::Apis::Error => e
137
- e
138
- end
139
- end
140
-
141
- it 'should raise error with HTTP status code' do
142
- expect(err.status_code).to eq 500
143
- end
144
-
145
- end
146
-
147
- context('with callbacks') do
148
- it 'should return the response body after retries' do
149
- expect { |b| command.execute(client, &b) }.to yield_with_args('Hello world', nil)
150
- end
151
- end
152
- end
153
-
154
- context('with options') do
155
- let(:command) do
156
- command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
157
- command.options.header = { 'X-Foo' => 'bar' }
158
- command
159
- end
160
-
161
- before(:example) do
162
- stub_request(:get, 'https://www.googleapis.com/zoo/animals')
163
- .to_return(body: %(Hello world))
164
- end
165
-
166
- it 'should send user headers' do
167
- result = command.execute(client)
168
- expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
169
- .with { |req| req.headers['X-Foo'] == 'bar' }).to have_been_made
170
- end
171
- end
172
-
173
-
174
- context('with redirects') do
175
- let(:command) do
176
- Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
177
- end
178
-
179
- before(:example) do
180
- stub_request(:get, 'https://www.googleapis.com/zoo/animals')
181
- .to_return(status: [302, 'Redirect'], headers: { 'Location' => 'https://zoo.googleapis.com/animals' })
182
- stub_request(:get, 'https://zoo.googleapis.com/animals')
183
- .to_return(body: %(Hello world))
184
- end
185
-
186
- it 'should return the response body' do
187
- result = command.execute(client)
188
- expect(result).to eql 'Hello world'
189
- end
190
- end
191
-
192
- context('with too many redirects') do
193
- let(:command) do
194
- Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
195
- end
196
-
197
- before(:example) do
198
- stub_request(:get, 'https://www.googleapis.com/zoo/animals')
199
- .to_return(status: [302, 'Redirect'], headers: { 'Location' => 'https://www.googleapis.com/zoo/animals' }).times(6)
200
- end
201
-
202
- it 'should raise error if retries exceeded' do
203
- expect { command.execute(client) }.to raise_error(Google::Apis::RedirectError)
204
- end
205
- end
206
-
207
- context('with no server response') do
208
- let(:command) do
209
- Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
210
- end
211
-
212
- before(:example) do
213
- stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_timeout
214
- end
215
-
216
- it 'should raise transmission error' do
217
- expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError)
218
- end
219
- end
220
-
221
- context('with invalid status code') do
222
- let(:command) do
223
- Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
224
- end
225
-
226
- before(:example) do
227
- stub_request(:get, 'https://www.googleapis.com/zoo/animals')
228
- .to_return(status: [0, 'Wat!?'])
229
- end
230
-
231
- it 'should raise transmission error' do
232
- expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError)
233
- end
234
- end
235
-
236
- context('with client errors') do
237
- let(:command) do
238
- Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
239
- end
240
-
241
- before(:example) do
242
- stub_request(:get, 'https://www.googleapis.com/zoo/animals')
243
- .to_return(status: [400, 'Invalid request'])
244
- end
245
-
246
- it 'should raise error without retry' do
247
- command.options.retries = 1
248
- expect { command.execute(client) }.to raise_error(Google::Apis::ClientError)
249
- end
250
-
251
- it 'should call block if present' do
252
- expect { |b| command.execute(client, &b) }.to yield_with_args(nil, an_instance_of(Google::Apis::ClientError))
253
- end
254
-
255
- it 'should not swallow errors raised in block' do
256
- expect { command.execute(client) { raise "Potatoes detected in tailpipe" } }.to raise_error("Potatoes detected in tailpipe")
257
- end
258
- end
259
-
260
- it 'should send repeated query parameters' do
261
- stub_request(:get, 'https://www.googleapis.com/zoo/animals?a=1&a=2&a=3')
262
- .to_return(status: [200, ''])
263
- command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
264
- command.query['a'] = [1,2,3]
265
- command.execute(client)
266
- end
267
-
268
- it 'should not remove initial query parameters' do
269
- stub_request(:get, 'https://www.googleapis.com/zoo/animals?a=1&a=2&a=3&foo=bar')
270
- .to_return(status: [200, ''])
271
- command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals?foo=bar')
272
- command.query['a'] = [1,2,3]
273
- command.execute(client)
274
- end
275
-
276
- it 'should send falsey query parameters' do
277
- stub_request(:get, 'https://www.googleapis.com/zoo/animals?a=0&b=false')
278
- .to_return(status: [200, ''])
279
- command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
280
- command.query['a'] = 0
281
- command.query['b'] = false
282
- command.execute(client)
283
- end
284
-
285
- it 'should form encode parameters when method is POST and no body present' do
286
- stub_request(:post, 'https://www.googleapis.com/zoo/animals')
287
- .with(body: 'a=1&a=2&a=3&b=hello&c=&d=0')
288
- .to_return(status: [200, ''])
289
- command = Google::Apis::Core::HttpCommand.new(:post, 'https://www.googleapis.com/zoo/animals')
290
- command.query['a'] = [1,2,3]
291
- command.query['b'] = 'hello'
292
- command.query['c'] = nil
293
- command.query['d'] = 0
294
- command.execute(client)
295
- end
296
-
297
- it 'should raise transmission error instead of socket error' do
298
- stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_raise(SocketError)
299
- command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
300
- command.options.retries = 0
301
- expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError)
302
- end
303
- end
@@ -1,199 +0,0 @@
1
- # Copyright 2015 Google Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'spec_helper'
16
- require 'google/apis/core/json_representation'
17
-
18
- RSpec.describe Google::Apis::Core::JsonRepresentation do
19
- let(:child_class) do
20
- Class.new do
21
- attr_accessor :value
22
- end
23
- end
24
-
25
- let(:model_class) do
26
- Class.new do
27
- attr_accessor :unset_value
28
- attr_accessor :nil_value
29
- attr_accessor :numeric_value
30
- attr_accessor :string_value
31
- attr_accessor :boolean_value_true
32
- attr_accessor :boolean_value_false
33
- attr_accessor :date_value
34
- attr_accessor :bytes_value
35
- attr_accessor :items
36
- attr_accessor :child
37
- attr_accessor :children
38
- end
39
- end
40
-
41
- let(:representer_class) do
42
- klass = child_class
43
- Class.new(Google::Apis::Core::JsonRepresentation) do
44
- property :unset_value, as: 'unsetValue'
45
- property :nil_value, as: 'nilValue'
46
- property :numeric_value, as: 'numericValue'
47
- property :string_value, as: 'stringValue'
48
- property :boolean_value_true, as: 'booleanValueTrue'
49
- property :boolean_value_false, as: 'booleanValueFalse'
50
- property :date_value, as: 'dateValue', type: DateTime
51
- property :bytes_value, as: 'bytesValue', base64: true
52
- property :items
53
- property :child, class: klass do
54
- property :value
55
- end
56
- collection :children, class: klass do
57
- property :value
58
- end
59
- end
60
- end
61
-
62
- shared_examples 'it serializes' do
63
- it 'does not serialize unset values' do
64
- expect(json).not_to have_json_path('unsetValue')
65
- end
66
-
67
- it 'serializes explicit nil values' do
68
- expect(json).to be_json_eql(%(null)).at_path('nilValue')
69
- end
70
-
71
- it 'serializes numeric values' do
72
- expect(json).to be_json_eql(%(123)).at_path('numericValue')
73
- end
74
-
75
- it 'serializes string values' do
76
- expect(json).to be_json_eql(%("test")).at_path('stringValue')
77
- end
78
-
79
- it 'serializes boolean values' do
80
- expect(json).to be_json_eql(%(true)).at_path('booleanValueTrue')
81
- expect(json).to be_json_eql(%(false)).at_path('booleanValueFalse')
82
- end
83
-
84
- it 'serializes date values' do
85
- expect(json).to be_json_eql(%("2015-05-01T12:00:00.000+00:00")).at_path('dateValue')
86
- end
87
-
88
- it 'serializes byte values to base64' do
89
- expect(json).to be_json_eql(%("SGVsbG8gd29ybGQ=")).at_path('bytesValue')
90
- end
91
-
92
- it 'serializes basic collections' do
93
- expect(json).to be_json_eql(%([1,2,3])).at_path('items')
94
- end
95
-
96
- it 'serializes nested objects' do
97
- expect(json).to be_json_eql(%({"value" : "child"})).at_path('child')
98
- end
99
-
100
- it 'serializes object collections' do
101
- expect(json).to be_json_eql(%([{"value" : "child"}])).at_path('children')
102
- end
103
- end
104
-
105
- context 'with model object' do
106
- let(:json) { representer_class.new(model).to_json(skip_undefined: true) }
107
- let(:model) do
108
- model = model_class.new
109
- model.nil_value = nil
110
- model.numeric_value = 123
111
- model.string_value = 'test'
112
- model.date_value = DateTime.new(2015, 5, 1, 12)
113
- model.boolean_value_true = true
114
- model.boolean_value_false = false
115
- model.bytes_value = 'Hello world'
116
- model.items = [1, 2, 3]
117
- model.child = child_class.new
118
- model.child.value = 'child'
119
- model.children = [model.child]
120
- model
121
- end
122
-
123
- include_examples 'it serializes'
124
- end
125
-
126
- context 'with hash' do
127
- let(:json) { representer_class.new(model).to_json(skip_undefined: true) }
128
- let(:model) do
129
- {
130
- nil_value: nil,
131
- string_value: 'test',
132
- numeric_value: 123,
133
- date_value: DateTime.new(2015, 5, 1, 12),
134
- boolean_value_true: true,
135
- boolean_value_false: false,
136
- bytes_value: 'Hello world',
137
- items: [1, 2, 3],
138
- child: {
139
- value: 'child'
140
- },
141
- children: [{ value: 'child' }]
142
- }
143
- end
144
-
145
- include_examples 'it serializes'
146
- end
147
-
148
- context 'when de-serializing' do
149
- let(:model) { representer_class.new(model_class.new).from_json(json) }
150
- let(:json) do
151
- json = <<EOF
152
- { "stringValue": "test",
153
- "nilValue": null,
154
- "booleanValueTrue": true,
155
- "booleanValueFalse": false,
156
- "numericValue": 123,
157
- "dateValue": "2015-05-01T12:00:00+00:00",
158
- "bytesValue": "SGVsbG8gd29ybGQ=",
159
- "items": [1,2,3],
160
- "child": {"value" : "hello"},
161
- "children": [{"value" : "hello"}]
162
- }
163
- EOF
164
- end
165
-
166
- it 'deserializes string values' do
167
- expect(model.string_value).to eql 'test'
168
- end
169
-
170
- it 'deserializes null values' do
171
- expect(model.nil_value).to be_nil
172
- end
173
-
174
- it 'deserializes numeric values' do
175
- expect(model.numeric_value).to eql 123
176
- end
177
-
178
- it 'deserializes boolean values' do
179
- expect(model.boolean_value_true).to be_truthy
180
- expect(model.boolean_value_false).to be_falsey
181
- end
182
-
183
- it 'deserializes date values' do
184
- expect(model.date_value).to eql DateTime.new(2015, 5, 1, 12)
185
- end
186
-
187
- it 'deserializes basic collections' do
188
- expect(model.items).to contain_exactly(1, 2, 3)
189
- end
190
-
191
- it 'deserializes nested objects' do
192
- expect(model.child.value).to eql 'hello'
193
- end
194
-
195
- it 'serializes object collections' do
196
- expect(model.children[0].value).to eql 'hello'
197
- end
198
- end
199
- end