Class: Finlight::ApiClient
- Inherits:
-
Object
- Object
- Finlight::ApiClient
- Defined in:
- lib/finlight/api_client.rb
Overview
Performs authenticated REST requests with retry and exponential backoff (500ms * 2^(attempt-1)), mirroring the sibling clients: retries on 429 and transient 5xx.
Constant Summary collapse
- RETRYABLE_STATUSES =
[429, 500, 502, 503, 504].freeze
- BASE_RETRY_DELAY =
0.5
Instance Method Summary collapse
-
#get(path, query = {}) ⇒ Object
The decoded JSON response.
-
#initialize(config, logger: Logging.default) ⇒ ApiClient
constructor
A new instance of ApiClient.
-
#post(path, body) ⇒ Object
The decoded JSON response.
Constructor Details
Instance Method Details
#get(path, query = {}) ⇒ Object
Returns the decoded JSON response.
21 22 23 24 25 |
# File 'lib/finlight/api_client.rb', line 21 def get(path, query = {}) uri = URI.parse(@config.base_url + path) uri.query = URI.encode_www_form(query) unless query.empty? perform(uri, Net::HTTP::Get.new(uri)) end |
#post(path, body) ⇒ Object
Returns the decoded JSON response.
28 29 30 31 32 33 34 |
# File 'lib/finlight/api_client.rb', line 28 def post(path, body) uri = URI.parse(@config.base_url + path) request = Net::HTTP::Post.new(uri) request["Content-Type"] = "application/json" request.body = JSON.generate(body) perform(uri, request) end |