BigW Consortium Gitlab

Commit 31f1f442 by Tarun Bhardwaj

Add request based client

parent 5291e67d
...@@ -300,6 +300,10 @@ class API(object): ...@@ -300,6 +300,10 @@ class API(object):
fields.append((name, str(value))) fields.append((name, str(value)))
content_type, body = encode_multipart_formdata(fields, files) content_type, body = encode_multipart_formdata(fields, files)
else:
url = '%s%s' % (self.api_url, url)
body = urlencode(kwargs)
content_type = 'application/x-www-form-urlencoded'
self.last_url = url self.last_url = url
data = self._get_url(url, http_method, content_type, body) data = self._get_url(url, http_method, content_type, body)
......
from etsy import EtsyEnvProduction
from requests_oauthlib import OAuth1Session
class EtsyOAuthClient(OAuth1Session):
def __init__(self, oauth_consumer_key,
oauth_consumer_secret, etsy_env=EtsyEnvProduction()):
super(EtsyOAuthClient, self).__init__(
oauth_consumer_key, oauth_consumer_secret)
self.request_token_url = etsy_env.request_token_url
self.access_token_url = etsy_env.access_token_url
self.signin_url = etsy_env.signin_url
def get_signin_url(self, **kwargs):
self.fetch_request_token(self.request_token_url)
return self.authorization_url(self.signin_url)
def set_oauth_verifier(self, oauth_verifier):
token = self.fetch_access_token(
self.access_token_url, verifier=unicode(oauth_verifier))
self.resource_owner_key = token['oauth_token']
self.resource_owner_secret = token['oauth_token_secret']
def do_oauth_request(self, url, http_method, content_type, body):
headers = {}
if content_type:
headers = {'Content-Type': content_type}
return self.request(http_method, url, headers=headers, data=body).text
...@@ -9,6 +9,8 @@ requirements = [ ...@@ -9,6 +9,8 @@ requirements = [
'httplib2', 'httplib2',
'oauth2==1.9.0.post1', 'oauth2==1.9.0.post1',
'simplejson', 'simplejson',
'requests',
'requests_oauthlib',
] ]
test_requirements = [ test_requirements = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment