Created
May 26, 2013 21:50
-
-
Save scottvdp/5654120 to your computer and use it in GitHub Desktop.
Playing with hammock to wrap the untappd API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hammock import Hammock | |
class Untappd(object): | |
"""Base object for the untappd API wrapper""" | |
def __init__(self, client_id, client_secret): | |
self.params = {'client_id':client_id,'client_secret':client_secret} | |
self._api = Hammock("http://api.untappd.com/v4", params=self.params) | |
class User(Untappd): | |
"""User object for Untappd""" | |
def __call__(self, name): | |
self.name = name | |
self.feed = self._api.user.checkins(self.name).GET().json()['response'] | |
self.info = self._api.user.info(self.name).GET().json()['response'] | |
self.badges = self._api.user.badges(self.name).GET().json()['response'] | |
self.friends = self._api.user.friends(self.name).GET().json()['response'] | |
self.wishlist = self._api.user.wishlist(self.name).GET().json()['response'] | |
self.beers = self._api.user.beers(self.name).GET().json()['response'] | |
return self | |
class Beer(Untappd): | |
"""Beer object with feed and info attributes""" | |
def __call__(self, beerid): | |
self.id = beerid | |
self.feed = self._api.beer.checkins(self.id).GET().json()['response'] | |
self.info = self._api.beer.info(self.id).GET().json()['response'] | |
return self | |
class Venue(Untappd): | |
"""Venue object with feed and info attributes""" | |
def __call__(self, venueid): | |
self.id = venueid | |
self.feed = self._api.venue.checkins(self.id).GET().json()['response'] | |
self.info = self._api.venue.info(self.id).GET().json()['response'] | |
return self | |
class Brewery(Untappd): | |
"""Brewery object with feed and info attributes""" | |
def __call__(self, breweryid): | |
self.id = breweryid | |
self.feed = self._api.brewery.checkins(self.id).GET().json()['response'] | |
self.info = self._api.brewery.info(self.id).GET().json()['response'] | |
return self | |
class Search(Untappd): | |
"""Returns a dict of search results""" | |
def __call__(self, search_type, terms): | |
self.params['q'] = terms | |
self._api = Hammock("http://api.untappd.com/v4", params=self.params) | |
if search_type.lower() == "beer": | |
return self._api.search.beer.GET().json()['response'] | |
elif search_type.lower() == "brewery": | |
return self._api.search.breweries.GET().json()['response'] | |
class Trending(Untappd): | |
"""Returns a dict of currently trending beers""" | |
def __call__(self): | |
return self._api.beer.trending.GET().json()['response'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment