Skip to content

Commit d75841a

Browse files
committed
version 4.0.149
1 parent 32806cf commit d75841a

File tree

9 files changed

+103
-8
lines changed

9 files changed

+103
-8
lines changed

examples.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,46 @@ def main ():
1717
client = FiscalApiClient(settings=settings)
1818

1919

20+
# listar api-keys
21+
# api_response = client.api_keys.get_list(1, 10)
22+
# print(api_response)
23+
24+
25+
# Obtener api-key por id
26+
# api_response = client.api_keys.get_by_id("78145e7d-40d3-4540-b1f8-262adff398a2")
27+
# print(api_response)
28+
29+
30+
# crear api-key
31+
32+
# api_key: ApiKey = ApiKey(
33+
# person_id="7c1d2a85-ae39-44dd-b9f1-54f02b204165",
34+
# description="Api Key de prueba para python"
35+
# )
36+
# api_response = client.api_keys.create(api_key)
37+
# print(api_response)
38+
39+
40+
# actualizar api-key
41+
# api_key: ApiKey = ApiKey(
42+
# id="78145e7d-40d3-4540-b1f8-262adff398a2",
43+
# description="Revocando por no pagar",
44+
# apiKeyStatus=0
45+
# )
46+
# api_response = client.api_keys.update(api_key)
47+
# print(api_response)
48+
49+
50+
# eliminar api-key
51+
# api_response = client.api_keys.delete("78145e7d-40d3-4540-b1f8-262adff398a2")
52+
# print(api_response)
53+
54+
55+
56+
57+
58+
59+
2060
# listar productos
2161
#api_response = client.products.get_list(1, 10)
2262

fiscalapi/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@
3535
SendInvoiceRequest,
3636
InvoiceStatusRequest,
3737
InvoiceStatusResponse,
38+
ApiKey,
3839
)
3940

4041
# Re-exportar servicios
4142
from .services.catalog_service import CatalogService
4243
from .services.invoice_service import InvoiceService
4344
from .services.people_service import PeopleService
4445
from .services.product_service import ProductService
45-
from .services.tax_file_servive import TaxFileService # Asegúrate de que coincida con tu nombre real (tax_file_service o tax_file_servive)
46+
from .services.tax_file_servive import TaxFileService
47+
from .services.api_key_service import ApiKeyService
4648

4749
# Re-exportar la clase FiscalApiClient
4850
# (asumiendo que la definición está en fiscalapi/services/fiscalapi_client.py)
@@ -79,6 +81,7 @@
7981
"SendInvoiceRequest",
8082
"InvoiceStatusRequest",
8183
"InvoiceStatusResponse",
84+
"ApiKey",
8285

8386

8487
# Servicios
@@ -87,6 +90,7 @@
8790
"PeopleService",
8891
"ProductService",
8992
"TaxFileService",
93+
"ApiKeyService"
9094

9195
# Cliente principal
9296
"FiscalApiClient",

fiscalapi/models/fiscalapi_models.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,22 @@ class InvoiceStatusResponse(BaseDto):
347347

