lib/codat/client.rb in codat-0.1.6.2 vs lib/codat/client.rb in codat-0.1.7
- old
+ new
@@ -1,37 +1,41 @@
# frozen_string_literal: true
require 'faraday'
-require 'multi_json'
+require 'faraday_middleware/multi_json'
require 'codat/faraday_codat_auth'
module Codat
class Client
BASE_URLS = {
production: 'https://api.codat.io/',
uat: 'https://api-uat.codat.io/'
}.freeze
+ def initialize
+ Faraday::Request.register_middleware codat_auth: -> { Codat::FaradayCodatAuth }
+ end
+
def get(path, params = {})
connection.get(path, params)
end
def post(path, params = {})
connection.post(path, MultiJson.dump(params))
end
def connection
@connection ||= Faraday.new(url: api_url) do |conn|
- conn.use Codat::FaradayCodatAuth, Codat.configuration.api_key
- conn.response :json, parser_options: { symbolize_names: true }
+ conn.request :codat_auth, Codat.configuration.api_key
+ conn.response :multi_json, symbolize_keys: true
# conn.response :logger # if Codat.configuration.debug?
conn.adapter Faraday.default_adapter
end
end
private
def api_url
- BASE_URLS.dig(Codat.configuration.environment.to_sym)
+ BASE_URLS[Codat.configuration.environment.to_sym]
end
end
end