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

Commit

Permalink
Merge pull request #7 from electronick1/master
Browse files Browse the repository at this point in the history
Add request session
  • Loading branch information
imankulov committed Jul 10, 2015
2 parents 02740a8 + 5fdf2f2 commit f6214c4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions todoist/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def deserialize(cls, data):
setattr(obj, key, data[key])
return obj

def __init__(self, token='', api_endpoint='https://api.todoist.com'):
def __init__(self, token='', api_endpoint='https://api.todoist.com', session=None):
self.api_endpoint = api_endpoint
self.seq_no = 0 # Sequence number since last update
self.seq_no_partial = {} # Sequence number of partial syncs
Expand Down Expand Up @@ -65,6 +65,7 @@ def __init__(self, token='', api_endpoint='https://api.todoist.com'):
self.token = token # User's API token
self.temp_ids = {} # Mapping of temporary ids to real ids
self.queue = [] # Requests to be sent are appended here
self.session = session or requests.Session() # Session instance for requests

# managers
self.projects = ProjectsManager(self)
Expand Down Expand Up @@ -260,7 +261,9 @@ def _get(self, call, url=None, **kwargs):
"""
if not url:
url = self.get_api_url()
response = requests.get(url + call, **kwargs)

response = self.session.get(url + call, **kwargs)

try:
return response.json()
except ValueError:
Expand All @@ -273,7 +276,9 @@ def _post(self, call, url=None, **kwargs):
"""
if not url:
url = self.get_api_url()
response = requests.post(url + call, **kwargs)

response = self.session.post(url + call, **kwargs)

try:
return response.json()
except ValueError:
Expand Down

0 comments on commit f6214c4

Please sign in to comment.