Skip to content

Commit

Permalink
Merge 1a69a48 into baa0aaa
Browse files Browse the repository at this point in the history
  • Loading branch information
pnpnpn committed Jul 13, 2015
2 parents baa0aaa + 1a69a48 commit a0e5696
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,9 +1,10 @@
language: python
python:
- "2.7"
- "3.4"
# does not have headers provided, please ask https://launchpad.net/~pypy/+archive/ppa
# maintainers to fix their pypy-dev package.
- "pypy"
#- "pypy"
# command to install dependencies
install:
- pip install -r requirements.txt
Expand Down
15 changes: 4 additions & 11 deletions buffpy/api.py
Expand Up @@ -35,33 +35,26 @@ def access_token(self, value):
self.session.access_token = value

def get(self, url, parser=None):
if parser is None:
parser = json.loads

if not self.session.access_token:
raise ValueError('Please set an access token first!')

response = self.session.get(url=BASE_URL % url)

return parser(response.content)
return response.json()

def post(self, url, parser=None, **params):
if parser is None:
parser = json.loads

if not self.session.access_token:
raise ValueError('Please set an access token first!')

headers = {'Content-Type': 'application/x-www-form-urlencoded'}

#Check if posting data and if data is unicode, encoding it as utf-8
if 'data' in params and isinstance(params['data'], unicode):
params['data'] = params['data'].encode('utf-8')

#if 'data' in params and isinstance(params['data'], str):
# params['data'] = params['data'].encode('utf-8')

response = self.session.post(url=BASE_URL % url, headers=headers, **params)

return parser(response.content)
return response.json()

@property
def info(self):
Expand Down
2 changes: 1 addition & 1 deletion buffpy/managers/updates.py
Expand Up @@ -124,7 +124,7 @@ def new(self, text, shorten=None, now=None, top=None, media=None, when=None):
if media:
media_format = "media[%s]=%s&"

for media_type, media_item in media.iteritems():
for media_type, media_item in sorted(media.items(), reverse=True):
post_data += media_format % (media_type, media_item)

response = self.api.post(url=url, data=post_data)
Expand Down
2 changes: 1 addition & 1 deletion buffpy/models/profile.py
Expand Up @@ -43,7 +43,7 @@ def schedules(self, schedules):
data_format = "schedules[0][%s][]=%s&"
post_data = ""

for format_type, values in schedules.iteritems():
for format_type, values in schedules.items():
for value in values:
post_data += data_format % (format_type, value)

Expand Down
2 changes: 1 addition & 1 deletion buffpy/models/update.py
Expand Up @@ -60,7 +60,7 @@ def edit(self, text, media=None, utc=None, now=None):
if media:
media_format = "media[%s]=%s&"

for media_type, media_item in media.iteritems():
for media_type, media_item in media.items():
post_data += media_format % (media_type, media_item)

response = self.api.post(url=url, data=post_data)
Expand Down
2 changes: 1 addition & 1 deletion buffpy/tests/test_api.py
Expand Up @@ -85,7 +85,7 @@ def test_api_info():
mocked_session = MagicMock()

mocked_response = MagicMock()
mocked_response.content = json.dumps({'status': 'ok'})
mocked_response.json.return_value = {'status': 'ok'}
mocked_session.get.return_value = mocked_response

mocked_oauth2.return_value = mocked_session
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -3,4 +3,4 @@ coverage==3.7.1
mock==1.0.1
nose==1.3.0
rauth==0.6.2
requests==1.2.3
requests==2.7.0

0 comments on commit a0e5696

Please sign in to comment.