Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Commit

Permalink
aweber_api:oauth update code std.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Druger committed Mar 4, 2014
1 parent 93e2b81 commit b3e0cbb
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions aweber_api/oauth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from urllib import urlencode
import json
import os

import oauth2 as oauth
import json
from urllib import urlencode

import aweber_api
from aweber_api.base import APIException


class OAuthAdapter(object):
Expand All @@ -29,21 +30,20 @@ def request(self, method, url, data={}, response='body'):
url = self._expand_url(url)
body = self._prepare_request_body(method, url, data)

# need a test for the next 4 lines below
content_type = 'application/json'
if method == 'GET' and body is not None and body is not '':
# todo: need a better way to do this!
if '?' in url:
url = '{0}&{1}'.format(url, body)
else:
url = '{0}?{1}'.format(url, body)

if method == 'POST':
content_type = 'application/x-www-form-urlencoded'
headers = {'Content-Type' : content_type}
headers = {'Content-Type': content_type}

resp, content = client.request(
url, method, body=body, headers=headers)

resp, content = client.request(url, method, body=body,
headers=headers)
if int(resp['status']) >= 400:
"""
API Service Errors:
Expand All @@ -58,7 +58,7 @@ def request(self, method, url, data={}, response='body'):
error = content.get('error', {})
error_type = error.get('type')
error_msg = error.get('message')
raise aweber_api.base.APIException(
raise APIException(
'{0}: {1}'.format(error_type, error_msg))

if response == 'body' and isinstance(content, str):
Expand All @@ -71,7 +71,7 @@ def request(self, method, url, data={}, response='body'):

def _expand_url(self, url):
if not url[:4] == 'http':
return '%s%s' % (self.api_base, url)
return '{0}{1}'.format(self.api_base, url)
return url

def _get_client(self):
Expand All @@ -81,11 +81,11 @@ def _get_client(self):
client = oauth.Client(self.consumer, token=token)
else:
client = oauth.Client(self.consumer)

client.ca_certs = os.path.join(os.path.dirname(__file__), 'cacert.crt')
return client

def _prepare_request_body(self, method, url, data):
# might need a test for the changes to this method
if method not in ['POST', 'GET', 'PATCH'] or len(data.keys()) == 0:
return ''
if method in ['POST', 'GET']:
Expand Down

0 comments on commit b3e0cbb

Please sign in to comment.