Add some support for datasync, and deleting times from Harvest
This commit is contained in:
parent
fe0daf00bc
commit
bdb8b22ef4
4 changed files with 35 additions and 53 deletions
|
@ -61,6 +61,9 @@ class HarvestWebAPI(object):
|
|||
elif request_method == 'PATCH':
|
||||
response = requests.patch('{}/{}'.format(self.base_url, api_method),
|
||||
headers=headers, params=params)
|
||||
elif request_method == 'DELETE':
|
||||
response = requests.delete('{}/{}'.format(self.base_url, api_method),
|
||||
headers=headers, params=params)
|
||||
else:
|
||||
raise NotImplementedError("unknown request method: {}".format(
|
||||
request_method))
|
||||
|
@ -85,6 +88,12 @@ class HarvestWebAPI(object):
|
|||
"""
|
||||
return self._request('PATCH', api_method, params=params)
|
||||
|
||||
def delete(self, api_method, params=None):
|
||||
"""
|
||||
Perform a DELETE request for the given API method, and return the response.
|
||||
"""
|
||||
return self._request('DELETE', api_method, params=params)
|
||||
|
||||
def get_company(self):
|
||||
"""
|
||||
Retrieves the company for the currently authenticated user.
|
||||
|
@ -170,8 +179,13 @@ class HarvestWebAPI(object):
|
|||
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#retrieve-a-time-entry
|
||||
"""
|
||||
response = self.get('/time_entries/{}'.format(time_entry_id))
|
||||
return response.json()
|
||||
try:
|
||||
response = self.get('/time_entries/{}'.format(time_entry_id))
|
||||
except requests.exceptions.HTTPError as error:
|
||||
if error.response.status_code != 404:
|
||||
raise
|
||||
else:
|
||||
return response.json()
|
||||
|
||||
def create_time_entry(self, **kwargs):
|
||||
"""
|
||||
|
@ -208,6 +222,14 @@ class HarvestWebAPI(object):
|
|||
response = self.patch('/time_entries/{}'.format(time_entry_id), params=kwargs)
|
||||
return response.json()
|
||||
|
||||
def delete_time_entry(self, time_entry_id, **kwargs):
|
||||
"""
|
||||
Delete a time entry.
|
||||
|
||||
https://help.getharvest.com/api-v2/timesheets-api/timesheets/time-entries/#delete-a-time-entry
|
||||
"""
|
||||
self.delete('/time_entries/{}'.format(time_entry_id), params=kwargs)
|
||||
|
||||
|
||||
def make_harvest_webapi(config):
|
||||
access_token = config.require('harvest', 'api.access_token')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue