Class: Starling::ApiService
- Inherits:
-
Object
- Object
- Starling::ApiService
- Defined in:
- lib/starling/api_service.rb
Overview
The API client under the hood, used by services publicly exposed by Client to dispatch requests to the Starling Bank API
Constant Summary collapse
- DEFAULT_ADAPTER =
The default adapter which will be used by Faraday to make requests. This can be customised by passing a :http_adapter when instantiating the ApiService.
:net_http
- BASE_PATH =
The path of the API version which will be prepended to request paths
'/api/v1'.freeze
Instance Method Summary collapse
-
#initialize(base_url, access_token:, http_adapter: [DEFAULT_ADAPTER], connection_options: {}, default_headers: {}) ⇒ Starling::ApiService
constructor
Instantiates a ApiService for dispatching requests to the Starling Bank API.
-
#make_request(method, path, params: {}, headers: {}) ⇒ Faraday::Response
Makes an HTTP request to the Starling Bank API with the specified method and path.
Constructor Details
#initialize(base_url, access_token:, http_adapter: [DEFAULT_ADAPTER], connection_options: {}, default_headers: {}) ⇒ Starling::ApiService
Instantiates a Starling::ApiService for dispatching requests to the Starling Bank API
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/starling/api_service.rb', line 29 def initialize(base_url, access_token:, http_adapter: [DEFAULT_ADAPTER], connection_options: {}, default_headers: {}) @connection = Faraday.new(base_url, ) do |faraday| faraday.response(:raise_starling_errors) faraday.adapter(*http_adapter) end @headers = library_default_headers(access_token: access_token) .merge(default_headers) end |
Instance Method Details
#make_request(method, path, params: {}, headers: {}) ⇒ Faraday::Response
Makes an HTTP request to the Starling Bank API with the specified method and path
50 51 52 53 54 55 56 |
# File 'lib/starling/api_service.rb', line 50 def make_request(method, path, params: {}, headers: {}) headers = @headers.merge(headers) Request.new(@connection, method, build_path(path), params: params, headers: headers) .make_request end |