mirror of
https://github.com/kennethreitz-archive/python-convore.git
synced 2026-06-05 23:40:18 +00:00
Hrmm
This commit is contained in:
+42
-29
@@ -8,9 +8,12 @@
|
|||||||
:copyright: (c) 2011 by Kenneth Reitz.
|
:copyright: (c) 2011 by Kenneth Reitz.
|
||||||
:license: ISC, see LICENSE for more details.
|
:license: ISC, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
import json
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
import models
|
||||||
|
|
||||||
|
|
||||||
__title__ = 'convore'
|
__title__ = 'convore'
|
||||||
__version__ = '0.0.1'
|
__version__ = '0.0.1'
|
||||||
@@ -19,42 +22,52 @@ __author__ = 'Kenneth Reitz'
|
|||||||
__license__ = 'ISC'
|
__license__ = 'ISC'
|
||||||
__copyright__ = 'Copyright 2011 Kenneth Reitz'
|
__copyright__ = 'Copyright 2011 Kenneth Reitz'
|
||||||
|
|
||||||
__all__ = ['Convore']
|
|
||||||
|
|
||||||
API_URL = 'https://convore.com/api/'
|
API_URL = 'https://convore.com/api/'
|
||||||
|
|
||||||
|
|
||||||
class Account(object):
|
def login(username, password):
|
||||||
"""Account API"""
|
auth = requests.AuthObject(username, password)
|
||||||
|
requests.add_autoauth(API_URL, auth)
|
||||||
|
|
||||||
def verify(self):
|
|
||||||
"""Authenticates. Returns True if authentication is successful,
|
|
||||||
False if not."""
|
|
||||||
|
|
||||||
r = requests.get(API_URL + 'account/verify.json')
|
|
||||||
return True if r.status_code == 200 else False
|
|
||||||
|
|
||||||
|
|
||||||
class Groups(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Convore(object):
|
|
||||||
"""The :class:`Convore` object is the heart of this api wrapper. It
|
|
||||||
provides all core functionality.
|
|
||||||
|
|
||||||
:param username: Username to authenticate with.
|
|
||||||
:param password: Password for given username.
|
|
||||||
|
|
||||||
"""
|
def account_verify():
|
||||||
|
r = requests.get(API_URL + 'account/verify.json')
|
||||||
account = Account()
|
try:
|
||||||
groups = Groups()
|
r.raise_for_status()
|
||||||
|
if r.status_code == 200:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except requests.HTTPError:
|
||||||
|
raise LoginFailed
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, username, password):
|
def groups(group_id=None):
|
||||||
self.username = username
|
# seeking list of groups
|
||||||
self.password = password
|
try:
|
||||||
|
|
||||||
requests.add_autoauth(API_URL, requests.AuthObject(self.username, self.password))
|
if not group_id:
|
||||||
|
r = requests.get(API_URL + 'groups.json')
|
||||||
|
groups = json.loads(r.content)['groups']
|
||||||
|
|
||||||
|
_groups = []
|
||||||
|
|
||||||
|
for group in groups:
|
||||||
|
_group = models.Group()
|
||||||
|
_group.import_from_api(group)
|
||||||
|
_groups.append(_group)
|
||||||
|
|
||||||
|
|
||||||
|
return _groups
|
||||||
|
# seeking unique group
|
||||||
|
else:
|
||||||
|
|
||||||
|
pass
|
||||||
|
except requests.HTTPError:
|
||||||
|
raise LoginFailed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class LoginFailed(RuntimeError):
|
||||||
|
"""Login falied!"""
|
||||||
|
|||||||
Reference in New Issue
Block a user