Class: Loqate::Client
- Inherits:
-
Object
- Object
- Loqate::Client
- Defined in:
- lib/loqate/client.rb
Overview
Responsible for the HTTP interactions. The only entity aware of HTTP concerns such as status codes and headers.
Instance Method Summary collapse
-
#get(endpoint, params = {}) ⇒ APIResult
Performs a GET request to Loqate’s API.
-
#initialize(configuration) ⇒ Client
constructor
Instantiates a new client.
Constructor Details
#initialize(configuration) ⇒ Client
Instantiates a new client
16 17 18 |
# File 'lib/loqate/client.rb', line 16 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#get(endpoint, params = {}) ⇒ APIResult
Performs a GET request to Loqate’s API. Every request returns the status code 200.
35 36 37 38 39 40 41 42 43 |
# File 'lib/loqate/client.rb', line 35 def get(endpoint, params = {}) authenticated_params = authenticate_params(params) formatted_params = format_params(authenticated_params) response = HTTP.headers(headers).get(configuration.host + endpoint, params: formatted_params) body = JSON.parse(response.body) APIResult.new(body.fetch('Items')) end |