Class: Preverus::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/preverus/http_client.rb

Constant Summary collapse

RETRYABLE_STATUSES =
[408, 409, 425, 429, 500, 502, 503, 504].freeze

Instance Method Summary collapse

Constructor Details

#initialize(server_key:, endpoint:, timeout:, retries:, retry_delay:, max_retry_delay:) ⇒ HttpClient

Returns a new instance of HttpClient.



11
12
13
14
15
16
17
18
# File 'lib/preverus/http_client.rb', line 11

def initialize(server_key:, endpoint:, timeout:, retries:, retry_delay:, max_retry_delay:)
  @server_key = server_key.to_s.strip
  @endpoint = endpoint.to_s.sub(%r{/+$}, "")
  @timeout = timeout
  @retries = [retries.to_i, 0].max
  @retry_delay = retry_delay
  @max_retry_delay = max_retry_delay
end

Instance Method Details

#get(path, params = {}, headers = {}) ⇒ Object



20
21
22
23
# File 'lib/preverus/http_client.rb', line 20

def get(path, params = {}, headers = {})
  query = URI.encode_www_form(params.reject { |_key, value| value.nil? || value == "" })
  request("GET", query.empty? ? path : "#{path}?#{query}", nil, headers)
end

#post(path, body, headers = {}) ⇒ Object



25
26
27
# File 'lib/preverus/http_client.rb', line 25

def post(path, body, headers = {})
  request("POST", path, body, headers)
end