Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds support for proxy_options when calling Client#_ #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/ruby_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def ratelimit

# A simple REST client.
class Client
attr_reader :host, :request_headers, :url_path, :request, :http
attr_reader :host, :request_headers, :url_path, :request, :http, :proxy_options
# * *Args* :
# - +host+ -> Base URL for the api. (e.g. https://api.sendgrid.com)
# - +request_headers+ -> A hash of the headers you want applied on
Expand Down Expand Up @@ -275,7 +275,8 @@ def _(name = nil)
url_path = name ? @url_path + [name] : @url_path
Client.new(host: @host, request_headers: @request_headers,
version: @version, url_path: url_path,
http_options: @http_options)
http_options: @http_options,
proxy_options: @proxy_options)
end

# Dynamically add segments to the url, then call a method.
Expand Down
12 changes: 11 additions & 1 deletion test/test_ruby_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ def setup
@host = 'http://localhost:4010'
@version = 'v3'
@http_options = { open_timeout: 60, read_timeout: 60 }
@proxy_options = { host: '127.0.0.1', port: 8080, user: 'anonymous', pass: 'secret'}
@client = MockRequest.new(host: @host,
request_headers: @headers,
version: @version)
@client_with_options = MockRequest.new(host: @host,
request_headers: @headers,
version: @version,
http_options: @http_options)
http_options: @http_options,
proxy_options: @proxy_options)
end

def test_init
Expand Down Expand Up @@ -266,6 +268,14 @@ def test__
assert_equal(['test'], url1.url_path)
end

def test___with_client_with_options
url1 = @client_with_options._('test')
assert_equal(['test'], url1.url_path)
assert_equal(@host, url1.host)
assert_equal(@headers, url1.request_headers)
assert_equal(@proxy_options, url1.proxy_options)
end

def test_ratelimit_core
expiry = Time.now.to_i + 1
rl = SendGrid::Response::Ratelimit.new(500, 100, expiry)
Expand Down
Loading