Class: Giftrocket::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/giftrocket/request.rb

Class Method Summary collapse

Class Method Details

.delete(path, *opts) ⇒ Object



12
13
14
# File 'lib/giftrocket/request.rb', line 12

def self.delete(path, *opts)
  handle_response(HTTParty.delete(url(path), *opts))
end

.get(path, *opts) ⇒ Object



3
4
5
# File 'lib/giftrocket/request.rb', line 3

def self.get(path, *opts)
  handle_response(HTTParty.get(url(path), *opts))
end

.handle_response(response) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/giftrocket/request.rb', line 19

def self.handle_response(response)
  if response.success?
    response_json = JSON.parse(response.body).with_indifferent_access
  else
    raise Giftrocket::Error.new(response)
  end
end

.post(path, *opts) ⇒ Object



6
7
8
# File 'lib/giftrocket/request.rb', line 6

def self.post(path, *opts)
  handle_response(HTTParty.post(url(path), *opts))
end

.put(path, *opts) ⇒ Object



9
10
11
# File 'lib/giftrocket/request.rb', line 9

def self.put(path, *opts)
  handle_response(HTTParty.put(url(path), *opts))
end

.url(path, params = {}) ⇒ Object



15
16
17
# File 'lib/giftrocket/request.rb', line 15

def self.url(path, params={})
  url = URI.join(Giftrocket.config[:base_api_uri], path)
end