Skip to content

Commit

Permalink
version: 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
saleweaver committed Aug 11, 2024
1 parent 0b68468 commit ff671eb
Show file tree
Hide file tree
Showing 40 changed files with 5,610 additions and 235 deletions.
31 changes: 27 additions & 4 deletions code_generator/client_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OpenAPIClientGenerator:
from moloni.base.client import MoloniBaseClient
from moloni.base.helpers import endpoint, fill_query_params, validate_data
from moloni.base import ApiResponse
class ApiRequestModel(BaseModel):
Expand Down Expand Up @@ -202,16 +202,39 @@ def generate_pydantic_model(
model_code += "\n"

model_code += "\n"
model_code += f"""
def request(self):
model_code += f'''
def request(self) -> ApiResponse:
"""
request(self) -> ApiResponse
Make an API request using the initialized client.
This method checks if the `_api_client` attribute is set (i.e., if the client has been initialized via the `connect` method).
If the client is initialized, it will make an API request using the provided method name and the model's data,
excluding the `_api_client` attribute itself from the request payload. If the client is not initialized, it will raise a `ValueError`.
Returns:
The response from the API.
Raises:
ValueError: If the client is not initialized via the `connect` method.
Example:
# Assuming you have a model instance `request_model` and an API client `api_client`
with request_model.connect(auth_config=auth_config) as api:
response = api.request()
# The above example assumes that the `connect` method has been used to initialize the client.
# The request method then sends the model's data to the API and returns the API's response.
"""
if hasattr(self, "_api_client"):
response = self._api_client.{method_name}(
self.model_dump(exclude={{"_api_client"}}, exclude_unset=True)
)
return response
else:
raise ValueError("Client not initialized. Use the 'connect' method.")
"""
'''

return model_code.strip()

Expand Down
126 changes: 121 additions & 5 deletions moloni/api/bankaccounts_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from moloni.base.client import MoloniBaseClient
from moloni.base.helpers import endpoint, fill_query_params, validate_data
from moloni.base import ApiResponse


class ApiRequestModel(BaseModel):
Expand All @@ -23,7 +24,30 @@ class BankaccountsCountModifiedSinceModel(ApiRequestModel):
company_id: Union[str, int]
lastmodified: Optional[str] = None

def request(self):
def request(self) -> ApiResponse:
"""
request(self) -> ApiResponse
Make an API request using the initialized client.
This method checks if the `_api_client` attribute is set (i.e., if the client has been initialized via the `connect` method).
If the client is initialized, it will make an API request using the provided method name and the model's data,
excluding the `_api_client` attribute itself from the request payload. If the client is not initialized, it will raise a `ValueError`.
Returns:
The response from the API.
Raises:
ValueError: If the client is not initialized via the `connect` method.
Example:
# Assuming you have a model instance `request_model` and an API client `api_client`
with request_model.connect(auth_config=auth_config) as api:
response = api.request()
# The above example assumes that the `connect` method has been used to initialize the client.
# The request method then sends the model's data to the API and returns the API's response.
"""
if hasattr(self, "_api_client"):
response = self._api_client.count_modified_since(
self.model_dump(exclude={"_api_client"}, exclude_unset=True)
Expand All @@ -37,7 +61,30 @@ class BankaccountsDeleteModel(ApiRequestModel):
company_id: Union[str, int]
bank_account_id: Optional[Union[str, int]] = None

def request(self):
def request(self) -> ApiResponse:
"""
request(self) -> ApiResponse
Make an API request using the initialized client.
This method checks if the `_api_client` attribute is set (i.e., if the client has been initialized via the `connect` method).
If the client is initialized, it will make an API request using the provided method name and the model's data,
excluding the `_api_client` attribute itself from the request payload. If the client is not initialized, it will raise a `ValueError`.
Returns:
The response from the API.
Raises:
ValueError: If the client is not initialized via the `connect` method.
Example:
# Assuming you have a model instance `request_model` and an API client `api_client`
with request_model.connect(auth_config=auth_config) as api:
response = api.request()
# The above example assumes that the `connect` method has been used to initialize the client.
# The request method then sends the model's data to the API and returns the API's response.
"""
if hasattr(self, "_api_client"):
response = self._api_client.delete(
self.model_dump(exclude={"_api_client"}, exclude_unset=True)
Expand All @@ -50,7 +97,30 @@ def request(self):
class BankaccountsGetAllModel(ApiRequestModel):
company_id: Union[str, int]

def request(self):
def request(self) -> ApiResponse:
"""
request(self) -> ApiResponse
Make an API request using the initialized client.
This method checks if the `_api_client` attribute is set (i.e., if the client has been initialized via the `connect` method).
If the client is initialized, it will make an API request using the provided method name and the model's data,
excluding the `_api_client` attribute itself from the request payload. If the client is not initialized, it will raise a `ValueError`.
Returns:
The response from the API.
Raises:
ValueError: If the client is not initialized via the `connect` method.
Example:
# Assuming you have a model instance `request_model` and an API client `api_client`
with request_model.connect(auth_config=auth_config) as api:
response = api.request()
# The above example assumes that the `connect` method has been used to initialize the client.
# The request method then sends the model's data to the API and returns the API's response.
"""
if hasattr(self, "_api_client"):
response = self._api_client.get_all(
self.model_dump(exclude={"_api_client"}, exclude_unset=True)
Expand All @@ -66,7 +136,30 @@ class BankaccountsInsertModel(ApiRequestModel):
order: Optional[str] = None
value: Optional[str] = None

def request(self):
def request(self) -> ApiResponse:
"""
request(self) -> ApiResponse
Make an API request using the initialized client.
This method checks if the `_api_client` attribute is set (i.e., if the client has been initialized via the `connect` method).
If the client is initialized, it will make an API request using the provided method name and the model's data,
excluding the `_api_client` attribute itself from the request payload. If the client is not initialized, it will raise a `ValueError`.
Returns:
The response from the API.
Raises:
ValueError: If the client is not initialized via the `connect` method.
Example:
# Assuming you have a model instance `request_model` and an API client `api_client`
with request_model.connect(auth_config=auth_config) as api:
response = api.request()
# The above example assumes that the `connect` method has been used to initialize the client.
# The request method then sends the model's data to the API and returns the API's response.
"""
if hasattr(self, "_api_client"):
response = self._api_client.insert(
self.model_dump(exclude={"_api_client"}, exclude_unset=True)
Expand All @@ -83,7 +176,30 @@ class BankaccountsUpdateModel(ApiRequestModel):
order: Optional[str] = None
value: Optional[str] = None

def request(self):
def request(self) -> ApiResponse:
"""
request(self) -> ApiResponse
Make an API request using the initialized client.
This method checks if the `_api_client` attribute is set (i.e., if the client has been initialized via the `connect` method).
If the client is initialized, it will make an API request using the provided method name and the model's data,
excluding the `_api_client` attribute itself from the request payload. If the client is not initialized, it will raise a `ValueError`.
Returns:
The response from the API.
Raises:
ValueError: If the client is not initialized via the `connect` method.
Example:
# Assuming you have a model instance `request_model` and an API client `api_client`
with request_model.connect(auth_config=auth_config) as api:
response = api.request()
# The above example assumes that the `connect` method has been used to initialize the client.
# The request method then sends the model's data to the API and returns the API's response.
"""
if hasattr(self, "_api_client"):
response = self._api_client.update(
self.model_dump(exclude={"_api_client"}, exclude_unset=True)
Expand Down
Loading

0 comments on commit ff671eb

Please sign in to comment.