Class: Drip::Client::HTTPClient
- Inherits:
-
Object
- Object
- Drip::Client::HTTPClient
- Defined in:
- lib/drip/client/http_client.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
- #make_request(drip_request, redirected_url: nil, step: 0) ⇒ Object
Constructor Details
#initialize(config) ⇒ HTTPClient
Returns a new instance of HTTPClient.
9 10 11 |
# File 'lib/drip/client/http_client.rb', line 9 def initialize(config) @config = config end |
Instance Method Details
#make_request(drip_request, redirected_url: nil, step: 0) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/drip/client/http_client.rb', line 13 def make_request(drip_request, redirected_url: nil, step: 0) raise TooManyRedirectsError, 'too many HTTP redirects' if step >= REDIRECT_LIMIT uri = redirected_url || drip_request.url.tap do |orig_url| next if drip_request.http_verb != :get orig_url.query = URI.encode_www_form(drip_request.) end response = Net::HTTP.start(uri.host, uri.port, (uri.scheme)) do |http| request = drip_request.verb_klass.new uri request.body = drip_request.body add_standard_headers(request) request['Content-Type'] = drip_request.content_type http.request request end return make_request(drip_request, redirected_url: URI(response["Location"]), step: step + 1) if response.is_a?(Net::HTTPRedirection) response end |