Module: Spree::API::Client::Request
- Included in:
- Spree::API::Client
- Defined in:
- lib/spree-api-client/request.rb
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
- #request(method, path, options = {}) ⇒ Object
Instance Method Details
#delete(path, options = {}) ⇒ Object
53 54 55 |
# File 'lib/spree-api-client/request.rb', line 53 def delete(path, ={}) request(:delete, path, ).body end |
#get(path, options = {}) ⇒ Object
41 42 43 |
# File 'lib/spree-api-client/request.rb', line 41 def get(path, = {}) request(:get, path, ).body end |
#post(path, options = {}) ⇒ Object
45 46 47 |
# File 'lib/spree-api-client/request.rb', line 45 def post(path, ={}) request(:post, path, ).body end |
#put(path, options = {}) ⇒ Object
49 50 51 |
# File 'lib/spree-api-client/request.rb', line 49 def put(path, ={}) request(:put, path, ).body end |
#request(method, path, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/spree-api-client/request.rb', line 8 def request(method, path, = {}) token = .delete(:api_token) || api_token begin response = connection.send(method) do |request| request.headers['Accept'] = .delete(:accept) || 'application/json' if token request.headers['X-Spree-Token'] = token end .merge!(:locale => locale) case method when :get [:per_page] = per_page unless [:per_page] request.url(path, ) when :delete, :head request.url(path, ) when :patch, :post, :put request.path = path request.body = MultiJson.dump() unless .empty? end end rescue Faraday::Error::ClientError => error raise Spree::API::Client::Error::ClientError.new(error) end response end |