Skip to content

Commit

Permalink
Update with latest OpenAPI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
moneykitt committed Dec 7, 2023
1 parent 587dc35 commit 748a9cf
Show file tree
Hide file tree
Showing 21 changed files with 85 additions and 106 deletions.
2 changes: 1 addition & 1 deletion moneykit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
""" # noqa: E501


__version__ = "0.1.3"
__version__ = "0.1.4"

# import apis into sdk package
from moneykit.api.access_token_api import AccessTokenApi
Expand Down
63 changes: 39 additions & 24 deletions moneykit/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
from moneykit.exceptions import (
ApiValueError,
ApiException,
BadRequestException,
UnauthorizedException,
ForbiddenException,
NotFoundException,
ServiceException,
)


Expand Down Expand Up @@ -76,7 +81,7 @@ def __init__(
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = "OpenAPI-Generator/0.1.3/python"
self.user_agent = "OpenAPI-Generator/0.1.4/python"
self.client_side_validation = configuration.client_side_validation

def __enter__(self):
Expand Down Expand Up @@ -260,7 +265,7 @@ def call_api(
return response_data

def response_deserialize(
self, response_data: rest.RESTResponse = None, response_types_map=None
self, response_data=None, response_types_map=None
) -> ApiResponse:
"""Deserializes response into an object.
:param response_data: RESTResponse object to be deserialized.
Expand All @@ -279,29 +284,39 @@ def response_deserialize(
str(response_data.status)[0] + "XX", None
)

if not 200 <= response_data.status <= 299:
if response_data.status == 400:
raise BadRequestException(http_resp=response_data)

if response_data.status == 401:
raise UnauthorizedException(http_resp=response_data)

if response_data.status == 403:
raise ForbiddenException(http_resp=response_data)

if response_data.status == 404:
raise NotFoundException(http_resp=response_data)

if 500 <= response_data.status <= 599:
raise ServiceException(http_resp=response_data)
raise ApiException(http_resp=response_data)

# deserialize response data
response_text = None
return_data = None
try:
if response_type == "bytearray":
return_data = response_data.data
elif response_type == "file":
return_data = self.__deserialize_file(response_data)
elif response_type is not None:
match = None
content_type = response_data.getheader("content-type")
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
encoding = match.group(1) if match else "utf-8"
response_text = response_data.data.decode(encoding)
return_data = self.deserialize(response_text, response_type)
finally:
if not 200 <= response_data.status <= 299:
raise ApiException.from_response(
http_resp=response_data,
body=response_text,
data=return_data,
)

if response_type == "bytearray":
return_data = response_data.data
elif response_type is None:
return_data = None
elif response_type == "file":
return_data = self.__deserialize_file(response_data)
else:
match = None
content_type = response_data.getheader("content-type")
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
encoding = match.group(1) if match else "utf-8"
response_text = response_data.data.decode(encoding)
return_data = self.deserialize(response_text, response_type)

return ApiResponse(
status_code=response_data.status,
Expand Down
2 changes: 1 addition & 1 deletion moneykit/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def to_debug_report(self):
"OS: {env}\n"
"Python Version: {pyversion}\n"
"Version of the API: 0.1.0\n"
"SDK Package Version: 0.1.3".format(env=sys.platform, pyversion=sys.version)
"SDK Package Version: 0.1.4".format(env=sys.platform, pyversion=sys.version)
)

