Class: Groupon::Client
- Inherits:
-
Object
- Object
- Groupon::Client
- Includes:
- HTTParty
- Defined in:
- lib/groupon/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Class Method Summary collapse
Instance Method Summary collapse
-
#deals(query = {}) ⇒ Array<Hashie::Mash>
Returns a list of deals.
-
#divisions ⇒ Array<Hashie::Mash>
Returns a list of divisions - cities where Groupon is live.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize the Groupon client.
Constructor Details
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/groupon/client.rb', line 3 def api_key @api_key end |
Class Method Details
.get(*args) ⇒ Object
48 |
# File 'lib/groupon/client.rb', line 48 def self.get(*args); handle_response super end |
.handle_response(response) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/groupon/client.rb', line 51 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
49 |
# File 'lib/groupon/client.rb', line 49 def self.post(*args); handle_response super end |
Instance Method Details
#deals(query = {}) ⇒ Array<Hashie::Mash>
Returns a list of deals.
The API returns an ordered list of deals currently running for a given Division.
Priority is based on position within the response (top deals are higher in priority).
40 41 42 43 44 45 46 |
# File 'lib/groupon/client.rb', line 40 def deals(query={}) division = query.delete(:division) query.merge! :client_id => @api_key path = division ? "/#{division}" : "" path += "/deals.json" self.class.get(path, :query => query).deals end |
#divisions ⇒ Array<Hashie::Mash>
Returns a list of divisions - cities where Groupon is live.
19 20 21 |
# File 'lib/groupon/client.rb', line 19 def divisions self.class.get("/divisions.json",:query => { :client_id => @api_key }).divisions end |