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