Skip to content

Commit

Permalink
Merge 54b0870 into 7160ce0
Browse files Browse the repository at this point in the history
  • Loading branch information
myslak71 committed Nov 11, 2019
2 parents 7160ce0 + 54b0870 commit 1dd8cd5
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 22 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 myslak71

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
[tool.black]
exclude = 'venv'
exclude = "venv"

[tool.isort]
include_trailing_comma = "True"
known_first_party = "vater"
line_length = 90
multi_line_output = 3
skip = "venv"
8 changes: 0 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@ exclude = .git,__pycache__,old,build,dist,venv
ignore=E203,D106, D202
max-line-length=90
max-complexity=10

[isort]
include_trailing_comma=True
known_first_party=vater
line_length=90
multi_line_output=3
skip=venv

3 changes: 2 additions & 1 deletion src/vater/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Optional

# Following code mapping comes from API docs
ERROR_CODE_MAPPING = {
"WL-100": "Unexpected server error.",
"WL-101": "Date cannot be empty.",
Expand Down Expand Up @@ -78,7 +79,7 @@ def __str__(self) -> str:
class ValidationError(ClientError):
"""Raised during parameter validation."""

def __init__(self, param, msg):
def __init__(self, param, msg) -> None:
"""Initialize the instance."""
self.param = param
self.msg = msg
Expand Down
6 changes: 3 additions & 3 deletions src/vater/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Schemas and models module."""
import datetime
from dataclasses import dataclass
from typing import Dict, List, Optional
from typing import Any, Dict, List, Optional

from marshmallow import Schema, fields, post_load

Expand All @@ -27,7 +27,7 @@ class CompanySchema(Schema):
pesel = fields.String(allow_none=True, required=True)

@post_load
def make_company(self, data: Dict[str, str], **kwargs) -> Company:
def make_company(self, data: Dict[str, str], **kwargs: Any) -> Company:
"""Create a company instance."""
return Company(**data)

Expand Down Expand Up @@ -95,6 +95,6 @@ class SubjectSchema(Schema):
)

@post_load
def make_subject(self, data: dict, **kwargs) -> Subject:
def make_subject(self, data: dict, **kwargs: Any) -> Subject:
"""Create a subject instance."""
return Subject(**data)
14 changes: 8 additions & 6 deletions src/vater/request_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module contains logic for different API request types."""
import datetime
from typing import List, Tuple, Union
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Tuple, Union

import requests
from requests import Response
Expand All @@ -14,12 +15,12 @@
from vater.models import Subject, SubjectSchema


class RequestType:
class RequestType(ABC):
"""Base class for all request types."""

def __init__(self, url_pattern: str, *args, validators=None, **kwargs) -> None:
"""Initialize instance parameters."""
self.params = None
self.params: Dict[str, Any] = {}
self.url_pattern = url_pattern
self.validators = {} if validators is None else validators
self.validated_params: dict = {}
Expand All @@ -37,10 +38,10 @@ def _get_url(self) -> None:

self.url = self.client.base_url + url # type: ignore

def register_params(self, **params):
def register_params(self, **kwargs: Any) -> None:
"""Register parameters to the instance."""
self.client = params.pop("client")
self.params = params
self.client = kwargs.pop("client")
self.params = kwargs

if self.params["date"] is None: # type: ignore
self.params["date"] = datetime.date.today() # type: ignore
Expand All @@ -66,6 +67,7 @@ def send_request(self) -> Response:

return response

@abstractmethod
def result(self):
"""Return request result."""

Expand Down
1 change: 0 additions & 1 deletion src/vater/utils.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/vater/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def nips_validator(values_iter: Iterable[str]) -> Generator[str, None, None]:
return (nip_validator(value) for value in values_iter)


def regon_validator(value: str):
def regon_validator(value: str) -> str:
"""Check if a given value is valid regon number."""
valid_len = (9, 14)
weights: Dict[int, tuple] = {
Expand Down Expand Up @@ -73,7 +73,7 @@ def accounts_validator(values_iter: Iterable[str]) -> Generator[str, None, None]
return (account_validator(value) for value in values_iter)


def date_validator(value: Union[datetime.date, str]):
def date_validator(value: Union[datetime.date, str]) -> str:
"""Check if a given value may be evaluated to `YYYY-MM-DD` date format."""

reg = re.compile(r"([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))$")
Expand Down

0 comments on commit 1dd8cd5

Please sign in to comment.