Sha256: dd08637e5ab695077c69cd24cf43f8bdce44bd8b37d65b38762b4cc5c7aa3fd8
Contents?: true
Size: 1.5 KB
Versions: 4
Compression:
Stored size: 1.5 KB
Contents
require 'spree-api-client/error' require 'multi_json' module Spree module API class Client module Request def request(method, path, options = {}) token = options.delete(:api_token) || api_token begin response = connection.send(method) do |request| request.headers['Accept'] = options.delete(:accept) || 'application/json' if token request.headers['X-Spree-Token'] = token end options.merge!(:locale => locale) case method when :get options[:per_page] = per_page unless options[:per_page] request.url(path, options) when :delete, :head request.url(path, options) when :patch, :post, :put request.path = path request.body = MultiJson.dump(options) unless options.empty? end end rescue Faraday::Error::ClientError => error raise Spree::API::Client::Error::ClientError.new(error) end response end def get(path, options = {}) request(:get, path, options).body end def post(path, options={}) request(:post, path, options).body end def put(path, options={}) request(:put, path, options).body end def delete(path, options={}) request(:delete, path, options).body end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems