Exemplo n.º 1
0
    def push_entry(self, date, entry):
        post_url = self.get_api_url('/timesheets/')

        mapping = aliases_database[entry.alias]
        parameters = {
            'time': entry.hours,
            'project_id': mapping.mapping[0],
            'activity_id': mapping.mapping[1],
            'date': date.strftime('%Y-%m-%d'),
            'description': entry.description,
        }

        try:
            response = self._session.post(post_url, data=parameters).json()
        except ValueError:
            raise PushEntryFailed(
                "Got a non-JSON response when trying to push timesheet")

        if not response['success']:
            try:
                error = response['error']
            except KeyError:
                error = "Unknown error message"

            raise PushEntryFailed(error)
Exemplo n.º 2
0
    def _push_entry(self, start, duration):
        end = start + datetime.timedelta(seconds=duration)

        r = requests.post(
            f"{self.scheme}://{self.hostname}:{self.port}/{self.path}/timeclock/timechecks/bulk",
            json=[{
                'person': self.person_id,
                'timeclock':
                f"taxi {taxi_version}, taxi-tipee {taxi_tipee_version}",
                'time': start.strftime('%Y-%m-%d %H:%M:%S'),
                'external_id': '',
                'in': True
            }, {
                'person': self.person_id,
                'timeclock':
                f"taxi {taxi_version}, taxi-tipee {taxi_tipee_version}",
                'time': end.strftime('%Y-%m-%d %H:%M:%S'),
                'external_id': ''
            }],
            headers={'Authorization': self.api_token()})

        if r.status_code == 500:
            raise PushEntryFailed(f"[{self.name}] {r.json()['detail']}")

        if r.status_code != 200:
            raise PushEntryFailed(f"[{self.name}] {r.json()['message']}")

        if not all(e['success'] for e in r.json()):
            raise PushEntryFailed(
                f"[{self.name}] {' // '.join(set(e['error'] for e in r.json() if 'error' in e))}"
            )
Exemplo n.º 3
0
    def push_entry(self, date, entry):
        if not isinstance(entry.duration, tuple):
            raise PushEntryFailed(
                f"[{self.name}] does not support durations as hours. Please use a time range instead."
            )

        self.entries[date].append(entry)
Exemplo n.º 4
0
    def push_entry(self, date, entry):
        if not isinstance(entry.duration, tuple):
            raise PushEntryFailed(
                f"[{self.name}] does not support durations as hours. Please use a time range instead."
            )

        seconds = int(entry.hours * 3600)
        mapping = aliases_database[entry.alias]

        r = requests.post(
            f"https://{self.hostname}/{self.path}/worklogs",
            json={
                'issueKey': f"{str(mapping.mapping[0]).upper()}-{int(mapping.mapping[1])}",
                'timeSpentSeconds': seconds,
                'startDate': date.strftime('%Y-%m-%d'),
                'startTime': entry.get_start_time().strftime('%H:%M:%S'),
                'description': entry.description,
                'authorAccountId': self.worker_id,
            },
            headers={'Authorization': f"Bearer {self.api_key}"}
        )

        if r.status_code != 200:
            raise PushEntryFailed(f"[{self.name}] {', '.join(e['message'] for e in r.json()['errors'])}")
Exemplo n.º 5
0
    def push_entry(self, date, entry):
        m, s = divmod(int(entry.hours * 3600), 60)
        h, m = divmod(m, 60)
        duration = f"{h:02d}:{m:02d}"

        mapping = aliases_database[entry.alias]
        project_id = int(mapping.mapping[1])

        r = requests.get(
            f"https://{self.hostname}/2.0/pr_project/{project_id}",
            headers={
                'Accept': 'application/json',
                'Authorization': f"Bearer {self.api_key}"
            })
        response = r.json()
        contact_id = None
        contact_sub_id = None

        if r.status_code == 200:
            contact_id = int(response['contact_id'])
            contact_sub_id = int(response['contact_sub_id'])

        r = requests.post(f"https://{self.hostname}/2.0/timesheet",
                          json={
                              'user_id': self.user_id,
                              'status_id': self.timesheet_status_id,
                              'client_service_id': self.client_service_id,
                              'text': entry.description,
                              'allowable_bill': True,
                              'contact_id': contact_id,
                              'sub_contact_id': contact_sub_id,
                              'pr_project_id': project_id,
                              'tracking': {
                                  'type': 'duration',
                                  'date': date.strftime('%Y-%m-%d'),
                                  'duration': duration
                              }
                          },
                          headers={
                              'Accept': 'application/json',
                              'Authorization': f"Bearer {self.api_key}"
                          })
        response = r.json()

        if r.status_code != 201:
            raise PushEntryFailed(
                f"[{self.name}] API error: HTTP {r.status_code} - {response['message']}"
            )
Exemplo n.º 6
0
    def push_entry(self, date, entry):
        seconds = int(entry.hours * 3600)

        r = requests.post(f'https://{self.hostname}/{self.path}/worklogs',
                          json={
                              'issueKey':
                              entry.alias.upper(),
                              'timeSpentSeconds':
                              seconds,
                              'startDate':
                              date.strftime('%Y-%m-%d'),
                              'startTime':
                              entry.get_start_time().strftime('%H:%M:%S'),
                              'description':
                              entry.description,
                              'authorAccountId':
                              self.worker_id,
                          },
                          headers={'Authorization': f'Bearer {self.api_key}'})

        if r.status_code != 200:
            raise PushEntryFailed(', '.join(e['message']
                                            for e in r.json()['errors']))
Exemplo n.º 7
0
    def push_entry(self, date, entry):
        seconds = int(entry.hours * 3600)
        start_time = datetime.datetime.combine(date, entry.get_start_time())
        end_time = start_time + datetime.timedelta(seconds=seconds)

        r = requests.post(f'https://{self.hostname}/{self.path}/timeclock/timechecks/bulk', json=[
            {
                'person': self.person_id,
                'timeclock': f'taxi {taxi_version}, taxi-tipee {taxi_tipee_version}',
                'time': start_time.strftime('%Y-%m-%d %H:%M:%S'),
                'external_id': '',
            },
            {
                'person': self.person_id,
                'timeclock': f'taxi {taxi_version}, taxi-tipee {taxi_tipee_version}',
                'time': end_time.strftime('%Y-%m-%d %H:%M:%S'),
                'external_id': '',
            }
        ], headers={
            'Authorization': self.api_token()
        })

        if r.status_code != 200:
            raise PushEntryFailed(r.json()['message'])
Exemplo n.º 8
0
        def push_entry(self, date, entry):
            self.entries.append(entry)

            if entry.alias == 'fail':
                raise PushEntryFailed()