Skip to content

Commit 8685fc1

Browse files
committed
adds support for proxy_options when calling Client#_
1 parent 4c9405c commit 8685fc1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/ruby_http_client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def ratelimit
8383

8484
# A simple REST client.
8585
class Client
86-
attr_reader :host, :request_headers, :url_path, :request, :http
86+
attr_reader :host, :request_headers, :url_path, :request, :http, :proxy_options
8787
# * *Args* :
8888
# - +host+ -> Base URL for the api. (e.g. https://api.sendgrid.com)
8989
# - +request_headers+ -> A hash of the headers you want applied on
@@ -275,7 +275,8 @@ def _(name = nil)
275275
url_path = name ? @url_path + [name] : @url_path
276276
Client.new(host: @host, request_headers: @request_headers,
277277
version: @version, url_path: url_path,
278-
http_options: @http_options)
278+
http_options: @http_options,
279+
proxy_options: @proxy_options)
279280
end
280281

281282
# Dynamically add segments to the url, then call a method.

test/test_ruby_http_client.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ def setup
6464
@host = 'http://localhost:4010'
6565
@version = 'v3'
6666
@http_options = { open_timeout: 60, read_timeout: 60 }
67+
@proxy_options = { host: '127.0.0.1', port: 8080, user: 'anonymous', pass: 'secret'}
6768
@client = MockRequest.new(host: @host,
6869
request_headers: @headers,
6970
version: @version)
7071
@client_with_options = MockRequest.new(host: @host,
7172
request_headers: @headers,
7273
version: @version,
73-
http_options: @http_options)
74+
http_options: @http_options,
75+
proxy_options: @proxy_options)
7476
end
7577

7678
def test_init
@@ -266,6 +268,14 @@ def test__
266268
assert_equal(['test'], url1.url_path)
267269
end
268270

271+
def test___with_client_with_options
272+
url1 = @client_with_options._('test')
273+
assert_equal(['test'], url1.url_path)
274+
assert_equal(@host, url1.host)
275+
assert_equal(@headers, url1.request_headers)
276+
assert_equal(@proxy_options, url1.proxy_options)
277+
end
278+
269279
def test_ratelimit_core
270280
expiry = Time.now.to_i + 1
271281
rl = SendGrid::Response::Ratelimit.new(500, 100, expiry)

0 commit comments

Comments
 (0)