Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
tweepy
Commits
f2a11439
Commit
f2a11439
authored
Aug 20, 2013
by
Joshua Roesslein
Browse files
Merge pull request #297 from Aaron1011/add_update_banner
Add account/update_profile_banner endpoint
parents
eb0cea62
5acff93d
Changes
4
Hide whitespace changes
Inline
Side-by-side
examples/banner.png
0 → 100644
View file @
f2a11439
3.75 KB
tests/test_api.py
View file @
f2a11439
...
...
@@ -198,6 +198,9 @@ class TweepyAPITests(TweepyTestCase):
self.api.update_profile_background_image('examples/bg.png')
"""
def
testupdateprofilebannerimage
(
self
):
self
.
api
.
update_profile_banner
(
'examples/banner.png'
)
def
testupdateprofile
(
self
):
original
=
self
.
api
.
me
()
profile
=
{
...
...
tweepy/api.py
View file @
f2a11439
...
...
@@ -366,6 +366,17 @@ class API(object):
require_auth
=
True
)(
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 """
update_profile
=
bind_api
(
path
=
'/account/update_profile.json'
,
...
...
@@ -657,7 +668,7 @@ class API(object):
""" Internal use only """
@
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"""
# image must be less than 700kb in size
try
:
...
...
@@ -679,7 +690,7 @@ class API(object):
BOUNDARY
=
'Tw3ePy'
body
=
[]
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
(
''
)
body
.
append
(
fp
.
read
())
...
...
tweepy/binder.py
View file @
f2a11439
...
...
@@ -165,7 +165,7 @@ def bind_api(**config):
# If an error was returned, throw an exception
self
.
api
.
last_response
=
resp
if
resp
.
status
!=
2
00
:
if
resp
.
status
and
not
200
<=
resp
.
status
<
3
00
:
try
:
error_msg
=
self
.
api
.
parser
.
parse_error
(
resp
.
read
())
except
Exception
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment