X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/f4921ca797953ddab6b35786864b2dd523190503..63519710f7ae064e26d3ee068d59201e8bc02cf3:/apps/apiclient/__init__.py diff --git a/apps/apiclient/__init__.py b/apps/apiclient/__init__.py index 7913ac3c..33d20081 100644 --- a/apps/apiclient/__init__.py +++ b/apps/apiclient/__init__.py @@ -22,25 +22,29 @@ class NotAuthorizedError(BaseException): def api_call(user, path, data=None): - # what if not verified? conn = OAuthConnection.get(user) if not conn.access: raise NotAuthorizedError("No WL authorization for user %s." % user) token = oauth2.Token(conn.token, conn.token_secret) client = oauth2.Client(wl_consumer, token) if data is not None: + data = simplejson.dumps(data) + data = urllib.urlencode({"data": data}) resp, content = client.request( - "%s%s.json" % (WL_API_URL, path), + "%s%s" % (WL_API_URL, path), method="POST", - body=urllib.urlencode(data)) + body=data) else: resp, content = client.request( - "%s%s.json" % (WL_API_URL, path)) + "%s%s" % (WL_API_URL, path)) status = resp['status'] + if status == '200': return simplejson.loads(content) elif status.startswith('2'): return + elif status == '401': + raise ApiError('User not authorized for publishing.') else: - raise ApiError("WL API call error") + raise ApiError("WL API call error %s, path: %s" % (status, path))