lib/iwoca/connection.rb in iwoca-1.0.1 vs lib/iwoca/connection.rb in iwoca-1.1.0

- old
+ new

@@ -6,12 +6,17 @@ require 'iwoca/response' module Iwoca class Connection - BASE_PATH = '/api/lending/v1' + BASE_PATH = '/api/lending/v2.1' + BASE_NOTIFICATIONS_PATH = '/api/notifications/v1' + def initialize(type = 'base') + @base_path = type == 'notifications' ? BASE_NOTIFICATIONS_PATH : BASE_PATH + end + def get(path, params = {}) log "GET #{path} with #{params}" http_response = adapter.get(PathSanitizer.sanitize(path), params) @@ -47,17 +52,17 @@ puts Rainbow("[Iwoca] #{text}").magenta.bright end def base_url - Addressable::URI.join(Iwoca.configuration.api_domain, BASE_PATH).to_s + Addressable::URI.join(Iwoca.configuration.api_domain, @base_path).to_s end def adapter token = Iwoca.configuration.api_key Faraday.new(url: base_url) do |conn| - conn.headers['Authorization'] = "Token #{token}" unless token.to_s.empty? + conn.headers['Authorization'] = "Bearer #{token}" unless token.to_s.empty? conn.headers['Content-Type'] = 'application/json' conn.headers['User-Agent'] = "ruby-iwoca-#{VERSION}" conn.response :json, parser_options: { symbolize_names: true } conn.response :logger if Iwoca.configuration.debug? conn.adapter Faraday.default_adapter