Commit f2a11439 authored by Joshua Roesslein's avatar Joshua Roesslein
Browse files

Merge pull request #297 from Aaron1011/add_update_banner

Add account/update_profile_banner endpoint
parents eb0cea62 5acff93d
...@@ -198,6 +198,9 @@ class TweepyAPITests(TweepyTestCase): ...@@ -198,6 +198,9 @@ class TweepyAPITests(TweepyTestCase):
self.api.update_profile_background_image('examples/bg.png') self.api.update_profile_background_image('examples/bg.png')
""" """
def testupdateprofilebannerimage(self):
self.api.update_profile_banner('examples/banner.png')
def testupdateprofile(self): def testupdateprofile(self):
original = self.api.me() original = self.api.me()
profile = { profile = {
......
...@@ -366,6 +366,17 @@ class API(object): ...@@ -366,6 +366,17 @@ class API(object):
require_auth = True require_auth = True
)(self, post_data=post_data, headers=headers) )(self, post_data=post_data, headers=headers)
""" account/update_profile_banner """
def update_profile_banner(self, filename, *args, **kargs):
headers, post_data = API._pack_image(filename, 700, form_field="banner")
bind_api(
path = '/account/update_profile_banner.json',
method = 'POST',
allowed_param = ['width', 'height', 'offset_left', 'offset_right'],
require_auth = True
)(self, post_data=post_data, headers=headers)
""" account/update_profile """ """ account/update_profile """
update_profile = bind_api( update_profile = bind_api(
path = '/account/update_profile.json', path = '/account/update_profile.json',
...@@ -657,7 +668,7 @@ class API(object): ...@@ -657,7 +668,7 @@ class API(object):
""" Internal use only """ """ Internal use only """
@staticmethod @staticmethod
def _pack_image(filename, max_size): def _pack_image(filename, max_size, form_field="image"):
"""Pack image from file into multipart-formdata post body""" """Pack image from file into multipart-formdata post body"""
# image must be less than 700kb in size # image must be less than 700kb in size
try: try:
...@@ -679,7 +690,7 @@ class API(object): ...@@ -679,7 +690,7 @@ class API(object):
BOUNDARY = 'Tw3ePy' BOUNDARY = 'Tw3ePy'
body = [] body = []
body.append('--' + BOUNDARY) body.append('--' + BOUNDARY)
body.append('Content-Disposition: form-data; name="image"; filename="%s"' % filename) body.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (form_field, filename))
body.append('Content-Type: %s' % file_type) body.append('Content-Type: %s' % file_type)
body.append('') body.append('')
body.append(fp.read()) body.append(fp.read())
......
...@@ -165,7 +165,7 @@ def bind_api(**config): ...@@ -165,7 +165,7 @@ def bind_api(**config):
# If an error was returned, throw an exception # If an error was returned, throw an exception
self.api.last_response = resp self.api.last_response = resp
if resp.status != 200: if resp.status and not 200 <= resp.status < 300:
try: try:
error_msg = self.api.parser.parse_error(resp.read()) error_msg = self.api.parser.parse_error(resp.read())
except Exception: except Exception:
......
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