attime-star-api-python-sdk 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (16) hide show
  1. {attime_star_api_python_sdk-1.1.0/src/attime_star_api_python_sdk.egg-info → attime_star_api_python_sdk-1.2.0}/PKG-INFO +1 -1
  2. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/pyproject.toml +1 -1
  3. attime_star_api_python_sdk-1.2.0/src/attime/star/apis/oxxy001.py +61 -0
  4. attime_star_api_python_sdk-1.2.0/src/attime/star/dtos/oxxy001.py +180 -0
  5. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0/src/attime_star_api_python_sdk.egg-info}/PKG-INFO +1 -1
  6. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime_star_api_python_sdk.egg-info/SOURCES.txt +2 -0
  7. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/LICENSE +0 -0
  8. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/README.md +0 -0
  9. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/setup.cfg +0 -0
  10. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime/star/api.py +0 -0
  11. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime/star/apis/__init__.py +0 -0
  12. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime/star/apis/infocar.py +0 -0
  13. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime/star/dtos/__init__.py +0 -0
  14. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime/star/dtos/infocar.py +0 -0
  15. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime_star_api_python_sdk.egg-info/dependency_links.txt +0 -0
  16. {attime_star_api_python_sdk-1.1.0 → attime_star_api_python_sdk-1.2.0}/src/attime_star_api_python_sdk.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: attime-star-api-python-sdk
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Client HTTP de comunicacao com a API da ATTime Star
5
5
  Author-email: Filipe Coelho <filipe@fmconsult.com.br>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "attime-star-api-python-sdk"
7
- version = "1.1.0"
7
+ version = "1.2.0"
8
8
  description = "Client HTTP de comunicacao com a API da ATTime Star"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -0,0 +1,61 @@