348348
model_config = {
349349
"populate_by_name": True
350-
}
350+
}
351+
352+
353+
354+
class ApiKey(BaseDto):
355+
"""Modelo de clave de autenticación en fiscalapi."""
356+
357+
id: Optional[str] = Field(default=None, alias="id", description="El identificador único de la API key.")
358+
environment: Optional[str] = Field(default=None, alias="environment", description="El entorno al que pertenece la API key.")
359+
api_key_value: Optional[str] = Field(default=None, alias="apiKeyValue", description="El API key. Este valor es el que se utiliza para autenticar las solicitudes.")
360+
person_id: Optional[str] = Field(default=None, alias="personId", description="El identificador único de la persona a la que pertenece la API key.")
361+
tenant_id: Optional[str] = Field(default=None, alias="tenantId", description="El identificador único del tenant al que pertenece la API key.")
362+
api_key_status: Optional[int] = Field(default=None, alias="apiKeyStatus", description="El estado de la API key. 0=Revocada, 1=Activa")
363+
description: Optional[str] = Field(default=None, alias="description", description="Nombre o description de la API key.")
364+
365+
model_config = ConfigDict(
366+
populate_by_name=True,
367+
json_encoders={Decimal: str}
368+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from fiscalapi.models.common_models import ApiResponse, PagedList
2+
from fiscalapi.models.fiscalapi_models import ApiKey
3+
from fiscalapi.services.base_service import BaseService
4+
5+
6+
class ApiKeyService(BaseService):
7+
8+
# get paged list of api keys
9+
def get_list(self, page_number: int, page_size: int) -> ApiResponse[PagedList[ApiKey]]:
10+
endpoint = f"apikeys?pageNumber={page_number}&pageSize={page_size}"
11+
return self.send_request("GET", endpoint, PagedList[ApiKey])
12+
13+
# get apikey by id
14+
def get_by_id(self, id: str) -> ApiResponse[ApiKey]:
15+
endpoint = f"apikeys/{id}"
16+
return self.send_request("GET", endpoint, ApiKey)
17+
18+
# create apikey
19+
def create(self, model: ApiKey) -> ApiResponse[ApiKey]:
20+
endpoint = "apikeys"
21+
return self.send_request("POST", endpoint, ApiKey, payload=model)
22+
23+
# update apikey
24+
def update(self, model: ApiKey) -> ApiResponse[ApiKey]:
25+
endpoint = f"apikeys/{model.id}"
26+
return self.send_request("PUT", endpoint, ApiKey, payload=model)
27+
28+
# delete apikey by id
29+
def delete(self, id: str) -> ApiResponse[bool]:
30+
endpoint = f"apikeys/{id}"
31+
return self.send_request("DELETE", endpoint, bool)

fiscalapi/services/fiscalapi_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from fiscalapi.services.people_service import PeopleService
55
from fiscalapi.services.product_service import ProductService
66
from fiscalapi.services.tax_file_servive import TaxFileService
7+
from fiscalapi.services.api_key_service import ApiKeyService
78

89

910

@@ -15,4 +16,5 @@ def __init__(self, settings: FiscalApiSettings):
1516
self.tax_files = TaxFileService(settings)
1617
self.catalogs = CatalogService(settings)
1718
self.invoices = InvoiceService(settings)
19+
self.api_keys = ApiKeyService(settings)
1820
self.settings = settings

fiscalapi/services/people_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def get_list(self, page_number: int, page_size: int) -> ApiResponse[PagedList[Pe
1111
return self.send_request("GET", endpoint, PagedList[Person])
1212

1313
# get person by id
14-
def get_by_id(self, person_id: int) -> ApiResponse[Person]:
14+
def get_by_id(self, person_id: str) -> ApiResponse[Person]:
1515
endpoint = f"people/{person_id}"
1616
return self.send_request("GET", endpoint, Person)
1717

fiscalapi/services/product_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def get_list(self, page_number: int, page_size: int) -> ApiResponse[PagedList[Pr
1111
return self.send_request("GET", endpoint, PagedList[Product])
1212

1313
# get product by id
14-
def get_by_id(self, product_id: int) -> ApiResponse[Product]:
14+
def get_by_id(self, product_id: str) -> ApiResponse[Product]:
1515
endpoint = f"products/{product_id}"
1616
return self.send_request("GET", endpoint, Product)
1717

fiscalapi/services/tax_file_servive.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def get_list(self, page_number: int, page_size: int) -> ApiResponse[PagedList[Ta
1010
return self.send_request("GET", endpoint, PagedList[TaxFile])
1111

1212
# get tax file by id
13-
def get_by_id(self, tax_file_id: int) -> ApiResponse[TaxFile]:
13+
def get_by_id(self, tax_file_id: str) -> ApiResponse[TaxFile]:
1414
endpoint = f"tax-files/{tax_file_id}"
1515
return self.send_request("GET", endpoint, TaxFile)
1616

@@ -28,14 +28,14 @@ def delete(self, tax_file_id: str) -> ApiResponse[bool]:
2828

2929
# get default tax files for a given person)
3030
# obtiene el último par de certificados válidos y vigente de una persona. Es decir sus certificados por defecto.
31-
def get_default_values(self, person_id: int) -> ApiResponse[list[TaxFile]]:
31+
def get_default_values(self, person_id: str) -> ApiResponse[list[TaxFile]]:
3232
endpoint = f"tax-files/{person_id}/default-values"
3333
return self.send_request("GET", endpoint, list[TaxFile])
3434

3535

3636
# get default references for a given person
3737
# obtiene el último par de ids de certificados válidos y vigente de una persona. Es decir sus certificados por defecto (solo los ids)
38-
def get_default_references(self, person_id: int) -> ApiResponse[list[TaxFile]]:
38+
def get_default_references(self, person_id: str) -> ApiResponse[list[TaxFile]]:
3939
endpoint = f"tax-files/{person_id}/default-references"
4040
return self.send_request("GET", endpoint, list[TaxFile])
4141

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from setuptools import setup, find_packages
44

5-
VERSION = "4.0.144"
5+
VERSION = "4.0.145"
66
# Descripción breve basada en el .csproj
77
DESCRIPTION = "Genera facturas CFDI válidas ante el SAT consumiendo el API de https://www.fiscalapi.com"
88

0 commit comments

Comments
 (0)