Class: Dawupxlrgo::FaradayClient
- Inherits:
-
HttpClient
- Object
- HttpClient
- Dawupxlrgo::FaradayClient
- Defined in:
- lib/dawupxlrgo/http/faraday_client.rb
Overview
An implementation of HttpClient.
Instance Method Summary collapse
-
#convert_response(response) ⇒ Object
Method overridden from HttpClient.
-
#execute_as_binary(http_request) ⇒ Object
Method overridden from HttpClient.
-
#execute_as_string(http_request) ⇒ Object
Method overridden from HttpClient.
-
#initialize(timeout: nil, cache: false, max_retries: nil, retry_interval: nil) ⇒ FaradayClient
constructor
The constructor.
Methods inherited from HttpClient
#delete, #get, #head, #patch, #post, #put
Constructor Details
#initialize(timeout: nil, cache: false, max_retries: nil, retry_interval: nil) ⇒ FaradayClient
The constructor.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dawupxlrgo/http/faraday_client.rb', line 12 def initialize(timeout: nil, cache: false, max_retries: nil, retry_interval: nil) @connection = Faraday.new do |faraday| faraday.use Faraday::HttpCache, serializer: Marshal if cache faraday.request :multipart faraday.request :url_encoded faraday.ssl[:ca_file] = Certifi.where faraday.adapter Faraday.default_adapter faraday.[:params_encoder] = Faraday::FlatParamsEncoder faraday.[:open_timeout] = timeout if timeout faraday.request :retry, max: max_retries, interval: if max_retries && retry_interval retry_interval end end end |
Instance Method Details
#convert_response(response) ⇒ Object
Method overridden from HttpClient.
58 59 60 |
# File 'lib/dawupxlrgo/http/faraday_client.rb', line 58 def convert_response(response) HttpResponse.new(response.status, response.headers, response.body) end |
#execute_as_binary(http_request) ⇒ Object
Method overridden from HttpClient.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dawupxlrgo/http/faraday_client.rb', line 44 def execute_as_binary(http_request) response = @connection.send( http_request.http_method.downcase, http_request.query_url ) do |request| request.headers = http_request.headers unless http_request.parameters.empty? request.body = http_request.parameters end end convert_response(response) end |
#execute_as_string(http_request) ⇒ Object
Method overridden from HttpClient.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dawupxlrgo/http/faraday_client.rb', line 30 def execute_as_string(http_request) response = @connection.send( http_request.http_method.downcase, http_request.query_url ) do |request| request.headers = http_request.headers unless http_request.parameters.empty? request.body = http_request.parameters end end convert_response(response) end |