Sha256: 45456c28f5026604a1bfc622408969b914a256be6d3b0abf0daec534935302da

Contents?: true

Size: 869 Bytes

Versions: 1

Compression:

Stored size: 869 Bytes

Contents

# frozen_string_literal: true

require 'faraday'
require '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 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.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)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codat-0.1.6.2 lib/codat/client.rb