Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
Make sure we don't send too much data in querystrings
Browse files Browse the repository at this point in the history
Use POST requests and POST data to sync commands and some other calls
where it makes sense.

Thanks @miracle2k for the catch. Closes #4
  • Loading branch information
imankulov committed May 4, 2015
1 parent 3ef2dc8 commit 0111423
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions todoist/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,21 @@ def sync(self, commands=None, **kwargs):
Sends to the server the changes that were made locally, and also
fetches the latest updated data from the server.
"""
params = {
data = {
'token': self.token,
'commands': json.dumps(commands or []),
'commands': json.dumps(commands or [], separators=',:'),
'day_orders_timestamp': self.state['DayOrdersTimestamp'],
}
if not commands:
params['seq_no'], params['seq_no_global'] = \
data['seq_no'], data['seq_no_global'] = \
self._get_seq_no(kwargs.get('resource_types', None))

if 'include_notification_settings' in kwargs:
params['include_notification_settings'] = 1
data['include_notification_settings'] = 1
if 'resource_types' in kwargs:
params['resource_types'] = json.dumps(kwargs['resource_types'])
data = self._post('sync', params=params)
data['resource_types'] = json.dumps(kwargs['resource_types'],
separators=',:')
data = self._post('sync', data=data)
self._update_state(data)
if not commands:
self._update_seq_no(data.get('seq_no', None),
Expand Down Expand Up @@ -339,8 +340,8 @@ def login(self, email, password):
"""
Logins user, and returns the response received by the server.
"""
data = self._get('login', params={'email': email,
'password': password})
data = self._post('login', data={'email': email,
'password': password})
if 'token' in data:
self.token = data['token']
return data
Expand All @@ -351,9 +352,9 @@ def login_with_google(self, email, oauth2_token, **kwargs):
the server.
"""
params = {'email': email, 'oauth2_token': oauth2_token}
params.update(kwargs)
data = self._get('login_with_google', params=params)
data = {'email': email, 'oauth2_token': oauth2_token}
data.update(kwargs)
data = self._post('login_with_google', data=data)
if 'token' in data:
self.token = data['token']
return data
Expand All @@ -363,9 +364,9 @@ def register(self, email, full_name, password, **kwargs):
"""
Registers a new user.
"""
params = {'email': email, 'full_name': full_name, 'password': password}
params.update(kwargs)
data = self._get('register', params=params)
data = {'email': email, 'full_name': full_name, 'password': password}
data.update(kwargs)
data = self._post('register', data=data)
if 'token' in data:
self.token = data['token']
return data
Expand All @@ -375,17 +376,18 @@ def upload_file(self, filename, **kwargs):
"""
Uploads a file.
"""
params = {'token': self.token}
params.update(kwargs)
data = {'token': self.token}
data.update(kwargs)
files = {'file': open(filename, 'rb')}
return self._post('upload_file', self.get_api_url(), params=params,
return self._post('upload_file', self.get_api_url(), data=data,
files=files)

def query(self, queries, **kwargs):
"""
Performs date queries and other searches, and returns the results.
"""
params = {'queries': json.dumps(queries), 'token': self.token}
params = {'queries': json.dumps(queries, separators=',:'),
'token': self.token}
params.update(kwargs)
return self._get('query', params=params)

Expand All @@ -409,11 +411,11 @@ def update_notification_setting(self, notification_type, service,
"""
Updates the user's notification settings.
"""
return self._get('update_notification_setting',
params={'token': self.token,
'notification_type': notification_type,
'service': service,
'dont_notify': dont_notify})
return self._post('update_notification_setting',
data={'token': self.token,
'notification_type': notification_type,
'service': service,
'dont_notify': dont_notify})

def get_all_completed_items(self, **kwargs):
"""
Expand Down

0 comments on commit 0111423

Please sign in to comment.