mirror of
https://github.com/kennethreitz-archive/python-convore.git
synced 2026-06-05 23:40:18 +00:00
extracted _safe_request()
new api.post function
This commit is contained in:
+17
-11
@@ -12,15 +12,7 @@ API_URL = 'https://convore.com/api/'
|
||||
# Helpers
|
||||
# =======
|
||||
|
||||
def get(*path):
|
||||
"""
|
||||
api.get('groups')
|
||||
api.get('groups', 'id')
|
||||
api.get('accounts', 'verify')
|
||||
"""
|
||||
|
||||
url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json')
|
||||
r = requests.get(url)
|
||||
def _safe_response(r):
|
||||
try:
|
||||
r.raise_for_status()
|
||||
return r
|
||||
@@ -30,8 +22,23 @@ def get(*path):
|
||||
else:
|
||||
raise APIError
|
||||
|
||||
def get(*path):
|
||||
"""
|
||||
api.get('groups')
|
||||
api.get('groups', 'id')
|
||||
api.get('accounts', 'verify')
|
||||
"""
|
||||
|
||||
url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json')
|
||||
r = requests.get(url)
|
||||
return _safe_response(r)
|
||||
|
||||
|
||||
def post(params, *path):
|
||||
url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json')
|
||||
r = requests.post(url, params=params)
|
||||
return _safe_response(r)
|
||||
|
||||
# ==========
|
||||
# Exceptions
|
||||
# ==========
|
||||
@@ -141,8 +148,7 @@ class Groups(UserList):
|
||||
return group
|
||||
|
||||
try:
|
||||
r = requests.get(API_URL + 'groups/%s.json' % key)
|
||||
r.raise_for_status()
|
||||
r = get('groups', key)
|
||||
|
||||
group = Group()
|
||||
group.import_from_api(json.loads(r.content)['group'])
|
||||
|
||||
Reference in New Issue
Block a user