Skip to content

Commit

Permalink
utils: Request parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
flashingpumpkin committed Apr 13, 2010
1 parent 669713d commit e58d26a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions socialregistration/utils.py
Expand Up @@ -190,6 +190,9 @@ def _get_request_token(self):
return self.request_token

def _get_access_token(self):
"""
Obtain the access token to access private resources at the API endpoint.
"""
if self.access_token is None:
request_token = self._get_rt_from_session()
token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
Expand Down Expand Up @@ -236,6 +239,12 @@ def get_redirect(self):
return HttpResponseRedirect(self._get_authorization_url())

class OAuth(object):
"""
Base class to perform oauth signed requests from access keys saved in a user's
session.
See the ``OAuthTwitter`` class below for an example.
"""

def __init__(self, request, consumer_key, secret_key, request_token_url):
self.request = request

Expand All @@ -255,16 +264,21 @@ def _get_at_from_session(self):
raise OAuthError(
_('No access token saved for "%s".') % get_token_prefix(self.request_token_url))

def query(self, url, method="GET", params=dict()):
# TODO: Params

at = self._get_at_from_session()
def query(self, url, method="GET", params=dict(), headers=dict()):
"""
Request a API endpoint at ``url`` with ``params`` being either the
POST or GET data.
"""
access_token = self._get_at_from_session()

token = oauth.Token(at['oauth_token'], at['oauth_token_secret'])
token = oauth.Token(access_token['oauth_token'], access_token['oauth_token_secret'])

client = oauth.Client(self.consumer, token)

response, content = client.request(url, method=method)
body = urllib.urlencode(params)

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

if response['status'] != '200':
raise OAuthError(
Expand Down

0 comments on commit e58d26a

Please sign in to comment.