Skip to content

Commit 91ae01a

Browse files
committed
Merge prioridata-master
2 parents 9b0e8d3 + 74134bf commit 91ae01a

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

lib/google/api_client.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class APIClient
7575
# @option options [String] :ca_file
7676
# Optional set of root certificates to use when validating SSL connections.
7777
# By default, a bundled set of trusted roots will be used.
78+
# @options options[Hash] :faraday_options
79+
# Pass through of options to set on the Faraday connection
7880
def initialize(options={})
7981
logger.debug { "#{self.class} - Initializing client with options #{options}" }
8082

@@ -123,6 +125,11 @@ def initialize(options={})
123125
faraday.ssl.verify = true
124126
faraday.proxy proxy
125127
faraday.adapter Faraday.default_adapter
128+
if options[:faraday_option].is_a?(Hash)
129+
options[:faraday_option].each_pair do |option, value|
130+
faraday.options.send("#{option}=", value)
131+
end
132+
end
126133
end
127134
return self
128135
end

spec/google/api_client_spec.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
shared_examples_for 'configurable user agent' do
2222
include ConnectionHelpers
23-
23+
2424
it 'should allow the user agent to be modified' do
2525
client.user_agent = 'Custom User Agent/1.2.3'
2626
expect(client.user_agent).to eq('Custom User Agent/1.2.3')
@@ -59,6 +59,11 @@
5959

6060
let(:client) { Google::APIClient.new(:application_name => 'API Client Tests') }
6161

62+
it "should pass the faraday options provided on initialization to FaraDay configuration block" do
63+
client = Google::APIClient.new(faraday_option: {timeout: 999})
64+
expect(client.connection.options.timeout).to be == 999
65+
end
66+
6267
it 'should make its version number available' do
6368
expect(Google::APIClient::VERSION::STRING).to be_instance_of(String)
6469
end
@@ -73,7 +78,7 @@
7378
end
7479
it_should_behave_like 'configurable user agent'
7580
end
76-
81+
7782
describe 'configured for OAuth 1' do
7883
before do
7984
client.authorization = :oauth_1
@@ -107,7 +112,7 @@
107112
# TODO
108113
it_should_behave_like 'configurable user agent'
109114
end
110-
115+
111116
describe 'when executing requests' do
112117
before do
113118
@prediction = client.discovered_api('prediction', 'v1.2')
@@ -123,10 +128,10 @@
123128
after do
124129
@connection.verify
125130
end
126-
131+
127132
it 'should use default authorization' do
128133
client.authorization.access_token = "12345"
129-
client.execute(
134+
client.execute(
130135
:api_method => @prediction.training.insert,
131136
:parameters => {'data' => '12345'},
132137
:connection => @connection
@@ -136,14 +141,14 @@
136141
it 'should use request scoped authorization when provided' do
137142
client.authorization.access_token = "abcdef"
138143
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')
139-
client.execute(
144+
client.execute(
140145
:api_method => @prediction.training.insert,
141146
:parameters => {'data' => '12345'},
142147
:authorization => new_auth,
143148
:connection => @connection
144149
)
145150
end
146-
151+
147152
it 'should accept options with batch/request style execute' do
148153
client.authorization.access_token = "abcdef"
149154
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')
@@ -157,17 +162,17 @@
157162
:connection => @connection
158163
)
159164
end
160-
161-
165+
166+
162167
it 'should accept options in array style execute' do
163168
client.authorization.access_token = "abcdef"
164169
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')
165-
client.execute(
170+
client.execute(
166171
@prediction.training.insert, {'data' => '12345'}, '', {},
167-
{ :authorization => new_auth, :connection => @connection }
172+
{ :authorization => new_auth, :connection => @connection }
168173
)
169174
end
170-
end
175+
end
171176

172177
describe 'when retries enabled' do
173178
before do
@@ -177,7 +182,7 @@
177182
after do
178183
@connection.verify
179184
end
180-
185+
181186
it 'should follow redirects' do
182187
client.authorization = nil
183188
@connection = stub_connection do |stub|
@@ -284,5 +289,5 @@
284289
expect(count).to eq(3)
285290
end
286291

287-
end
292+
end
288293
end

0 commit comments

Comments
 (0)