require 'poms/api/drivers/net_http' require 'poms/api/request' require 'poms/api/auth' require 'poms/errors' module Poms module Api # The Client module isolates all HTTP interactions, regardless of the driver # module to implement the actual operations. Use the Client module to build # signed requests and execute them. # # @see Poms::Api::Drivers::NetHttp module Client extend Drivers::NetHttp module_function def get(uri, credentials, headers = {}) handle_response( execute( Auth.sign( prepare_get(uri, headers), credentials ) ) ) end def post(uri, body, credentials, headers = {}) handle_response( execute( Auth.sign( prepare_post(uri, body, headers), credentials ) ) ) end def handle_response(response) case response.code when 400..499 then raise Errors::HttpMissingError, response.code when 500..599 then raise Errors::HttpServerError, response.code else response end end def prepare_get(uri, headers = {}) Request.get(uri, nil, headers) end def prepare_post(uri, body, headers = {}) Request.post(uri, body, headers) end end end end