use extractor.request for API calls (#130)
... at least for OAuth1.0 based APIs (flickr, smugmug, tumblr)
This commit is contained in:
@@ -54,16 +54,17 @@ class Extractor():
|
||||
return config.interpolate(
|
||||
("extractor", self.category, self.subcategory, key), default)
|
||||
|
||||
def request(self, url, method="GET", *,
|
||||
def request(self, url, method="GET", *, session=None,
|
||||
encoding=None, expect=(), retries=None, **kwargs):
|
||||
tries = 0
|
||||
retries = retries or self._retries
|
||||
session = session or self.session
|
||||
kwargs.setdefault("timeout", self._timeout)
|
||||
kwargs.setdefault("verify", self._verify)
|
||||
|
||||
while True:
|
||||
try:
|
||||
response = self.session.request(method, url, **kwargs)
|
||||
response = session.request(method, url, **kwargs)
|
||||
except (requests.exceptions.ConnectionError,
|
||||
requests.exceptions.Timeout,
|
||||
requests.exceptions.ChunkedEncodingError,
|
||||
|
||||
@@ -295,7 +295,6 @@ class FlickrAPI(oauth.OAuth1API):
|
||||
else:
|
||||
self.formats = self.FORMATS
|
||||
self.formats = self.formats[:4]
|
||||
self.subcategory = extractor.subcategory
|
||||
|
||||
def favorites_getList(self, user_id):
|
||||
"""Returns a list of the user's favorite photos."""
|
||||
@@ -387,10 +386,10 @@ class FlickrAPI(oauth.OAuth1API):
|
||||
params["nojsoncallback"] = "1"
|
||||
if self.api_key:
|
||||
params["api_key"] = self.api_key
|
||||
data = self.session.get(self.API_URL, params=params).json()
|
||||
data = self.request(self.API_URL, params=params).json()
|
||||
if "code" in data:
|
||||
if data["code"] == 1:
|
||||
raise exception.NotFoundError(self.subcategory)
|
||||
raise exception.NotFoundError(self.extractor.subcategory)
|
||||
elif data["code"] == 98:
|
||||
raise exception.AuthenticationError(data.get("message"))
|
||||
elif data["code"] == 99:
|
||||
|
||||
@@ -238,7 +238,7 @@ class SmugmugAPI(oauth.OAuth1API):
|
||||
params["APIKey"] = self.api_key
|
||||
params["_verbosity"] = "1"
|
||||
|
||||
response = self.session.get(url, params=params, headers=self.HEADERS)
|
||||
response = self.request(url, params=params, headers=self.HEADERS)
|
||||
data = response.json()
|
||||
|
||||
if 200 <= data["Code"] < 400:
|
||||
|
||||
@@ -303,7 +303,7 @@ class TumblrAPI(oauth.OAuth1API):
|
||||
url = "https://api.tumblr.com/v2/blog/{}/{}".format(
|
||||
blog, endpoint)
|
||||
|
||||
response = self.session.get(url, params=params)
|
||||
response = self.request(url, params=params)
|
||||
data = response.json()
|
||||
status = data["meta"]["status"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user