Class: Groupon::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/groupon/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/groupon/client.rb', line 7

def initialize(options={})
  api_key = options[:api_key] || Groupon.api_key
  self.class.headers({'X-GrouponToken' => api_key }) unless api_key.nil?
end

Class Method Details

.get(*args) ⇒ Object



24
# File 'lib/groupon/client.rb', line 24

def self.get(*args); handle_response super end

.handle_response(response) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/groupon/client.rb', line 27

def self.handle_response(response)
  case response.code
  when 500...600; raise GrouponError.new(Hashie::Mash.new(response).status)
  else; response
  end
  
  Hashie::Mash.new(response)
  
end

.post(*args) ⇒ Object



25
# File 'lib/groupon/client.rb', line 25

def self.post(*args); handle_response super end

Instance Method Details

#deals(query = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/groupon/client.rb', line 16

def deals(query={})
  division = query.delete(:division)
  path = division ? "/#{division}" : ""
  path += "/deals.json"
  self.class.get(path, :query => query).deals
end

#divisionsObject



12
13
14
# File 'lib/groupon/client.rb', line 12

def divisions
  self.class.get("/divisions.json").divisions
end