Class: DefaultHttpClient

Inherits:
HttpClient show all
Defined in:
lib/default_http_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HttpClient

#response

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.options.timeout = config.connect_timeout
    f.options.open_timeout = config.connection_request_timeout
  end
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/default_http_client.rb', line 9

def config
  @config
end

#sessionObject

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, status_message, content_type, content)
  env = Faraday::Env.from(status: status_code, body: content || status_message,
                    response_headers: { "Content-Type" => content_type })
  Faraday::Response.new(env)
end

Instance Method Details

#closeObject



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