Skip to content

Commit 2f88bc5

Browse files
committed
allows to pass FaraDay options furthur to FaraDay configuration block upon client initialization
1 parent bfa5225 commit 2f88bc5

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

lib/google/api_client.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ def initialize(options={})
119119
faraday.ssl.ca_file = ca_file
120120
faraday.ssl.verify = true
121121
faraday.adapter Faraday.default_adapter
122+
if options[:faraday_option].is_a?(Hash)
123+
options[:faraday_option].each_pair do |option, value|
124+
faraday.options.send("#{option}=", value)
125+
end
126+
end
122127
end
123128
return self
124129
end

spec/google/api_client_spec.rb

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
shared_examples_for 'configurable user agent' do
2323
include ConnectionHelpers
24-
24+
2525
it 'should allow the user agent to be modified' do
2626
client.user_agent = 'Custom User Agent/1.2.3'
2727
client.user_agent.should == 'Custom User Agent/1.2.3'
@@ -60,6 +60,11 @@
6060

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

63+
it "should pass the faraday options provided on initialization to FaraDay configuration block" do
64+
client = Google::APIClient.new(faraday_option: {timeout: 999})
65+
client.connection.options.timeout.should == 999
66+
end
67+
6368
it 'should make its version number available' do
6469
Google::APIClient::VERSION::STRING.should be_instance_of(String)
6570
end
@@ -74,7 +79,7 @@
7479
end
7580
it_should_behave_like 'configurable user agent'
7681
end
77-
82+
7883
describe 'configured for OAuth 1' do
7984
before do
8085
client.authorization = :oauth_1
@@ -106,7 +111,7 @@
106111
# TODO
107112
it_should_behave_like 'configurable user agent'
108113
end
109-
114+
110115
describe 'when executing requests' do
111116
before do
112117
@prediction = client.discovered_api('prediction', 'v1.2')
@@ -122,10 +127,10 @@
122127
after do
123128
@connection.verify
124129
end
125-
130+
126131
it 'should use default authorization' do
127132
client.authorization.access_token = "12345"
128-
client.execute(
133+
client.execute(
129134
:api_method => @prediction.training.insert,
130135
:parameters => {'data' => '12345'},
131136
:connection => @connection
@@ -135,14 +140,14 @@
135140
it 'should use request scoped authorization when provided' do
136141
client.authorization.access_token = "abcdef"
137142
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')
138-
client.execute(
143+
client.execute(
139144
:api_method => @prediction.training.insert,
140145
:parameters => {'data' => '12345'},
141146
:authorization => new_auth,
142147
:connection => @connection
143148
)
144149
end
145-
150+
146151
it 'should accept options with batch/request style execute' do
147152
client.authorization.access_token = "abcdef"
148153
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')
@@ -156,17 +161,17 @@
156161
:connection => @connection
157162
)
158163
end
159-
160-
164+
165+
161166
it 'should accept options in array style execute' do
162167
client.authorization.access_token = "abcdef"
163168
new_auth = Signet::OAuth2::Client.new(:access_token => '12345')
164-
client.execute(
169+
client.execute(
165170
@prediction.training.insert, {'data' => '12345'}, '', {},
166-
{ :authorization => new_auth, :connection => @connection }
171+
{ :authorization => new_auth, :connection => @connection }
167172
)
168173
end
169-
end
174+
end
170175

171176
describe 'when retries enabled' do
172177
before do
@@ -176,7 +181,7 @@
176181
after do
177182
@connection.verify
178183
end
179-
184+
180185
it 'should follow redirects' do
181186
client.authorization = nil
182187
@connection = stub_connection do |stub|
@@ -188,7 +193,7 @@
188193
end
189194
end
190195

191-
client.execute(
196+
client.execute(
192197
:uri => 'https://www.gogole.com/foo',
193198
:connection => @connection
194199
)
@@ -207,7 +212,7 @@
207212
end
208213
end
209214

210-
client.execute(
215+
client.execute(
211216
:uri => 'https://www.gogole.com/foo',
212217
:connection => @connection
213218
)
@@ -224,7 +229,7 @@
224229
end
225230
end
226231

227-
client.execute(
232+
client.execute(
228233
:uri => 'https://www.gogole.com/foo',
229234
:connection => @connection
230235
)
@@ -240,7 +245,7 @@
240245
end
241246
end
242247

243-
client.execute(
248+
client.execute(
244249
:uri => 'https://www.gogole.com/foo',
245250
:connection => @connection,
246251
:authenticated => false
@@ -259,7 +264,7 @@
259264
end
260265
end
261266

262-
client.execute(
267+
client.execute(
263268
:uri => 'https://www.gogole.com/foo',
264269
:connection => @connection
265270
).status.should == 200
@@ -276,12 +281,12 @@
276281
end
277282
end
278283

279-
client.execute(
284+
client.execute(
280285
:uri => 'https://www.gogole.com/foo',
281286
:connection => @connection
282287
).status.should == 500
283288
count.should == 3
284289
end
285290

286-
end
291+
end
287292
end

0 commit comments

Comments
 (0)