tumblr / pytumblr

A Python Tumblr API v2 Client
Apache License 2.0
723 stars 196 forks source link

Handle 302 responses same as other successes; fix avatars #101

Closed ceyko closed 6 years ago

ceyko commented 6 years ago

Description

We previously only treated 200, 201 and 301 http response codes as successes, and everything else as an error. Switch to treating all codes between 200 and 399 as successes.

This was necessary due to a backend change where avatars are now returned as 302 responses instead of 301, causing their entire json payload to be returned instead of just the relevant portion.

Testing

Unit tests added to show the expected return from the client.avatar() call. You can also observe via the following:

master
>>> client.avatar('staff')
{u'meta': {u'status': 302, u'msg': u'Found'}, u'response': {u'avatar_url': u'https://78.media.tumblr.com/avatar_4490c797e72f_64.png'}}

branch
>>> client.avatar('staff')
{u'avatar_url': u'https://78.media.tumblr.com/avatar_4490c797e72f_64.png'}