1
+ import logging, jsonpickle
2
+ from http import HTTPMethod
3
+ from fmconsult.utils.url import UrlUtil
4
+ from attime.star.api import ATTimeStarApi
5
+ from attime.star.dtos.oxxy001 import APIOxxy001DTO, TipoItem
6
+
7
+ ALLOWED_TIPO_ITEM = {int(TipoItem.VIDA_VIAGEM), int(TipoItem.AUTOMOVEL)}
8
+
9
+
10
+ class Oxxy001Api(ATTimeStarApi):
11
+
12
+ def insere_item_contrato(self, item: APIOxxy001DTO | dict) -> list[APIOxxy001DTO]:
13
+ logging.info('inserting contract item via ApiOxxy001 InsereItemContrato...')
14
+ try:
15
+ if isinstance(item, APIOxxy001DTO):
16
+ payload = item.to_dict()
17
+ else:
18
+ payload = dict(item)
19
+
20
+ tipo_item = payload.get('tipoItem')
21
+ if isinstance(tipo_item, TipoItem):
22
+ tipo_item = int(tipo_item)
23
+ payload['tipoItem'] = tipo_item
24
+
25
+ if tipo_item not in ALLOWED_TIPO_ITEM:
26
+ raise ValueError(
27
+ f'tipoItem inválido: {tipo_item!r}. Valores aceitos: '
28
+ f'{int(TipoItem.VIDA_VIAGEM)} (vida/viagem) ou {int(TipoItem.AUTOMOVEL)} (automóvel).'
29
+ )
30
+
31
+ url = UrlUtil().make_url(
32
+ self.base_url,
33
+ ['btc', 'ABTP0001', 'ApiOxxy001', 'InsereItemContrato']
34
+ )
35
+ res = self.call_request(
36
+ http_method=HTTPMethod.POST,
37
+ request_url=url,
38
+ payload=payload
39
+ )
40
+ res = jsonpickle.decode(res)
41
+
42
+ if isinstance(res, list):
43
+ return [APIOxxy001DTO.from_dict(row) for row in res]
44
+
45
+ if isinstance(res, dict):
46
+ if 'dados' in res:
47
+ dados = res['dados']
48
+ if isinstance(dados, list):
49
+ return [APIOxxy001DTO.from_dict(row) for row in dados]
50
+ if isinstance(dados, dict):
51
+ return [APIOxxy001DTO.from_dict(dados)]
52
+ raise Exception(res.get('mensagem', 'Resposta inesperada em dados'))
53
+
54
+ if 'codigo' in res:
55
+ raise Exception(res.get('mensagem', 'Erro desconhecido'))
56
+
57
+ return [APIOxxy001DTO.from_dict(res)]
58
+
59
+ raise Exception('Resposta inesperada da API Oxxy001')
60
+ except:
61
+ raise
@@ -0,0 +1,180 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import asdict, dataclass
4
+ from enum import IntEnum
5
+ from typing import Optional
6
+
7
+
8
+ class TipoItem(IntEnum):
9
+ VIDA_VIAGEM = 1
10
+ AUTOMOVEL = 20
11
+
12
+
13
+ @dataclass
14
+ class ValoresCobertura:
15
+ coberturaCodigo: Optional[int] = None
16
+ is_Cobertura: Optional[float] = None
17
+ taxa: Optional[float] = None
18
+ premio: Optional[float] = None
19
+
20
+ def to_dict(self):
21
+ return {k: v for k, v in asdict(self).items() if v is not None}
22
+
23
+ @classmethod
24
+ def from_dict(cls, data: dict | None) -> ValoresCobertura | None:
25
+ if data is None:
26
+ return None
27
+ if isinstance(data, cls):
28
+ return data
29
+ return cls(**{k: data.get(k) for k in cls.__dataclass_fields__})
30
+
31
+
32
+ @dataclass
33
+ class ValoresCoberturaServico:
34
+ servicoCodigo: Optional[int] = None
35
+ servicovalor: Optional[float] = None
36
+ numeroSerieServico: Optional[str] = None
37
+ numeroSorteServico: Optional[str] = None
38
+
39
+ def to_dict(self):
40
+ return {k: v for k, v in asdict(self).items() if v is not None}
41
+
42
+ @classmethod
43
+ def from_dict(cls, data: dict | None) -> ValoresCoberturaServico | None:
44
+ if data is None:
45
+ return None
46
+ if isinstance(data, cls):
47
+ return data
48
+ return cls(**{k: data.get(k) for k in cls.__dataclass_fields__})
49
+
50
+
51
+ @dataclass
52
+ class APIOxxy001DTO:
53
+ tipoItem: int | TipoItem
54
+ numeroContrato: str
55
+ cpf: Optional[str] = None
56
+ nome: Optional[str] = None
57
+ dataNascimento: Optional[str] = None
58
+ sexo: Optional[str] = None
59
+ estadoCivil: Optional[str] = None
60
+ numeroSerie: Optional[str] = None
61
+ numeroSorte: Optional[str] = None
62
+ inicioVigencia: Optional[str] = None
63
+ fimVigencia: Optional[str] = None
64
+ destino: Optional[str] = None
65
+ placa: Optional[str] = None
66
+ chassi: Optional[str] = None
67
+ valoresCoberturas: Optional[list[ValoresCobertura]] = None
68
+ valoresCoberturasServico: Optional[list[ValoresCoberturaServico]] = None
69
+
70
+ def to_dict(self):
71
+ raw = asdict(self)
72
+ result = {}
73
+ for key, value in raw.items():
74
+ if value is None:
75
+ continue
76
+ if isinstance(value, IntEnum):
77
+ result[key] = int(value)
78
+ elif isinstance(value, list):
79
+ result[key] = [
80
+ {k: v for k, v in item.items() if v is not None} if isinstance(item, dict) else item
81
+ for item in value
82
+ ]
83
+ else:
84
+ result[key] = value
85
+ return result
86
+
87
+ @classmethod
88
+ def from_dict(cls, data: dict | APIOxxy001DTO) -> APIOxxy001DTO:
89
+ if isinstance(data, cls):
90
+ return data
91
+ coberturas = data.get('valoresCoberturas')
92
+ servicos = data.get('valoresCoberturasServico')
93
+ return cls(
94
+ tipoItem=data.get('tipoItem'),
95
+ numeroContrato=data.get('numeroContrato'),
96
+ cpf=data.get('cpf'),
97
+ nome=data.get('nome'),
98
+ dataNascimento=data.get('dataNascimento'),
99
+ sexo=data.get('sexo'),
100
+ estadoCivil=data.get('estadoCivil'),
101
+ numeroSerie=data.get('numeroSerie'),
102
+ numeroSorte=data.get('numeroSorte'),
103
+ inicioVigencia=data.get('inicioVigencia'),
104
+ fimVigencia=data.get('fimVigencia'),
105
+ destino=data.get('destino'),
106
+ placa=data.get('placa'),
107
+ chassi=data.get('chassi'),
108
+ valoresCoberturas=[ValoresCobertura.from_dict(i) for i in coberturas] if coberturas else None,
109
+ valoresCoberturasServico=[ValoresCoberturaServico.from_dict(i) for i in servicos] if servicos else None,
110
+ )
111
+
112
+ @classmethod
113
+ def for_vida(
114
+ cls,
115
+ numeroContrato: str,
116
+ cpf: Optional[str] = None,
117
+ nome: Optional[str] = None,
118
+ dataNascimento: Optional[str] = None,
119
+ sexo: Optional[str] = None,
120
+ estadoCivil: Optional[str] = None,
121
+ inicioVigencia: Optional[str] = None,
122
+ fimVigencia: Optional[str] = None,
123
+ destino: Optional[str] = None,
124
+ numeroSerie: Optional[str] = None,
125
+ numeroSorte: Optional[str] = None,
126
+ valoresCoberturas: Optional[list[ValoresCobertura]] = None,
127
+ valoresCoberturasServico: Optional[list[ValoresCoberturaServico]] = None,
128
+ ) -> APIOxxy001DTO:
129
+ return cls(
130
+ tipoItem=TipoItem.VIDA_VIAGEM,
131
+ numeroContrato=numeroContrato,
132
+ cpf=cpf,
133
+ nome=nome,
134
+ dataNascimento=dataNascimento,
135
+ sexo=sexo,
136
+ estadoCivil=estadoCivil,
137
+ inicioVigencia=inicioVigencia,
138
+ fimVigencia=fimVigencia,
139
+ destino=destino,
140
+ numeroSerie=numeroSerie,
141
+ numeroSorte=numeroSorte,
142
+ valoresCoberturas=valoresCoberturas,
143
+ valoresCoberturasServico=valoresCoberturasServico,
144
+ )
145
+
146
+ @classmethod
147
+ def for_automovel(
148
+ cls,
149
+ numeroContrato: str,
150
+ placa: Optional[str] = None,
151
+ chassi: Optional[str] = None,
152
+ cpf: Optional[str] = None,
153
+ nome: Optional[str] = None,
154
+ dataNascimento: Optional[str] = None,
155
+ sexo: Optional[str] = None,
156
+ estadoCivil: Optional[str] = None,
157
+ inicioVigencia: Optional[str] = None,
158
+ fimVigencia: Optional[str] = None,
159
+ numeroSerie: Optional[str] = None,
160
+ numeroSorte: Optional[str] = None,
161
+ valoresCoberturas: Optional[list[ValoresCobertura]] = None,
162
+ valoresCoberturasServico: Optional[list[ValoresCoberturaServico]] = None,
163
+ ) -> APIOxxy001DTO:
164
+ return cls(
165
+ tipoItem=TipoItem.AUTOMOVEL,
166
+ numeroContrato=numeroContrato,
167
+ placa=placa,
168
+ chassi=chassi,
169
+ cpf=cpf,
170
+ nome=nome,
171
+ dataNascimento=dataNascimento,
172
+ sexo=sexo,
173
+ estadoCivil=estadoCivil,
174
+ inicioVigencia=inicioVigencia,
175
+ fimVigencia=fimVigencia,
176
+ numeroSerie=numeroSerie,
177
+ numeroSorte=numeroSorte,
178
+ valoresCoberturas=valoresCoberturas,
179
+ valoresCoberturasServico=valoresCoberturasServico,
180
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: attime-star-api-python-sdk
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Client HTTP de comunicacao com a API da ATTime Star
5
5
  Author-email: Filipe Coelho <filipe@fmconsult.com.br>
6
6
  License: MIT License
@@ -4,8 +4,10 @@ pyproject.toml
4
4
  src/attime/star/api.py
5
5
  src/attime/star/apis/__init__.py
6
6
  src/attime/star/apis/infocar.py
7
+ src/attime/star/apis/oxxy001.py
7
8
  src/attime/star/dtos/__init__.py
8
9
  src/attime/star/dtos/infocar.py
10
+ src/attime/star/dtos/oxxy001.py
9
11
  src/attime_star_api_python_sdk.egg-info/PKG-INFO
10
12
  src/attime_star_api_python_sdk.egg-info/SOURCES.txt
11
13
  src/attime_star_api_python_sdk.egg-info/dependency_links.txt