Skip to content

Instantly share code, notes, and snippets.

@angusb
Created October 16, 2012 18:16
Show Gist options
  • Save angusb/3901024 to your computer and use it in GitHub Desktop.
Save angusb/3901024 to your computer and use it in GitHub Desktop.
asanaapi
class AsanaResource(object):
def __init__(self):
# stuff
def get(self, endpoint=""):
"""Submits a get to the Asana API and returns the result.
Returns:
dict: json response from Asana
"""
target = "/".join([self.aurl, self.resource, str(endpoint)])
if self.debug:
print "-> Calling: %s" % target
r = requests.get(target, auth=(self.api_key, ""))
self._check_http_status(r)
return self._handle_response(r)
# more stuff
class User(AsanaResource):
def __init__(self, user_id='me'):
super(User, self).__init__()
user_json = self.get(user_id)
self._name = user_json['name']
self._email = user_json['email']
self._id = user_json['id']
self._workspaces = user_json['workspaces']
@classmethod
def users(cls):
users = []
users_json = cls.get() # Problematic spot
for user_dict in users_json:
users.append(User(str(user_dict['id'])))
return users
# TypeError: 'unbound method get() must be called with User instance as first argument (got nothing instead)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment