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
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rails/railtie'
|
1
2
|
require 'google/api_client/logging'
|
2
3
|
|
3
4
|
module Google
|
@@ -9,7 +10,7 @@ module Google
|
|
9
10
|
#
|
10
11
|
class Railtie < Rails::Railtie
|
11
12
|
initializer 'google-api-client' do |app|
|
12
|
-
Google::APIClient.logger =
|
13
|
+
Google::APIClient.logger = app.logger
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
@@ -14,7 +14,6 @@
|
|
14
14
|
|
15
15
|
require 'faraday'
|
16
16
|
require 'faraday/request/multipart'
|
17
|
-
require 'multi_json'
|
18
17
|
require 'compat/multi_json'
|
19
18
|
require 'addressable/uri'
|
20
19
|
require 'stringio'
|
@@ -168,7 +167,7 @@ module Google
|
|
168
167
|
|
169
168
|
# Resumamble slightly different than other upload protocols in that it requires at least
|
170
169
|
# 2 requests.
|
171
|
-
if result.status == 200 && self.upload_type == 'resumable'
|
170
|
+
if result.status == 200 && self.upload_type == 'resumable' && self.media
|
172
171
|
upload = result.resumable_upload
|
173
172
|
unless upload.complete?
|
174
173
|
logger.debug { "#{self.class} Sending upload body" }
|
@@ -182,8 +182,9 @@ module Google
|
|
182
182
|
# Build a request for fetching the next page of data
|
183
183
|
#
|
184
184
|
# @return [Google::APIClient::Request]
|
185
|
-
# API request for retrieving next page
|
185
|
+
# API request for retrieving next page, nil if no page token available
|
186
186
|
def next_page
|
187
|
+
return nil unless self.next_page_token
|
187
188
|
merged_parameters = Hash[self.reference.parameters].merge({
|
188
189
|
self.page_token_param => self.next_page_token
|
189
190
|
})
|
@@ -215,8 +216,9 @@ module Google
|
|
215
216
|
# Build a request for fetching the previous page of data
|
216
217
|
#
|
217
218
|
# @return [Google::APIClient::Request]
|
218
|
-
# API request for retrieving previous page
|
219
|
+
# API request for retrieving previous page, nil if no page token available
|
219
220
|
def prev_page
|
221
|
+
return nil unless self.prev_page_token
|
220
222
|
merged_parameters = Hash[self.reference.parameters].merge({
|
221
223
|
self.page_token_param => self.prev_page_token
|
222
224
|
})
|
@@ -120,7 +120,7 @@ module Google
|
|
120
120
|
if options.include? :cache_store
|
121
121
|
@cache_store = options[:cache_store]
|
122
122
|
else
|
123
|
-
cache_exists = File.
|
123
|
+
cache_exists = File.exists?(DEFAULT_CACHE_FILE)
|
124
124
|
if (cache_exists && File.writable?(DEFAULT_CACHE_FILE)) ||
|
125
125
|
(!cache_exists && File.writable?(Dir.pwd))
|
126
126
|
@cache_store = Google::APIClient::Service::SimpleFileStore.new(
|
@@ -225,7 +225,7 @@ module Google
|
|
225
225
|
result = @client.execute(params)
|
226
226
|
return Google::APIClient::Service::Result.new(request, result)
|
227
227
|
elsif request.instance_of? Google::APIClient::Service::BatchRequest
|
228
|
-
@client.execute(request.base_batch)
|
228
|
+
@client.execute(request.base_batch, {:connection => @connection})
|
229
229
|
end
|
230
230
|
end
|
231
231
|
end
|
@@ -80,6 +80,13 @@ module Google
|
|
80
80
|
:api_method => call.method,
|
81
81
|
:parameters => call.parameters
|
82
82
|
}
|
83
|
+
if call.respond_to? :body
|
84
|
+
if call.body.respond_to? :to_hash
|
85
|
+
base_call[:body_object] = call.body
|
86
|
+
else
|
87
|
+
base_call[:body] = call.body
|
88
|
+
end
|
89
|
+
end
|
83
90
|
@base_batch.add(base_call) do |base_result|
|
84
91
|
result = Google::APIClient::Service::BatchedCallResult.new(
|
85
92
|
call, base_result)
|
@@ -12,6 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require 'active_support/inflector'
|
16
|
+
|
15
17
|
module Google
|
16
18
|
class APIClient
|
17
19
|
class Service
|
@@ -25,7 +27,7 @@ module Google
|
|
25
27
|
|
26
28
|
# Handle resources.
|
27
29
|
root.discovered_resources.each do |resource|
|
28
|
-
method_name =
|
30
|
+
method_name = ActiveSupport::Inflector.underscore(resource.name).to_sym
|
29
31
|
if !self.respond_to?(method_name)
|
30
32
|
metaclass.send(:define_method, method_name) do
|
31
33
|
Google::APIClient::Service::Resource.new(service, resource)
|
@@ -35,7 +37,7 @@ module Google
|
|
35
37
|
|
36
38
|
# Handle methods.
|
37
39
|
root.discovered_methods.each do |method|
|
38
|
-
method_name =
|
40
|
+
method_name = ActiveSupport::Inflector.underscore(method.name).to_sym
|
39
41
|
if !self.respond_to?(method_name)
|
40
42
|
metaclass.send(:define_method, method_name) do |*args|
|
41
43
|
if args.length > 1
|
@@ -16,3 +16,6 @@ require 'google/api_client/auth/pkcs12'
|
|
16
16
|
require 'google/api_client/auth/jwt_asserter'
|
17
17
|
require 'google/api_client/auth/key_utils'
|
18
18
|
require 'google/api_client/auth/compute_service_account'
|
19
|
+
require 'google/api_client/auth/storage'
|
20
|
+
require 'google/api_client/auth/storages/redis_store'
|
21
|
+
require 'google/api_client/auth/storages/file_store'
|
@@ -13,19 +13,14 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
MINOR = 7
|
25
|
-
TINY = 1
|
26
|
-
PATCH = nil
|
27
|
-
STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
|
28
|
-
end
|
16
|
+
module Google
|
17
|
+
class APIClient
|
18
|
+
module VERSION
|
19
|
+
MAJOR = 0
|
20
|
+
MINOR = 8
|
21
|
+
TINY = 0
|
22
|
+
PATCH = nil
|
23
|
+
STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
|
29
24
|
end
|
30
25
|
end
|
31
26
|
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'google/api_client'
|
4
|
+
require 'google/api_client/version'
|
5
|
+
|
6
|
+
describe Google::APIClient::Storage do
|
7
|
+
let(:client) { Google::APIClient.new(:application_name => 'API Client Tests') }
|
8
|
+
let(:root_path) { File.expand_path(File.join(__FILE__, '..', '..', '..')) }
|
9
|
+
let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) }
|
10
|
+
|
11
|
+
let(:store) { double }
|
12
|
+
let(:client_stub) { double }
|
13
|
+
subject { Google::APIClient::Storage.new(store) }
|
14
|
+
|
15
|
+
describe 'authorize' do
|
16
|
+
it 'should authorize' do
|
17
|
+
expect(subject).to respond_to(:authorization)
|
18
|
+
expect(subject.store).to be == store
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'authorize' do
|
23
|
+
describe 'with credentials' do
|
24
|
+
|
25
|
+
it 'should initialize a new OAuth Client' do
|
26
|
+
expect(subject).to receive(:load_credentials).and_return({:first => 'a dummy'})
|
27
|
+
expect(client_stub).to receive(:issued_at=)
|
28
|
+
expect(client_stub).to receive(:expired?).and_return(false)
|
29
|
+
expect(Signet::OAuth2::Client).to receive(:new).and_return(client_stub)
|
30
|
+
expect(subject).not_to receive(:refresh_authorization)
|
31
|
+
subject.authorize
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should refresh authorization' do
|
35
|
+
expect(subject).to receive(:load_credentials).and_return({:first => 'a dummy'})
|
36
|
+
expect(client_stub).to receive(:issued_at=)
|
37
|
+
expect(client_stub).to receive(:expired?).and_return(true)
|
38
|
+
expect(Signet::OAuth2::Client).to receive(:new).and_return(client_stub)
|
39
|
+
expect(subject).to receive(:refresh_authorization)
|
40
|
+
auth = subject.authorize
|
41
|
+
expect(auth).to be == subject.authorization
|
42
|
+
expect(auth).not_to be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'without credentials' do
|
47
|
+
|
48
|
+
it 'should return nil' do
|
49
|
+
expect(subject.authorization).to be_nil
|
50
|
+
expect(subject).to receive(:load_credentials).and_return({})
|
51
|
+
expect(subject.authorize).to be_nil
|
52
|
+
expect(subject.authorization).to be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'write_credentials' do
|
58
|
+
it 'should call store to write credentials' do
|
59
|
+
authorization_stub = double
|
60
|
+
expect(authorization_stub).to receive(:refresh_token).and_return(true)
|
61
|
+
expect(subject).to receive(:credentials_hash)
|
62
|
+
expect(subject.store).to receive(:write_credentials)
|
63
|
+
subject.write_credentials(authorization_stub)
|
64
|
+
expect(subject.authorization).to be == authorization_stub
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not call store to write credentials' do
|
68
|
+
expect(subject).not_to receive(:credentials_hash)
|
69
|
+
expect(subject.store).not_to receive(:write_credentials)
|
70
|
+
expect {
|
71
|
+
subject.write_credentials()
|
72
|
+
}.not_to raise_error
|
73
|
+
end
|
74
|
+
it 'should not call store to write credentials' do
|
75
|
+
expect(subject).not_to receive(:credentials_hash)
|
76
|
+
expect(subject.store).not_to receive(:write_credentials)
|
77
|
+
expect {
|
78
|
+
subject.write_credentials('something')
|
79
|
+
}.not_to raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'refresh_authorization' do
|
85
|
+
it 'should call refresh and write credentials' do
|
86
|
+
expect(subject).to receive(:write_credentials)
|
87
|
+
authorization_stub = double
|
88
|
+
expect(subject).to receive(:authorization).and_return(authorization_stub)
|
89
|
+
expect(authorization_stub).to receive(:refresh!).and_return(true)
|
90
|
+
subject.refresh_authorization
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'load_credentials' do
|
95
|
+
it 'should call store to load credentials' do
|
96
|
+
expect(subject.store).to receive(:load_credentials)
|
97
|
+
subject.send(:load_credentials)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'credentials_hash' do
|
102
|
+
it 'should return an hash' do
|
103
|
+
authorization_stub = double
|
104
|
+
expect(authorization_stub).to receive(:access_token)
|
105
|
+
expect(authorization_stub).to receive(:client_id)
|
106
|
+
expect(authorization_stub).to receive(:client_secret)
|
107
|
+
expect(authorization_stub).to receive(:expires_in)
|
108
|
+
expect(authorization_stub).to receive(:refresh_token)
|
109
|
+
expect(authorization_stub).to receive(:issued_at).and_return('100')
|
110
|
+
allow(subject).to receive(:authorization).and_return(authorization_stub)
|
111
|
+
credentials = subject.send(:credentials_hash)
|
112
|
+
expect(credentials).to include(:access_token)
|
113
|
+
expect(credentials).to include(:authorization_uri)
|
114
|
+
expect(credentials).to include(:client_id)
|
115
|
+
expect(credentials).to include(:client_secret)
|
116
|
+
expect(credentials).to include(:expires_in)
|
117
|
+
expect(credentials).to include(:refresh_token)
|
118
|
+
expect(credentials).to include(:token_credential_uri)
|
119
|
+
expect(credentials).to include(:issued_at)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'google/api_client'
|
4
|
+
require 'google/api_client/version'
|
5
|
+
|
6
|
+
describe Google::APIClient::FileStore do
|
7
|
+
let(:root_path) { File.expand_path(File.join(__FILE__, '..','..','..', '..','..')) }
|
8
|
+
let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) }
|
9
|
+
|
10
|
+
let(:credentials_hash) {{
|
11
|
+
"access_token"=>"my_access_token",
|
12
|
+
"authorization_uri"=>"https://accounts.google.com/o/oauth2/auth",
|
13
|
+
"client_id"=>"123456_test_client_id@.apps.googleusercontent.com",
|
14
|
+
"client_secret"=>"123456_client_secret",
|
15
|
+
"expires_in"=>3600,
|
16
|
+
"refresh_token"=>"my_refresh_token",
|
17
|
+
"token_credential_uri"=>"https://accounts.google.com/o/oauth2/token",
|
18
|
+
"issued_at"=>1384440275
|
19
|
+
}}
|
20
|
+
|
21
|
+
subject{Google::APIClient::FileStore.new('a file path')}
|
22
|
+
|
23
|
+
it 'should have a path' do
|
24
|
+
expect(subject.path).to be == 'a file path'
|
25
|
+
subject.path = 'an other file path'
|
26
|
+
expect(subject.path).to be == 'an other file path'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should load credentials' do
|
30
|
+
subject.path = json_file
|
31
|
+
credentials = subject.load_credentials
|
32
|
+
expect(credentials).to include('access_token', 'authorization_uri', 'refresh_token')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should write credentials' do
|
36
|
+
io_stub = StringIO.new
|
37
|
+
expect(subject).to receive(:open).and_return(io_stub)
|
38
|
+
subject.write_credentials(credentials_hash)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'google/api_client'
|
4
|
+
require 'google/api_client/version'
|
5
|
+
|
6
|
+
|
7
|
+
describe Google::APIClient::RedisStore do
|
8
|
+
let(:root_path) { File.expand_path(File.join(__FILE__, '..', '..', '..', '..', '..')) }
|
9
|
+
let(:json_file) { File.expand_path(File.join(root_path, 'fixtures', 'files', 'auth_stored_credentials.json')) }
|
10
|
+
let(:redis) {double}
|
11
|
+
|
12
|
+
let(:credentials_hash) { {
|
13
|
+
"access_token" => "my_access_token",
|
14
|
+
"authorization_uri" => "https://accounts.google.com/o/oauth2/auth",
|
15
|
+
"client_id" => "123456_test_client_id@.apps.googleusercontent.com",
|
16
|
+
"client_secret" => "123456_client_secret",
|
17
|
+
"expires_in" => 3600,
|
18
|
+
"refresh_token" => "my_refresh_token",
|
19
|
+
"token_credential_uri" => "https://accounts.google.com/o/oauth2/token",
|
20
|
+
"issued_at" => 1384440275
|
21
|
+
} }
|
22
|
+
|
23
|
+
subject { Google::APIClient::RedisStore.new('a redis instance') }
|
24
|
+
|
25
|
+
it 'should have a redis instance' do
|
26
|
+
expect(subject.redis).to be == 'a redis instance'
|
27
|
+
subject.redis = 'an other redis instance'
|
28
|
+
expect(subject.redis).to be == 'an other redis instance'
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'load_credentials' do
|
32
|
+
|
33
|
+
it 'should load credentials' do
|
34
|
+
subject.redis= redis
|
35
|
+
expect(redis).to receive(:get).and_return(credentials_hash.to_json)
|
36
|
+
expect(subject.load_credentials).to be == credentials_hash
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should return nil' do
|
40
|
+
subject.redis= redis
|
41
|
+
expect(redis).to receive(:get).and_return(nil)
|
42
|
+
expect(subject.load_credentials).to be_nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'redis_credentials_key' do
|
47
|
+
context 'without given key' do
|
48
|
+
it 'should return default key' do
|
49
|
+
expect(subject.redis_credentials_key).to be == "google_api_credentials"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
context 'with given key' do
|
53
|
+
let(:redis_store) { Google::APIClient::RedisStore.new('a redis instance', 'another_google_api_credentials') }
|
54
|
+
it 'should use given key' do
|
55
|
+
expect(redis_store.redis_credentials_key).to be == "another_google_api_credentials"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'write credentials' do
|
62
|
+
|
63
|
+
it 'should write credentials' do
|
64
|
+
subject.redis= redis
|
65
|
+
expect(redis).to receive(:set).and_return('ok')
|
66
|
+
expect(subject.write_credentials(credentials_hash)).to be_truthy
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -14,9 +14,8 @@
|
|
14
14
|
|
15
15
|
require 'spec_helper'
|
16
16
|
require 'google/api_client'
|
17
|
-
require 'google/api_client/version'
|
18
17
|
|
19
|
-
describe Google::APIClient::BatchRequest do
|
18
|
+
RSpec.describe Google::APIClient::BatchRequest do
|
20
19
|
CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
|
21
20
|
|
22
21
|
after do
|
@@ -28,9 +27,9 @@ describe Google::APIClient::BatchRequest do
|
|
28
27
|
it 'should raise an error if making an empty batch request' do
|
29
28
|
batch = Google::APIClient::BatchRequest.new
|
30
29
|
|
31
|
-
(lambda do
|
30
|
+
expect(lambda do
|
32
31
|
CLIENT.execute(batch)
|
33
|
-
end).
|
32
|
+
end).to raise_error(Google::APIClient::BatchError)
|
34
33
|
end
|
35
34
|
|
36
35
|
it 'should allow query parameters in batch requests' do
|
@@ -39,7 +38,7 @@ describe Google::APIClient::BatchRequest do
|
|
39
38
|
'a' => '12345'
|
40
39
|
})
|
41
40
|
method, uri, headers, body = batch.to_http_request
|
42
|
-
body.read.
|
41
|
+
expect(body.read).to include("/?a=12345")
|
43
42
|
end
|
44
43
|
|
45
44
|
describe 'with the discovery API' do
|
@@ -73,8 +72,8 @@ describe Google::APIClient::BatchRequest do
|
|
73
72
|
expected_ids = ids.clone
|
74
73
|
batch = Google::APIClient::BatchRequest.new do |result|
|
75
74
|
block_called += 1
|
76
|
-
result.status.
|
77
|
-
expected_ids.
|
75
|
+
expect(result.status).to eq(200)
|
76
|
+
expect(expected_ids).to include(result.response.call_id)
|
78
77
|
expected_ids.delete(result.response.call_id)
|
79
78
|
end
|
80
79
|
|
@@ -82,7 +81,7 @@ describe Google::APIClient::BatchRequest do
|
|
82
81
|
batch.add(@call2, ids[1])
|
83
82
|
|
84
83
|
CLIENT.execute(batch)
|
85
|
-
block_called.
|
84
|
+
expect(block_called).to eq(2)
|
86
85
|
end
|
87
86
|
|
88
87
|
it 'should execute both when using individual callbacks' do
|
@@ -91,25 +90,25 @@ describe Google::APIClient::BatchRequest do
|
|
91
90
|
call1_returned, call2_returned = false, false
|
92
91
|
batch.add(@call1) do |result|
|
93
92
|
call1_returned = true
|
94
|
-
result.status.
|
93
|
+
expect(result.status).to eq(200)
|
95
94
|
end
|
96
95
|
batch.add(@call2) do |result|
|
97
96
|
call2_returned = true
|
98
|
-
result.status.
|
97
|
+
expect(result.status).to eq(200)
|
99
98
|
end
|
100
99
|
|
101
100
|
CLIENT.execute(batch)
|
102
|
-
call1_returned.
|
103
|
-
call2_returned.
|
101
|
+
expect(call1_returned).to be_truthy
|
102
|
+
expect(call2_returned).to be_truthy
|
104
103
|
end
|
105
104
|
|
106
105
|
it 'should raise an error if using the same call ID more than once' do
|
107
106
|
batch = Google::APIClient::BatchRequest.new
|
108
107
|
|
109
|
-
(lambda do
|
108
|
+
expect(lambda do
|
110
109
|
batch.add(@call1, 'my_id')
|
111
110
|
batch.add(@call2, 'my_id')
|
112
|
-
end).
|
111
|
+
end).to raise_error(Google::APIClient::BatchError)
|
113
112
|
end
|
114
113
|
end
|
115
114
|
|
@@ -138,13 +137,13 @@ describe Google::APIClient::BatchRequest do
|
|
138
137
|
expected_ids = ids.clone
|
139
138
|
batch = Google::APIClient::BatchRequest.new do |result|
|
140
139
|
block_called += 1
|
141
|
-
expected_ids.
|
140
|
+
expect(expected_ids).to include(result.response.call_id)
|
142
141
|
expected_ids.delete(result.response.call_id)
|
143
142
|
if result.response.call_id == ids[0]
|
144
|
-
result.status.
|
143
|
+
expect(result.status).to eq(200)
|
145
144
|
else
|
146
|
-
result.status.
|
147
|
-
result.status.
|
145
|
+
expect(result.status).to be >= 400
|
146
|
+
expect(result.status).to be < 500
|
148
147
|
end
|
149
148
|
end
|
150
149
|
|
@@ -152,7 +151,7 @@ describe Google::APIClient::BatchRequest do
|
|
152
151
|
batch.add(@call2, ids[1])
|
153
152
|
|
154
153
|
CLIENT.execute(batch)
|
155
|
-
block_called.
|
154
|
+
expect(block_called).to eq(2)
|
156
155
|
end
|
157
156
|
|
158
157
|
it 'should execute both when using individual callbacks' do
|
@@ -161,17 +160,17 @@ describe Google::APIClient::BatchRequest do
|
|
161
160
|
call1_returned, call2_returned = false, false
|
162
161
|
batch.add(@call1) do |result|
|
163
162
|
call1_returned = true
|
164
|
-
result.status.
|
163
|
+
expect(result.status).to eq(200)
|
165
164
|
end
|
166
165
|
batch.add(@call2) do |result|
|
167
166
|
call2_returned = true
|
168
|
-
result.status.
|
169
|
-
result.status.
|
167
|
+
expect(result.status).to be >= 400
|
168
|
+
expect(result.status).to be < 500
|
170
169
|
end
|
171
170
|
|
172
171
|
CLIENT.execute(batch)
|
173
|
-
call1_returned.
|
174
|
-
call2_returned.
|
172
|
+
expect(call1_returned).to be_truthy
|
173
|
+
expect(call2_returned).to be_truthy
|
175
174
|
end
|
176
175
|
end
|
177
176
|
end
|
@@ -236,12 +235,12 @@ describe Google::APIClient::BatchRequest do
|
|
236
235
|
batch.add(@call1, '1').add(@call2, '2')
|
237
236
|
request = batch.to_env(CLIENT.connection)
|
238
237
|
boundary = Google::APIClient::BatchRequest::BATCH_BOUNDARY
|
239
|
-
request[:method].to_s.downcase.
|
240
|
-
request[:url].to_s.
|
241
|
-
request[:request_headers]['Content-Type'].
|
242
|
-
|
243
|
-
|
244
|
-
|
238
|
+
expect(request[:method].to_s.downcase).to eq('post')
|
239
|
+
expect(request[:url].to_s).to eq('https://www.googleapis.com/batch')
|
240
|
+
expect(request[:request_headers]['Content-Type']).to eq("multipart/mixed;boundary=#{boundary}")
|
241
|
+
body = request[:body].read
|
242
|
+
expect(body).to include(@call1[:body])
|
243
|
+
expect(body).to include(@call2[:body])
|
245
244
|
end
|
246
245
|
end
|
247
246
|
|