Sha256: 87ff3b41e54fdaf28c7b7ac67fef37eec19e77a2055a591874bbe622c39257f2

Contents?: true

Size: 759 Bytes

Versions: 2

Compression:

Stored size: 759 Bytes

Contents

require "faraday"
require "faraday_middleware"

module Fulfillment
  class Client
    def connection
      @connection ||= Faraday.new(proxy: config.proxy) do |conn|
        conn.request :json
        conn.response :json
        conn.adapter Faraday.default_adapter
      end
    end

    def call(method, path, params={})
      raw_response = connection.public_send(method, path, params) do |req|
        req.options.timeout = params[:query]&.delete(:request_timeout) || 30
      end
      Response.new(raw_response)
    end

    [:get, :post, :put, :patch, :delete].each do |method|
      define_method(method) do |path, params={}|
        call(method, path, params)
      end
    end

    private

    def config
      Fulfillment.config
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fulfillment-api-1.1.9 lib/fulfillment/client.rb
fulfillment-api-1.1.7 lib/fulfillment/client.rb