Created
February 13, 2013 19:33
-
-
Save maxcountryman/4947401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def request(self, | |
method, | |
uri, | |
access_token=None, | |
access_token_secret=None, | |
header_auth=False, | |
allow_redirects=False, | |
**kwargs): | |
'''Makes a proper OAuth 1.0/a request. | |
:param method: A string representation of the HTTP method to be | |
used. | |
:param uri: The resource to be requested. | |
:param access_token: The access token as returned by | |
:class:`get_access_token`. | |
:param access_token_secret: The access token secret as returned by | |
:class:`get_access_token`. | |
:param header_auth: Authenication via header, defaults to False. | |
:param allow_redirects: Allows a request to redirect, defaults to True. | |
:param \*\*kwargs: Optional arguments. Same as Requests. | |
''' | |
header_auth = header_auth or self.header_auth | |
# prepend a base_url to the uri if we can | |
if self.base_url is not None and not absolute_url(uri): | |
uri = urljoin(self.base_url, uri) | |
# check user supplied tokens | |
tokens = (access_token, access_token_secret) | |
all_tokens_none = all(v is None for v in tokens) | |
if None in tokens and not all_tokens_none: | |
raise TypeError('Either both or neither access_token and ' | |
'access_token_secret must be supplied') | |
# use default tokens if user supplied tokens are not present | |
if all_tokens_none: | |
access_token = self.access_token | |
access_token_secret = self.access_token_secret | |
response = OAuth1Request(method=method, | |
url=uri, | |
consumer_key=self.consumer_key, | |
consumer_secret=self.consumer_secret, | |
access_token=access_token, | |
access_token_secret=access_token_secret, | |
header_auth=header_auth, | |
**kwargs).send() | |
return Response(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment