require "uri" module Fulfillment class Request attr_reader :path, :params def initialize(path, params={}) @path = path @params = params end def call(method) response = client.public_send(method, uri, params) response.on_error(&:raise_errors) end [:get, :post, :put, :patch, :delete].each do |method| define_method(method) do call(method) end end def uri @uri ||= build_uri end private def build_uri URI.parse(endpoint).tap do |uri| uri.merge!(path) end end def endpoint return Fulfillment.config.endpoint if Fulfillment.config.endpoint =~ /^http/ "http://#{Fulfillment.config.endpoint}" end def client Fulfillment.client end end end