Skip to content

Commit

Permalink
Merge pull request #7 from dribia/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
nikosdribia authored Jan 25, 2024
2 parents ae7dfd3 + 5b4233b commit f96b8bd
Show file tree
Hide file tree
Showing 13 changed files with 1,180 additions and 998 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: snok/install-poetry@v1
- uses: actions/setup-python@v4
with:
python-version: "3.7"
- name: Install Poetry
run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
python-version: '3.10'
cache: 'poetry'
- name: Install Dependencies
run: poetry install
run: poetry install --only docs
- name: Publish Docs
run: poetry run mkdocs gh-deploy --force
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.7"
python-version: "3.8"
- name: Install Poetry
run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
run: curl -sSL https://install.python-poetry.org | python3 -
- name: Build Package
run: poetry build
- name: Publish
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ['3.8', '3.9', '3.10']
fail-fast: false

steps:
Expand All @@ -20,7 +20,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -
run: curl -sSL https://install.python-poetry.org | python3 -
- name: Install Dependencies
run: poetry install
- name: Lint
Expand Down
31 changes: 14 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-yaml
- id: check-json
- id: check-yaml
- id: check-json
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 21.7b0
rev: 23.1.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.9.3
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.257
hooks:
- id: isort
- id: ruff
args: [ --fix ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
rev: v1.1.1
hooks:
- id: mypy
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
additional_dependencies:
- toml
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- types-PyYAML
- pydantic>=2.2.1,<3.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x<p style="text-align: center; padding-bottom: 1rem;">
<p style="text-align: center; padding-bottom: 1rem;">
<a href="https://dribia.github.io/drifactorial">
<img
src="https://dribia.github.io/drifactorial/img/logo_dribia_blau_cropped.png"
Expand Down
22 changes: 11 additions & 11 deletions drifactorial/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from typing import Any, Dict, Generator, List, Optional, Tuple, Union
from urllib import parse, request

import pydantic
from dateutil.parser import parse as du_parse # type: ignore
from pydantic import TypeAdapter

from drifactorial.schemas import Account, Employee, Holiday, Leave, Shift, Token

Expand Down Expand Up @@ -130,7 +130,7 @@ def get_holidays(
List of Holiday objects.
"""
response = self._get(endpoint=URL_HOLIDAYS)
parsed = [pydantic.parse_obj_as(Holiday, x) for x in response]
parsed = [TypeAdapter(Holiday).validate_python(x) for x in response]
if start is not None:
parsed = [x for x in parsed if x.date >= _parse_date(start)]
if end is not None:
Expand All @@ -140,12 +140,12 @@ def get_holidays(
def get_employees(self) -> List[Employee]:
"""Get employees information."""
response = self._get(endpoint=URL_EMPLOYEES)
return [pydantic.parse_obj_as(Employee, x) for x in response]
return [TypeAdapter(Employee).validate_python(x) for x in response]

def get_single_employee(self, *, employee_id: int) -> Employee:
"""Get single employee information."""
response = self._get(endpoint=f"{URL_EMPLOYEES}/{employee_id}")
return pydantic.parse_obj_as(Employee, response)
return TypeAdapter(Employee).validate_python(response)

def get_shifts(
self,
Expand All @@ -172,7 +172,7 @@ def get_shifts(
if year is not None and month is not None:
params = {"year": f"{year}", "month": f"{month}"}
response = self._get(endpoint=URL_SHIFTS, params=params)
parsed = [pydantic.parse_obj_as(Shift, x) for x in response]
parsed = [TypeAdapter(Shift).validate_python(x) for x in response]
if employee_id is not None:
parsed = [x for x in parsed if x.employee_id == employee_id]
return parsed
Expand All @@ -195,7 +195,7 @@ def get_leaves(
List of Leaves objects.
"""
response = self._get(endpoint=URL_LEAVES)
parsed = [pydantic.parse_obj_as(Leave, x) for x in response]
parsed = [TypeAdapter(Leave).validate_python(x) for x in response]
if start is not None:
parsed = [x for x in parsed if x.finish_on >= _parse_date(start)]
if end is not None:
Expand Down Expand Up @@ -292,19 +292,19 @@ def get_daysoff(
def get_account(self) -> Account:
"""Get account information."""
response = self._get(endpoint=URL_ACCOUNT)
return pydantic.parse_obj_as(Account, response)
return TypeAdapter(Account).validate_python(response)

def clock_in(self, *, now: datetime, employee_id: int) -> Shift:
"""Post clock-in time."""
payload = {"now": f"{now.isoformat()}", "employee_id": f"{employee_id}"}
response = self._post(endpoint=f"{URL_SHIFTS}/{URL_CLOCK_IN}", payload=payload)
return pydantic.parse_obj_as(Shift, response)
return TypeAdapter(Shift).validate_python(response)

def clock_out(self, *, now: datetime, employee_id: int) -> Shift:
"""Post clock-out time."""
payload = {"now": f"{now.isoformat()}", "employee_id": f"{employee_id}"}
response = self._post(endpoint=f"{URL_SHIFTS}/{URL_CLOCK_OUT}", payload=payload)
return pydantic.parse_obj_as(Shift, response)
return TypeAdapter(Shift).validate_python(response)

@staticmethod
def obtain_authorization_link(
Expand Down Expand Up @@ -372,7 +372,7 @@ def obtain_access_token(
"grant_type": "authorization_code",
}
response = self._post_token(data=data)
token = pydantic.parse_obj_as(Token, response)
token = TypeAdapter(Token).validate_python(response)
self.access_token = token.access_token
return token

Expand All @@ -387,6 +387,6 @@ def refresh_access_token(
"grant_type": "refresh_token",
}
response = self._post_token(data=data)
token = pydantic.parse_obj_as(Token, response)
token = TypeAdapter(Token).validate_python(response)
self.access_token = token.access_token
return token
2 changes: 1 addition & 1 deletion drifactorial/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Employee(BaseModel):
social_security_number: Optional[str]
start_date: Optional[date]
state: Optional[str]
terminated_on: Optional[date]
terminated_on: Optional[date] = None


class Shift(BaseModel):
Expand Down
Loading

0 comments on commit f96b8bd

Please sign in to comment.