X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/36a01feacb6dd0da10fab3c6500eadf91c2336cd..4184843909d3867e3f9d8d489fea78377794cad1:/apps/apiclient/__init__.py?ds=sidebyside diff --git a/apps/apiclient/__init__.py b/apps/apiclient/__init__.py index e61b1bcb..485bf606 100644 --- a/apps/apiclient/__init__.py +++ b/apps/apiclient/__init__.py @@ -1,10 +1,12 @@ +# -*- coding: utf-8 -*- +import json import urllib -from django.utils import simplejson import oauth2 from apiclient.models import OAuthConnection from apiclient.settings import WL_CONSUMER_KEY, WL_CONSUMER_SECRET, WL_API_URL +from django.conf import settings if WL_CONSUMER_KEY and WL_CONSUMER_SECRET: @@ -28,23 +30,23 @@ def api_call(user, path, data=None): token = oauth2.Token(conn.token, conn.token_secret) client = oauth2.Client(wl_consumer, token) if data is not None: - data = simplejson.dumps(data) + data = json.dumps(data) data = urllib.urlencode({"data": data}) resp, content = client.request( "%s%s" % (WL_API_URL, path), method="POST", body=data) else: - resp, content = client.request( - "%s%s" % (WL_API_URL, path)) + resp, content = client.request("%s%s" % (WL_API_URL, path)) status = resp['status'] if status == '200': - return simplejson.loads(content) + return json.loads(content) elif status.startswith('2'): return + elif settings.DEBUG: + raise ApiError(content) elif status == '401': raise ApiError('User not authorized for publishing.') else: - raise ApiError("WL API call error [code %s]" % status") - + raise ApiError("WL API call error [code %s]" % status)