def get_host_settings(self):
Expand Down
78 changes: 21 additions & 57 deletions moneykit/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
Do not edit the class manually.
""" # noqa: E501

from typing import Any, Optional, Self


class OpenApiException(Exception):
"""The base exception class for all OpenAPIExceptions"""
Expand Down Expand Up @@ -103,87 +101,53 @@ def __init__(self, msg, path_to_item=None) -> None:


class ApiException(OpenApiException):
def __init__(
self,
status=None,
reason=None,
http_resp=None,
*,
body: Optional[str] = None,
data: Optional[Any] = None,
) -> None:
self.status = status
self.reason = reason
self.body = body
self.data = data
self.headers = None

def __init__(self, status=None, reason=None, http_resp=None) -> None:
if http_resp:
if self.status is None:
self.status = http_resp.status
if self.reason is None:
self.reason = http_resp.reason
if self.body is None:
try:
self.body = http_resp.data.decode("utf-8")
except Exception:
pass
self.status = http_resp.status
self.reason = http_resp.reason
self.body = http_resp.data.decode("utf-8")
self.headers = http_resp.getheaders()

@classmethod
def from_response(
cls,
*,
http_resp,
body: Optional[str],
data: Optional[Any],
) -> Self:
if http_resp.status == 400:
raise BadRequestException(http_resp=http_resp, body=body, data=data)

if http_resp.status == 401:
raise UnauthorizedException(http_resp=http_resp, body=body, data=data)

if http_resp.status == 403:
raise ForbiddenException(http_resp=http_resp, body=body, data=data)

if http_resp.status == 404:
raise NotFoundException(http_resp=http_resp, body=body, data=data)

if 500 <= http_resp.status <= 599:
raise ServiceException(http_resp=http_resp, body=body, data=data)
raise ApiException(http_resp=http_resp, body=body, data=data)
else:
self.status = status
self.reason = reason
self.body = None
self.headers = None

def __str__(self):
"""Custom error messages for exception"""
error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason)
if self.headers:
error_message += "HTTP response headers: {0}\n".format(self.headers)

if self.data or self.body:
error_message += "HTTP response body: {0}\n".format(self.data or self.body)
if self.body:
error_message += "HTTP response body: {0}\n".format(self.body)

return error_message


class BadRequestException(ApiException):
pass
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(BadRequestException, self).__init__(status, reason, http_resp)


class NotFoundException(ApiException):
pass
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(NotFoundException, self).__init__(status, reason, http_resp)


class UnauthorizedException(ApiException):
pass
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(UnauthorizedException, self).__init__(status, reason, http_resp)


class ForbiddenException(ApiException):
pass
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(ForbiddenException, self).__init__(status, reason, http_resp)


class ServiceException(ApiException):
pass
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(ServiceException, self).__init__(status, reason, http_resp)


def render_path(path_to_item):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("api_error.auth.expired_access_token"):
if value not in ("api_error.auth.expired_access_token",):
raise ValueError(
"must be one of enum values ('api_error.auth.expired_access_token')"
)
Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/api_error_auth_unauthorized_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("api_error.auth.unauthorized"):
if value not in ("api_error.auth.unauthorized",):
raise ValueError(
"must be one of enum values ('api_error.auth.unauthorized')"
)
Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/api_error_rate_limit_exceeded_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("api_error.rate_limit_exceeded"):
if value not in ("api_error.rate_limit_exceeded",):
raise ValueError(
"must be one of enum values ('api_error.rate_limit_exceeded')"
)
Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/http_validation_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("api_error.request.validation_failed"):
if value not in ("api_error.request.validation_failed",):
raise ValueError(
"must be one of enum values ('api_error.request.validation_failed')"
)
Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/institution_error_not_found_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("institution_error.not_found"):
if value not in ("institution_error.not_found",):
raise ValueError(
"must be one of enum values ('institution_error.not_found')"
)
Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/link_error_bad_config_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_error.bad_config"):
if value not in ("link_error.bad_config",):
raise ValueError("must be one of enum values ('link_error.bad_config')")
return value

Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/link_error_bad_state_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_error.bad_state"):
if value not in ("link_error.bad_state",):
raise ValueError("must be one of enum values ('link_error.bad_state')")
return value

Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/link_error_deleted_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_error.deleted"):
if value not in ("link_error.deleted",):
raise ValueError("must be one of enum values ('link_error.deleted')")
return value

Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/link_error_forbidden_action_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_error.forbidden_action"):
if value not in ("link_error.forbidden_action",):
raise ValueError(
"must be one of enum values ('link_error.forbidden_action')"
)
Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/link_error_not_found_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_error.not_found"):
if value not in ("link_error.not_found",):
raise ValueError("must be one of enum values ('link_error.not_found')")
return value

Expand Down
2 changes: 1 addition & 1 deletion moneykit/models/link_error_unauthorized_access_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_error.unauthorized_access"):
if value not in ("link_error.unauthorized_access",):
raise ValueError(
"must be one of enum values ('link_error.unauthorized_access')"
)
Expand Down
6 changes: 3 additions & 3 deletions moneykit/models/link_product_refresh_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def webhook_event_validate_enum(cls, value):
if value is None:
return value

if value not in ("link.product_refresh"):
if value not in ("link.product_refresh",):
raise ValueError("must be one of enum values ('link.product_refresh')")
return value

Expand All @@ -78,7 +78,7 @@ def webhook_major_version_validate_enum(cls, value):
if value is None:
return value

if value not in (1):
if value not in (1,):
raise ValueError("must be one of enum values (1)")
return value

Expand All @@ -88,7 +88,7 @@ def webhook_minor_version_validate_enum(cls, value):
if value is None:
return value

if value not in (0):
if value not in (0,):
raise ValueError("must be one of enum values (0)")
return value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_session_error.forbidden_config"):
if value not in ("link_session_error.forbidden_config",):
raise ValueError(
"must be one of enum values ('link_session_error.forbidden_config')"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def error_code_validate_enum(cls, value):
if value is None:
return value

if value not in ("link_session_error.invalid_token_exchange"):
if value not in ("link_session_error.invalid_token_exchange",):
raise ValueError(
"must be one of enum values ('link_session_error.invalid_token_exchange')"
)
Expand Down
6 changes: 3 additions & 3 deletions moneykit/models/link_state_changed_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def webhook_event_validate_enum(cls, value):
if value is None:
return value

if value not in ("link.state_changed"):
if value not in ("link.state_changed",):
raise ValueError("must be one of enum values ('link.state_changed')")
return value

Expand All @@ -76,7 +76,7 @@ def webhook_major_version_validate_enum(cls, value):
if value is None:
return value

if value not in (1):
if value not in (1,):
raise ValueError("must be one of enum values (1)")
return value

Expand All @@ -86,7 +86,7 @@ def webhook_minor_version_validate_enum(cls, value):
if value is None:
return value

if value not in (0):
if value not in (0,):
raise ValueError("must be one of enum values (0)")
return value

Expand Down
Loading

0 comments on commit 748a9cf

Please sign in to comment.