From 39cf91062c4889a60274ac58173bc4228f1ac45f Mon Sep 17 00:00:00 2001 From: Maksym Novozhylov Date: Fri, 17 Jul 2015 09:22:48 +0200 Subject: [PATCH] add workdays api --- changelog.rst | 7 +++++ upwork/routers/team.py | 70 ++++++++++++++++++++++++++++++++++++++++++ upwork/tests.py | 6 ++++ 3 files changed, 83 insertions(+) diff --git a/changelog.rst b/changelog.rst index d9e2888..9ce65ed 100644 --- a/changelog.rst +++ b/changelog.rst @@ -5,6 +5,13 @@ Changelog *************** +.. _1.0.1: + +Version 1.0.1 +------------- +* Added new API call - :py:meth:`Get Workdays by Company `. +* Added new API call - :py:meth:`Get Workdays by Contract `. + .. _1.0.0: Version 1.0.0 diff --git a/upwork/routers/team.py b/upwork/routers/team.py index 8879324..0f170dd 100644 --- a/upwork/routers/team.py +++ b/upwork/routers/team.py @@ -220,6 +220,76 @@ def get_snapshots(self, company_or_team_id, online=None, disabled=None): return snapshots + def get_workdays_by_company(self, company_id, from_date, till_date, tz=None): + """ + Retrieve workdays by company + + *Parameters:* + :company_id: The Company ID. + + :from_date: The target start date in `yyyymmdd` format. + + :end_date: The target end date in `yyyymmdd` format. + + :tz: (optional) Time zone to use. Possible values: + * 'mine' (default) + * 'user' + * 'gmt' + + """ + url = 'workdays/companies/{0}/{1},{2}'.format(company_id, from_date, till_date) + + data = {} + + if tz: + assert_parameter('tz', tz, self.TZ_CHOICES) + data['tz'] = tz + + result = self.get(url, data) + if 'error' in result: + return result + + workdays = result.get('workdays', data) + if not isinstance(workdays, list): + workdays = {} + + return workdays + + def get_workdays_by_contract(self, contract_id, from_date, till_date, tz=None): + """ + Retrieve workdays by contract + + *Parameters:* + :contract_id: The Contract ID. + + :from_date: The target start date in `yyyymmdd` format. + + :end_date: The target end date in `yyyymmdd` format. + + :tz: (optional) Time zone to use. Possible values: + * 'mine' (default) + * 'user' + * 'gmt' + + """ + url = 'workdays/contracts/{0}/{1},{2}'.format(contract_id, from_date, till_date) + + data = {} + + if tz: + assert_parameter('tz', tz, self.TZ_CHOICES) + data['tz'] = tz + + result = self.get(url, data) + if 'error' in result: + return result + + workdays = result.get('workdays', data) + if not isinstance(workdays, list): + workdays = {} + + return workdays + def get_workdiaries_by_contract(self, contract_id, date, tz=None): """ Retrieve workdiary snapshots by contract diff --git a/upwork/tests.py b/upwork/tests.py index 1879bef..2fdaed3 100644 --- a/upwork/tests.py +++ b/upwork/tests.py @@ -387,6 +387,12 @@ def test_team(): eq_(te_v2.get_workdiaries_by_contract(1, 1), (teamrooms_dict['snapshots']['user'], [teamrooms_dict['snapshots']['snapshot']])) + #test get_workdays + eq_(te_v2.get_workdays_by_company(1, 1, 1), {}) + + #test get_workdays_by_contract + eq_(te_v2.get_workdays_by_contract(1, 1, 1), {}) + #test get_snapshot_by_contract eq_(te_v2.get_snapshot_by_contract(1), {'status':'private'})