Client instance clobbers internal state
jacobat opened this issue · comments
Jacob Atzen commented
Issue Summary
Reusing the Sendgrid client causes a 404.
Steps to Reproduce
If you try to reuse a client with a path multiple times it fails on subsequent attempts:
mail = SendGrid::Mail.new
[ ... do some mail setup ...]
client = SendGrid::API.new(api_key: API_KEY, host: 'https://api.sendgrid.com').client.mail
client._('send').post(request_body: mail.to_json) # This succeeds
client._('send').post(request_body: mail.to_json) # This fails
if instead you move the clients #mail
method to be called twice things work:
mail = SendGrid::Mail.new
[ ... do some mail setup ...]
client = SendGrid::API.new(api_key: API_KEY, host: 'https://api.sendgrid.com').client
client.mail._('send').post(request_body: mail.to_json) # This succeeds
client.mail._('send').post(request_body: mail.to_json) # This succeeds
This is very unexpected behaviour, the code should not require you to call mail
over an over. Instead you should be able to reuse the same client instance over and over.
Technical details:
- ruby-http-client Version: 3.3.0
- Ruby Version: 2.5
Jacob Atzen commented
I believe the issue is caused by these lines: https://github.com/sendgrid/ruby-http-client/blob/master/lib/ruby_http_client.rb#L215-L216
I think replacing those two lines by will fix the issue:
url_path = name ? @url_path + [name] : @url_path