Class: DefaultHttpClient
- Inherits:
-
HttpClient
- Object
- HttpClient
- DefaultHttpClient
- Defined in:
- lib/default_http_client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#session ⇒ Object
Returns the value of attribute session.
Class Method Summary collapse
- .create(config) ⇒ Object
- .default_response(status_code, status_message, content_type, content) ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
-
#get(url, query, headers) ⇒ Object
def context_data end.
-
#initialize(config) ⇒ DefaultHttpClient
constructor
A new instance of DefaultHttpClient.
- #post(url, query, headers, body) ⇒ Object
- #put(url, query, headers, body) ⇒ Object
Methods inherited from HttpClient
Constructor Details
#initialize(config) ⇒ DefaultHttpClient
Returns a new instance of DefaultHttpClient.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/default_http_client.rb', line 14 def initialize(config) @config = config @session = Faraday.new("") do |f| f.request :retry, max: config.max_retries, interval: config.retry_interval, interval_randomness: 0.5, backoff_factor: 2 f..timeout = config.connect_timeout f..open_timeout = config.connection_request_timeout end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/default_http_client.rb', line 8 def config @config end |
#session ⇒ Object
Returns the value of attribute session.
8 9 10 |
# File 'lib/default_http_client.rb', line 8 def session @session end |
Class Method Details
.create(config) ⇒ Object
10 11 12 |
# File 'lib/default_http_client.rb', line 10 def self.create(config) DefaultHttpClient.new(config) end |
.default_response(status_code, status_message, content_type, content) ⇒ Object
46 47 48 49 50 |
# File 'lib/default_http_client.rb', line 46 def self.default_response(status_code, , content_type, content) env = Faraday::Env.from(status: status_code, body: content || , response_headers: { "Content-Type" => content_type }) Faraday::Response.new(env) end |
Instance Method Details
#close ⇒ Object
42 43 44 |
# File 'lib/default_http_client.rb', line 42 def close @session.close end |
#get(url, query, headers) ⇒ Object
def context_data end
30 31 32 |
# File 'lib/default_http_client.rb', line 30 def get(url, query, headers) @session.get(url, query, headers) end |
#post(url, query, headers, body) ⇒ Object
38 39 40 |
# File 'lib/default_http_client.rb', line 38 def post(url, query, headers, body) @session.post(add_tracking(url, query), body, headers) end |
#put(url, query, headers, body) ⇒ Object
34 35 36 |
# File 'lib/default_http_client.rb', line 34 def put(url, query, headers, body) @session.put(add_tracking(url, query), body, headers) end |