From 4684e2e2c46bf2aab9e743ce1ea0b7ea925ee51e Mon Sep 17 00:00:00 2001 From: jasdev Date: Thu, 23 Apr 2015 14:09:22 -0700 Subject: [PATCH 1/9] Adding Mashape support --- imgurpython/client.py | 17 +++++++++++++---- setup.py | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/imgurpython/client.py b/imgurpython/client.py index f247d73..e19e70e 100644 --- a/imgurpython/client.py +++ b/imgurpython/client.py @@ -17,6 +17,7 @@ from .imgur.models.account_settings import AccountSettings API_URL = 'https://api.imgur.com/' +MASHAPE_URL = 'https://imgur-apiv3.p.mashape.com/' class AuthWrapper(object): @@ -72,10 +73,11 @@ class ImgurClient(object): 'album', 'name', 'title', 'description' } - def __init__(self, client_id, client_secret, access_token=None, refresh_token=None): + def __init__(self, client_id, client_secret, access_token=None, refresh_token=None, mashape_key=None): self.client_id = client_id self.client_secret = client_secret self.auth = None + self.mashape_key = mashape_key if refresh_token is not None: self.auth = AuthWrapper(access_token, refresh_token, client_id, client_secret) @@ -103,20 +105,27 @@ def authorize(self, response, grant_type='pin'): }, True) def prepare_headers(self, force_anon=False): + headers = {} if force_anon or self.auth is None: if self.client_id is None: raise ImgurClientError('Client credentials not found!') else: - return {'Authorization': 'Client-ID %s' % self.get_client_id()} + headers['Authorization'] = 'Client-ID %s' % self.get_client_id() else: - return {'Authorization': 'Bearer %s' % self.auth.get_current_access_token()} + headers['Authorization'] = 'Bearer %s' % self.auth.get_current_access_token() + + if self.mashape_key is not None: + headers['X-Mashape-Key'] = self.mashape_key + + return headers + def make_request(self, method, route, data=None, force_anon=False): method = method.lower() method_to_call = getattr(requests, method) header = self.prepare_headers(force_anon) - url = API_URL + ('3/%s' % route if 'oauth2' not in route else route) + url = (MASHAPE_URL if self.mashape_key is not None else API_URL) + ('3/%s' % route if 'oauth2' not in route else route) if method in ('delete', 'get'): response = method_to_call(url, headers=header, params=data, data=data) diff --git a/setup.py b/setup.py index 46982b1..79bcbb8 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # http://packaging.python.org/en/latest/tutorial.html#version - version='1.1.5', + version='1.1.6', description='Official Imgur python library with OAuth2 and samples', long_description='', From 0aaaa98dc65a31eb234f53e3bd78688f7fb127d4 Mon Sep 17 00:00:00 2001 From: manu Date: Sat, 30 May 2015 12:38:37 +0200 Subject: [PATCH 2/9] adding a "page" parameter to get_gallery_favorites and get_account_favorites --- imgurpython/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgurpython/client.py b/imgurpython/client.py index e19e70e..544330b 100644 --- a/imgurpython/client.py +++ b/imgurpython/client.py @@ -184,15 +184,15 @@ def get_account(self, username): account_data['pro_expiration'], ) - def get_gallery_favorites(self, username): + def get_gallery_favorites(self, username, page=0): self.validate_user_context(username) - gallery_favorites = self.make_request('GET', 'account/%s/gallery_favorites' % username) + gallery_favorites = self.make_request('GET', 'account/%s/gallery_favorites/%d' % (username, page)) return build_gallery_images_and_albums(gallery_favorites) - def get_account_favorites(self, username): + def get_account_favorites(self, username, page=0): self.validate_user_context(username) - favorites = self.make_request('GET', 'account/%s/favorites' % username) + favorites = self.make_request('GET', 'account/%s/favorites/%d' % (username, page)) return build_gallery_images_and_albums(favorites) From 534c2c8d346e7067b78036f7ece9a1d36a6be18e Mon Sep 17 00:00:00 2001 From: Kevin Cramer Date: Thu, 1 Oct 2015 18:05:24 -0700 Subject: [PATCH 3/9] Update support info. --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index e38054f..999a987 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,7 @@ Our developer documentation can be found [here](https://api.imgur.com/). Community --------- -The best way to reach out to Imgur for API support would be our -[Google Group](https://groups.google.com/forum/#!forum/imgur), [Twitter](https://twitter.com/imgurapi), or via - api@imgur.com. +The best way to reach out to Imgur for API support is emailing us at api@imgur.com. Installation ------------ From 33776a80930fe7b6a199b1b86fd8a78786e176e2 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Sun, 27 Dec 2015 05:28:48 -0500 Subject: [PATCH 4/9] closed file in upload_from_path The file no longer remains open after calling upload_from_path(). This would previously throw warnings. --- imgurpython/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgurpython/client.py b/imgurpython/client.py index 544330b..b860a1a 100644 --- a/imgurpython/client.py +++ b/imgurpython/client.py @@ -586,13 +586,13 @@ def upload_from_path(self, path, config=None, anon=True): fd = open(path, 'rb') contents = fd.read() b64 = base64.b64encode(contents) - data = { 'image': b64, 'type': 'base64', } - data.update({meta: config[meta] for meta in set(self.allowed_image_fields).intersection(config.keys())}) + fd.close() + return self.make_request('POST', 'upload', data, anon) def upload_from_url(self, url, config=None, anon=True): From 3d2d2866770d251bc81c73732fd19fdcaabe012b Mon Sep 17 00:00:00 2001 From: Jacob Greenleaf Date: Fri, 29 Jan 2016 12:54:42 -0800 Subject: [PATCH 5/9] Add TravisYML --- .travis.yml | 9 +++++++++ setup.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8e11c2f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: python +deploy: + provider: pypi + user: imgurops + password: + secure: DBBXzMOm037T4XUmfo0Gu9mAytw2DCYJT8i0KgihKYxS+uslF+dwHf2clBEWDLUE0xkXhqXetq+sNgfshovGKIqZanASYZ/6Zf5ikg10ApgaBidObv2XMYNyuQxL8Gqv9l2tdlWqdUoOJzRBMV2Nh0B3BJ9hG7V5NFMDcfG/qyo= + on: + tags: true + repo: Imgur/imgurpython diff --git a/setup.py b/setup.py index 79bcbb8..300e786 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # http://packaging.python.org/en/latest/tutorial.html#version - version='1.1.6', + version='1.1.7', description='Official Imgur python library with OAuth2 and samples', long_description='', From 8694d428046aee4a5ea47dab55ae86e5663b6e7e Mon Sep 17 00:00:00 2001 From: Jacob Greenleaf Date: Fri, 29 Jan 2016 13:04:22 -0800 Subject: [PATCH 6/9] Add requirements.txt to let Travis install requests --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests From c43e2364c26eaeeba58abfa7f4a001528190aa73 Mon Sep 17 00:00:00 2001 From: Jacob Greenleaf Date: Fri, 29 Jan 2016 13:11:33 -0800 Subject: [PATCH 7/9] Do a simple syntax check on Travis script --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8e11c2f..cd12a9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: python +script: + - python -m compileall deploy: provider: pypi user: imgurops From cb717fe7490d304f858f00b459166f8b42900300 Mon Sep 17 00:00:00 2001 From: Khazhismel Date: Wed, 2 Dec 2015 20:45:17 -0500 Subject: [PATCH 8/9] Allow uploading file-like objects, allowing uploading of BytesIO/etc. --- imgurpython/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/imgurpython/client.py b/imgurpython/client.py index b860a1a..9c41ea6 100644 --- a/imgurpython/client.py +++ b/imgurpython/client.py @@ -580,10 +580,13 @@ def get_image(self, image_id): return Image(image) def upload_from_path(self, path, config=None, anon=True): + with open(path, 'rb') as fd: + self.upload(fd, config, anon) + + def upload(self, fd, config=None, anon=True): if not config: config = dict() - fd = open(path, 'rb') contents = fd.read() b64 = base64.b64encode(contents) data = { @@ -591,7 +594,6 @@ def upload_from_path(self, path, config=None, anon=True): 'type': 'base64', } data.update({meta: config[meta] for meta in set(self.allowed_image_fields).intersection(config.keys())}) - fd.close() return self.make_request('POST', 'upload', data, anon) From 1cd23bc471c1682247e9e5afece3305073befd26 Mon Sep 17 00:00:00 2001 From: Kevin Cramer Date: Thu, 19 Oct 2017 13:14:04 -0700 Subject: [PATCH 9/9] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 999a987..c89b846 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# The imgurpython project is no longer supported. + imgurpython ===========