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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/google-api-client.gemspec +4 -3
- data/lib/google/api_client/client_secrets.rb +1 -1
- data/lib/google/apis/core/download.rb +10 -1
- data/lib/google/apis/core/json_representation.rb +2 -2
- data/lib/google/apis/version.rb +1 -1
- data/samples/cli/.env +4 -0
- data/samples/web/.env +2 -0
- data/samples/web/views/home.erb +0 -1
- metadata +5 -71
- data/api_names_out.yaml +0 -28434
- data/generated/google/apis/sheets_v1.rb +0 -43
- data/generated/google/apis/sheets_v1/classes.rb +0 -4542
- data/generated/google/apis/sheets_v1/representations.rb +0 -1703
- data/generated/google/apis/sheets_v1/service.rb +0 -363
- data/script/generate +0 -105
- data/script/package +0 -8
- data/script/release +0 -15
- data/spec/fixtures/files/api_names.yaml +0 -3
- data/spec/fixtures/files/auth_stored_credentials.json +0 -8
- data/spec/fixtures/files/child/.gitignore +0 -0
- data/spec/fixtures/files/client_secrets.json +0 -1
- data/spec/fixtures/files/invalid.json +0 -1
- data/spec/fixtures/files/test.blah +0 -1
- data/spec/fixtures/files/test.txt +0 -1
- data/spec/fixtures/files/test_api.json +0 -440
- data/spec/google/api_client/auth/storage_spec.rb +0 -120
- data/spec/google/api_client/auth/storages/file_store_spec.rb +0 -39
- data/spec/google/api_client/auth/storages/redis_store_spec.rb +0 -68
- data/spec/google/api_client/client_secrets_spec.rb +0 -389
- data/spec/google/apis/core/api_command_spec.rb +0 -209
- data/spec/google/apis/core/batch_spec.rb +0 -142
- data/spec/google/apis/core/download_spec.rb +0 -103
- data/spec/google/apis/core/hashable_spec.rb +0 -60
- data/spec/google/apis/core/http_command_spec.rb +0 -303
- data/spec/google/apis/core/json_representation_spec.rb +0 -199
- data/spec/google/apis/core/service_spec.rb +0 -313
- data/spec/google/apis/core/upload_spec.rb +0 -300
- data/spec/google/apis/generated_spec.rb +0 -27
- data/spec/google/apis/generator/generator_spec.rb +0 -324
- data/spec/google/apis/logging_spec.rb +0 -100
- data/spec/google/apis/options_spec.rb +0 -40
- data/spec/integration_tests/adsense_spec.rb +0 -29
- data/spec/integration_tests/drive_spec.rb +0 -35
- data/spec/integration_tests/pubsub_spec.rb +0 -48
- data/spec/integration_tests/url_shortener_spec.rb +0 -45
- data/spec/spec_helper.rb +0 -153
- data/spec/spec_helper/load_path_spec.rb +0 -33
@@ -1,209 +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/api_command'
|
17
|
-
require 'google/apis/core/json_representation'
|
18
|
-
require 'hurley/test'
|
19
|
-
|
20
|
-
RSpec.describe Google::Apis::Core::HttpCommand do
|
21
|
-
include TestHelpers
|
22
|
-
include_context 'HTTP client'
|
23
|
-
|
24
|
-
let(:model_class) do
|
25
|
-
Class.new do
|
26
|
-
attr_accessor :value
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:representer_class) do
|
31
|
-
Class.new(Google::Apis::Core::JsonRepresentation) do
|
32
|
-
property :value
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context('with a request body') do
|
37
|
-
let(:command) do
|
38
|
-
request = model_class.new
|
39
|
-
request.value = 'hello'
|
40
|
-
command = Google::Apis::Core::ApiCommand.new(:post, 'https://www.googleapis.com/zoo/animals')
|
41
|
-
command.request_representation = representer_class
|
42
|
-
command.request_object = request
|
43
|
-
command
|
44
|
-
end
|
45
|
-
|
46
|
-
before(:example) do
|
47
|
-
stub_request(:post, 'https://www.googleapis.com/zoo/animals')
|
48
|
-
.to_return(headers: { 'Content-Type' => 'application/json' }, body: %({}))
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should serialize the request object' do
|
52
|
-
command.execute(client)
|
53
|
-
expect(a_request(:post, 'https://www.googleapis.com/zoo/animals').with do |req|
|
54
|
-
be_json_eql(%({"value":"hello"})).matches?(req.body)
|
55
|
-
end).to have_been_made
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context('with a JSON response') do
|
60
|
-
let(:command) do
|
61
|
-
command = Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
62
|
-
command.response_representation = representer_class
|
63
|
-
command.response_class = model_class
|
64
|
-
command
|
65
|
-
end
|
66
|
-
|
67
|
-
before(:example) do
|
68
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
69
|
-
.to_return(headers: { 'Content-Type' => 'application/json' }, body: %({"value" : "hello"}))
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should return a model instance' do
|
73
|
-
result = command.execute(client)
|
74
|
-
expect(result).to be_kind_of(model_class)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should return a populated object' do
|
78
|
-
result = command.execute(client)
|
79
|
-
expect(result.value).to eql 'hello'
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context('with an invalid content-type response') do
|
84
|
-
let(:command) do
|
85
|
-
command = Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
86
|
-
command.response_representation = representer_class
|
87
|
-
command.response_class = model_class
|
88
|
-
command
|
89
|
-
end
|
90
|
-
|
91
|
-
before(:example) do
|
92
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
93
|
-
.to_return(headers: { 'Content-Type' => 'text/plain' }, body: %(Ignore me))
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should return nil' do
|
97
|
-
result = command.execute(client)
|
98
|
-
expect(result).to be_nil
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
context('with a field parameter') do
|
104
|
-
let(:command) do
|
105
|
-
command = Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
106
|
-
command.query['fields'] = ':items(:id, :long_name, :a_really_long_name), shouldBeLeftAlone '
|
107
|
-
command
|
108
|
-
end
|
109
|
-
|
110
|
-
before(:example) do
|
111
|
-
stub_request(:get, /.*/)
|
112
|
-
.to_return(headers: { 'Content-Type' => 'application/json' }, body: %({}))
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'should normalize fields params' do
|
116
|
-
command.execute(client)
|
117
|
-
expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
|
118
|
-
.with(query: { 'fields' => 'items(id, longName, aReallyLongName), shouldBeLeftAlone ' })) .to have_been_made
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context('with a rate limit response') do
|
123
|
-
let(:command) do
|
124
|
-
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
125
|
-
end
|
126
|
-
|
127
|
-
before(:example) do
|
128
|
-
json = <<EOF
|
129
|
-
{
|
130
|
-
"error": {
|
131
|
-
"errors": [
|
132
|
-
{
|
133
|
-
"domain": "global",
|
134
|
-
"reason": "rateLimitExceeded",
|
135
|
-
"message": "Rate limit exceeded"
|
136
|
-
}
|
137
|
-
],
|
138
|
-
"code": 403,
|
139
|
-
"message": "Rate limit exceeded"
|
140
|
-
}
|
141
|
-
}
|
142
|
-
EOF
|
143
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
144
|
-
.to_return(status: [403, 'Rate Limit Exceeded'], headers: { 'Content-Type' => 'application/json' }, body: json)
|
145
|
-
.to_return(headers: { 'Content-Type' => 'application/json' }, body: %({}))
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'should retry' do
|
149
|
-
command.execute(client)
|
150
|
-
expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')).to have_been_made.times(2)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context('with a client error response') do
|
155
|
-
let(:command) do
|
156
|
-
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
157
|
-
end
|
158
|
-
|
159
|
-
before(:example) do
|
160
|
-
json = <<EOF
|
161
|
-
{
|
162
|
-
"error": {
|
163
|
-
"errors": [
|
164
|
-
{
|
165
|
-
"domain": "global",
|
166
|
-
"reason": "timeRangeEmpty",
|
167
|
-
"message": "The specified time range is empty."
|
168
|
-
}
|
169
|
-
],
|
170
|
-
"code": 400,
|
171
|
-
"message": "The specified time range is empty."
|
172
|
-
}
|
173
|
-
}
|
174
|
-
EOF
|
175
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
176
|
-
.to_return(status: [400, 'Bad Request'], headers: { 'Content-Type' => 'application/json' }, body: json)
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'should raise client error' do
|
180
|
-
expect { command.execute(client) }.to raise_error(Google::Apis::ClientError)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'should raise an error with the reason and message' do
|
184
|
-
expect { command.execute(client) }.to raise_error(
|
185
|
-
/timeRangeEmpty: The specified time range is empty/)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context('with an empty error body') do
|
190
|
-
let(:command) do
|
191
|
-
Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
192
|
-
end
|
193
|
-
|
194
|
-
before(:example) do
|
195
|
-
json = %({})
|
196
|
-
|
197
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
198
|
-
.to_return(status: [403, 'Rate Limit Exceeded'], headers: { 'Content-Type' => 'application/json' }, body: json)
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'should raise client error' do
|
202
|
-
expect { command.execute(client) }.to raise_error(Google::Apis::ClientError)
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'should use the default error message' do
|
206
|
-
expect { command.execute(client) }.to raise_error(/Invalid request/)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
@@ -1,142 +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/batch'
|
17
|
-
require 'google/apis/core/json_representation'
|
18
|
-
require 'hurley/test'
|
19
|
-
|
20
|
-
RSpec.describe Google::Apis::Core::BatchCommand do
|
21
|
-
include TestHelpers
|
22
|
-
include_context 'HTTP client'
|
23
|
-
|
24
|
-
let(:command) do
|
25
|
-
command = Google::Apis::Core::BatchCommand.new(:post, 'https://www.googleapis.com/batch')
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:get_command) { Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals/1') }
|
29
|
-
|
30
|
-
let(:post_with_string_command) do
|
31
|
-
command = Google::Apis::Core::HttpCommand.new(:post, 'https://www.googleapis.com/zoo/animals/2')
|
32
|
-
command.body = 'Hello world'
|
33
|
-
command.header[:content_type] = 'text/plain'
|
34
|
-
command
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:post_with_io_command) do
|
38
|
-
command = Google::Apis::Core::HttpCommand.new(:post, 'https://www.googleapis.com/zoo/animals/3')
|
39
|
-
command.body = StringIO.new('Goodbye!')
|
40
|
-
command.header[:content_type] = 'text/plain'
|
41
|
-
command
|
42
|
-
end
|
43
|
-
|
44
|
-
before(:example) do
|
45
|
-
allow(SecureRandom).to receive(:uuid).and_return('ffe23d1b-e8f7-47f5-8c01-2a30cf8ecb8f')
|
46
|
-
|
47
|
-
response = <<EOF
|
48
|
-
--batch123
|
49
|
-
Content-Type: application/http
|
50
|
-
Content-ID: <response-ffe23d1b-e8f7-47f5-8c01-2a30cf8ecb8f+0>
|
51
|
-
|
52
|
-
HTTP/1.1 200 OK
|
53
|
-
Content-Type: text/plain; charset=UTF-8
|
54
|
-
|
55
|
-
Hello
|
56
|
-
--batch123
|
57
|
-
Content-Type: application/http
|
58
|
-
Content-ID: <response-ffe23d1b-e8f7-47f5-8c01-2a30cf8ecb8f+2>
|
59
|
-
|
60
|
-
HTTP/1.1 500 Server Error
|
61
|
-
Content-Type: text/plain; charset=UTF-8
|
62
|
-
|
63
|
-
Error!
|
64
|
-
--batch123
|
65
|
-
Content-Type: application/http
|
66
|
-
Content-ID: <response-ffe23d1b-e8f7-47f5-8c01-2a30cf8ecb8f+1>
|
67
|
-
|
68
|
-
HTTP/1.1 200 OK
|
69
|
-
Content-Type: text/plain; charset=UTF-8
|
70
|
-
|
71
|
-
world
|
72
|
-
--batch123--
|
73
|
-
EOF
|
74
|
-
stub_request(:post, 'https://www.googleapis.com/batch')
|
75
|
-
.to_return(headers: { 'Content-Type' => 'multipart/mixed; boundary=batch123' }, body: response)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should send content' do
|
79
|
-
b = ->(_res, _err) {}
|
80
|
-
command.add(get_command, &b)
|
81
|
-
command.add(post_with_string_command, &b)
|
82
|
-
command.add(post_with_io_command, &b)
|
83
|
-
command.execute(client)
|
84
|
-
|
85
|
-
expected_body = <<EOF.gsub(/\n/, "\r\n")
|
86
|
-
--RubyApiBatchRequest
|
87
|
-
Content-Length: 58
|
88
|
-
Content-ID: <ffe23d1b-e8f7-47f5-8c01-2a30cf8ecb8f+0>
|
89
|
-
Content-Type: application/http
|
90
|
-
Content-Transfer-Encoding: binary
|
91
|
-
|
92
|
-
GET /zoo/animals/1? HTTP/1.1
|
93
|
-
Host: www.googleapis.com
|
94
|
-
|
95
|
-
|
96
|
-
--RubyApiBatchRequest
|
97
|
-
Content-Length: 96
|
98
|
-
Content-ID: <ffe23d1b-e8f7-47f5-8c01-2a30cf8ecb8f+1>
|
99
|
-
Content-Type: application/http
|
100
|
-
Content-Transfer-Encoding: binary
|
101
|
-
|
102
|
-
POST /zoo/animals/2? HTTP/1.1
|
103
|
-
Content-Type: text/plain
|
104
|
-
Host: www.googleapis.com
|
105
|
-
|
106
|
-
Hello world
|
107
|
-
--RubyApiBatchRequest
|
108
|
-
Content-Length: 93
|
109
|
-
Content-ID: <ffe23d1b-e8f7-47f5-8c01-2a30cf8ecb8f+2>
|
110
|
-
Content-Type: application/http
|
111
|
-
Content-Transfer-Encoding: binary
|
112
|
-
|
113
|
-
POST /zoo/animals/3? HTTP/1.1
|
114
|
-
Content-Type: text/plain
|
115
|
-
Host: www.googleapis.com
|
116
|
-
|
117
|
-
Goodbye!
|
118
|
-
--RubyApiBatchRequest--
|
119
|
-
|
120
|
-
EOF
|
121
|
-
expect(a_request(:post, 'https://www.googleapis.com/batch').with(body: expected_body)).to have_been_made
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should send decode responses' do
|
125
|
-
expect do |b|
|
126
|
-
command.add(get_command) do |res, err|
|
127
|
-
b.to_proc.call(1, res, err)
|
128
|
-
end
|
129
|
-
command.add(post_with_string_command) do |res, err|
|
130
|
-
b.to_proc.call(2, res, err)
|
131
|
-
end
|
132
|
-
command.add(post_with_io_command) do |res, err|
|
133
|
-
b.to_proc.call(3, res, err)
|
134
|
-
end
|
135
|
-
command.execute(client)
|
136
|
-
end.to yield_successive_args([1, 'Hello', nil], [3, nil, an_instance_of(Google::Apis::ServerError)], [2, 'world', nil],)
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'should raise error if batch is empty' do
|
140
|
-
expect { command.execute(client) }.to raise_error(Google::Apis::BatchError)
|
141
|
-
end
|
142
|
-
end
|
@@ -1,103 +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/download'
|
17
|
-
require 'google/apis/core/json_representation'
|
18
|
-
require 'hurley/test'
|
19
|
-
require 'tempfile'
|
20
|
-
require 'tmpdir'
|
21
|
-
|
22
|
-
RSpec.describe Google::Apis::Core::DownloadCommand do
|
23
|
-
include TestHelpers
|
24
|
-
include_context 'HTTP client'
|
25
|
-
|
26
|
-
let(:command) do
|
27
|
-
command = Google::Apis::Core::DownloadCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
28
|
-
command.download_dest = dest
|
29
|
-
command
|
30
|
-
end
|
31
|
-
|
32
|
-
shared_examples 'should download' do
|
33
|
-
context 'with successful response' do
|
34
|
-
before(:example) do
|
35
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
36
|
-
.to_return(headers: { 'Content-Type' => 'application/json' }, body: %(Hello world))
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should not include a range header' do
|
40
|
-
command.execute(client)
|
41
|
-
expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
|
42
|
-
.with { |req| !req.headers.key?('Range') }
|
43
|
-
).to have_been_made
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should receive content' do
|
47
|
-
expect(received).to eql 'Hello world'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'with disconnects' do
|
52
|
-
before(:example) do
|
53
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
54
|
-
.to_return(body: ['Hello ', Timeout::Error])
|
55
|
-
.to_return(body: 'world')
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should receive entire content' do
|
59
|
-
expect(received).to eql('Hello world')
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'with redirect' do
|
64
|
-
before(:example) do
|
65
|
-
stub_request(:get, 'https://www.googleapis.com/zoo/animals')
|
66
|
-
.to_return(status: [302, 'Content moved'], headers: { 'Location' => 'https://content.googleapis.com/files/12345' }, body: %(Content moved))
|
67
|
-
stub_request(:get, 'https://content.googleapis.com/files/12345')
|
68
|
-
.to_return(headers: { 'Content-Type' => 'application/json' }, body: %(Hello world))
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should receive content' do
|
72
|
-
expect(received).to eql 'Hello world'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'with default destination' do
|
78
|
-
let(:dest) { nil }
|
79
|
-
let(:received) { command.execute(client).string }
|
80
|
-
include_examples 'should download'
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'with IO destination' do
|
84
|
-
let(:dest) { Tempfile.new('test') }
|
85
|
-
let(:received) do
|
86
|
-
command.execute(client)
|
87
|
-
dest.rewind
|
88
|
-
dest.read
|
89
|
-
end
|
90
|
-
|
91
|
-
include_examples 'should download'
|
92
|
-
end
|
93
|
-
|
94
|
-
context 'with filename destination' do
|
95
|
-
let(:dest) { File.join(Dir.mktmpdir, 'test.txt') }
|
96
|
-
let(:received) do
|
97
|
-
command.execute(client)
|
98
|
-
File.read(dest)
|
99
|
-
end
|
100
|
-
|
101
|
-
include_examples 'should download'
|
102
|
-
end
|
103
|
-
end
|