Class: Starling::ApiService
- Inherits:
-
Object
- Object
- Starling::ApiService
- Defined in:
- lib/starling/api_service.rb
Constant Summary collapse
- DEFAULT_ADAPTER =
:net_http- BASE_PATH =
'/api/v1'.freeze
Instance Method Summary collapse
-
#initialize(base_url, options = {}) ⇒ ApiService
constructor
A new instance of ApiService.
- #make_request(method, path, options = {}) ⇒ Object
Constructor Details
#initialize(base_url, options = {}) ⇒ ApiService
Returns a new instance of ApiService.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/starling/api_service.rb', line 8 def initialize(base_url, = {}) @access_token = .fetch(:access_token) http_adapter = [:http_adapter] || [DEFAULT_ADAPTER] = [:connection_options] @connection = Faraday.new(base_url, ) do |faraday| faraday.response(:raise_starling_errors) faraday.adapter(*http_adapter) end user_provided_default_headers = .fetch(:default_headers, {}) @headers = default_headers.merge(user_provided_default_headers) end |
Instance Method Details
#make_request(method, path, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/starling/api_service.rb', line 23 def make_request(method, path, = {}) raise ArgumentError, 'options must be a hash' unless .is_a?(Hash) [:headers] ||= {} [:headers] = @headers.merge([:headers]) Request.new(@connection, method, build_path(path), ) .make_request end |