mirror of
https://github.com/kennethreitz-archive/python-convore.git
synced 2026-06-05 23:40:18 +00:00
Added friend_list
This commit is contained in:
+41
-6
@@ -7,6 +7,12 @@ import requests
|
|||||||
API_URL = 'https://convore.com/api/'
|
API_URL = 'https://convore.com/api/'
|
||||||
|
|
||||||
|
|
||||||
|
#^groups/discover/friend.json
|
||||||
|
#^groups/discover/explore/(?P<angle>popular|recent|alphabetical).json
|
||||||
|
#^groups/discover/category.json
|
||||||
|
#^groups/discover/category/(?P<category>[\w-]+).json
|
||||||
|
#^groups/discover/search.json
|
||||||
|
|
||||||
|
|
||||||
# =======
|
# =======
|
||||||
# Helpers
|
# Helpers
|
||||||
@@ -20,27 +26,31 @@ def _safe_response(r):
|
|||||||
if r.status_code == 401:
|
if r.status_code == 401:
|
||||||
raise LoginFailed
|
raise LoginFailed
|
||||||
else:
|
else:
|
||||||
raise APIError
|
# raise APIError
|
||||||
|
return r
|
||||||
|
|
||||||
def get(*path, **kwargs):
|
def get(*path):
|
||||||
"""
|
"""
|
||||||
api.get('groups')
|
api.get('groups')
|
||||||
api.get('groups', 'id')
|
api.get('groups', 'id')
|
||||||
api.get('accounts', 'verify')
|
api.get('accounts', 'verify')
|
||||||
"""
|
"""
|
||||||
params = kwargs.get('params', None)
|
|
||||||
url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json')
|
url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json')
|
||||||
r = requests.get(url, params=params)
|
|
||||||
|
r = requests.get(url)
|
||||||
|
print r.url
|
||||||
|
|
||||||
return _safe_response(r)
|
return _safe_response(r)
|
||||||
|
|
||||||
|
|
||||||
def post(*path, **kwargs):
|
def post(params, *path):
|
||||||
params = kwargs.get('params', None)
|
|
||||||
|
|
||||||
url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json')
|
url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json')
|
||||||
r = requests.post(url, params=params)
|
r = requests.post(url, params=params)
|
||||||
return _safe_response(r)
|
return _safe_response(r)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ==========
|
# ==========
|
||||||
# Exceptions
|
# Exceptions
|
||||||
# ==========
|
# ==========
|
||||||
@@ -72,6 +82,7 @@ class User(object):
|
|||||||
|
|
||||||
def import_from_api(self, d):
|
def import_from_api(self, d):
|
||||||
"""Constructs User from Deserialized API Response."""
|
"""Constructs User from Deserialized API Response."""
|
||||||
|
|
||||||
self.username = d.get('username', None)
|
self.username = d.get('username', None)
|
||||||
self.url = d.get('url', None)
|
self.url = d.get('url', None)
|
||||||
self.id = d.get('id', None)
|
self.id = d.get('id', None)
|
||||||
@@ -94,6 +105,7 @@ class Group(object):
|
|||||||
self.date_latest_message = None
|
self.date_latest_message = None
|
||||||
self.date_created = None
|
self.date_created = None
|
||||||
self.topics_count = None
|
self.topics_count = None
|
||||||
|
self.friend_list = None
|
||||||
self.unread = None
|
self.unread = None
|
||||||
self.id = None
|
self.id = None
|
||||||
self.joined = False
|
self.joined = False
|
||||||
@@ -119,6 +131,15 @@ class Group(object):
|
|||||||
self.unread = d.get('unread', None)
|
self.unread = d.get('unread', None)
|
||||||
self.id = d.get('id', None)
|
self.id = d.get('id', None)
|
||||||
|
|
||||||
|
self.friend_list = []
|
||||||
|
|
||||||
|
if 'friend_list' in d:
|
||||||
|
for friend in d.get('friend_list', None):
|
||||||
|
_user = User()
|
||||||
|
_user.import_from_api(friend)
|
||||||
|
self.friend_list.append(_user)
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<group %s>' % (self.slug)
|
return '<group %s>' % (self.slug)
|
||||||
|
|
||||||
@@ -141,7 +162,19 @@ class Groups(object):
|
|||||||
return [g for g in self.groups if g.joined]
|
return [g for g in self.groups if g.joined]
|
||||||
|
|
||||||
|
|
||||||
|
def discover_friend(self):
|
||||||
|
|
||||||
|
_groups = []
|
||||||
|
|
||||||
|
r = get('groups', 'discover', 'friend')
|
||||||
|
|
||||||
|
for group in json.loads(r.content)['groups']:
|
||||||
|
_group = Group()
|
||||||
|
_group.import_from_api(group)
|
||||||
|
_groups.append(_group)
|
||||||
|
|
||||||
|
return _groups
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self.groups)
|
return str(self.groups)
|
||||||
|
|
||||||
@@ -161,10 +194,12 @@ class Groups(object):
|
|||||||
|
|
||||||
return _group
|
return _group
|
||||||
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for group in self.groups:
|
for group in self.groups:
|
||||||
yield group
|
yield group
|
||||||
|
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
|
|
||||||
if isinstance(key, int):
|
if isinstance(key, int):
|
||||||
|
|||||||
Reference in New Issue
Block a user