Skip to content

Commit

Permalink
support POST in make_api_call
Browse files Browse the repository at this point in the history
  • Loading branch information
brosner committed Jul 6, 2010
1 parent 468d730 commit c9c9adc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions oauth_access/access.py
Expand Up @@ -215,16 +215,27 @@ def lookup_user(self, identifier):

def make_api_call(self, kind, url, token, method="GET", **kwargs):
if isinstance(token, OAuth20Token):
url += "?%s" % urllib.urlencode(dict(access_token=str(token)))
request_kwargs = dict(method=method)
if method == "POST":
params = {
"access_token": str(token),
}
params.update(kwargs["params"])
request_kwargs["body"] = urllib.urlencode(params)
else:
url += "?%s" % urllib.urlencode(dict(access_token=str(token)))
http = httplib2.Http()
response, content = http.request(url, method=method)
response, content = http.request(url, **request_kwargs)
else:
if isinstance(token, basestring):
token = oauth.Token.from_string(token)
client = Client(self.consumer, token=token)
# @@@ LinkedIn requires Authorization header which is supported in
# sub-classed version of Client (originally from oauth2)
response, content = client.request(url, method=method, force_auth_header=True)
request_kwargs = dict(method=method, force_auth_header=True)
if method == "POST":
request_kwargs["body"] = urllib.urlencode(kwargs["params"])
response, content = client.request(url, **request_kwargs)
if response["status"] == "401":
raise NotAuthorized()
if not content:
Expand Down

0 comments on commit c9c9adc

Please sign in to comment.