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.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/default_http_client.rb', line 15 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.
9 10 11 |
# File 'lib/default_http_client.rb', line 9 def config @config end |
#session ⇒ Object
Returns the value of attribute session.
9 10 11 |
# File 'lib/default_http_client.rb', line 9 def session @session end |
Class Method Details
.create(config) ⇒ Object
11 12 13 |
# File 'lib/default_http_client.rb', line 11 def self.create(config) DefaultHttpClient.new(config) end |
.default_response(status_code, status_message, content_type, content) ⇒ Object
47 48 49 50 51 |
# File 'lib/default_http_client.rb', line 47 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
43 44 45 |
# File 'lib/default_http_client.rb', line 43 def close @session.close end |
#get(url, query, headers) ⇒ Object
def context_data end
31 32 33 |
# File 'lib/default_http_client.rb', line 31 def get(url, query, headers) @session.get(url, query, headers) end |
#post(url, query, headers, body) ⇒ Object
39 40 41 |
# File 'lib/default_http_client.rb', line 39 def post(url, query, headers, body) @session.post(add_tracking(url, query), body, headers) end |
#put(url, query, headers, body) ⇒ Object
35 36 37 |
# File 'lib/default_http_client.rb', line 35 def put(url, query, headers, body) @session.put(add_tracking(url, query), body, headers) end |