Skip to content

Create base class for models and move here utility functions #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fingerprint_pro_server_api_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# import ApiClient
from fingerprint_pro_server_api_sdk.api_client import ApiClient
from fingerprint_pro_server_api_sdk.configuration import Configuration
# import BaseModel
from fingerprint_pro_server_api_sdk.base_model import BaseModel
# import models into sdk package
from fingerprint_pro_server_api_sdk.models.asn import ASN
from fingerprint_pro_server_api_sdk.models.botd_detection_result import BotdDetectionResult
Expand Down
56 changes: 56 additions & 0 deletions fingerprint_pro_server_api_sdk/base_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import pprint
from typing import Union, Dict


class BaseModel:
"""Base class for all models with utility methods."""

swagger_types: Dict[str, str] = {}
attribute_map: Dict[str, str] = {}

def to_dict(self) -> Dict[str, Union[list, dict]]:
"""Returns the model properties as a dict"""
result = {}

for attr, _ in self.swagger_types.items():
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, Dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
elif value is None:
continue
else:
result[attr] = value
if issubclass(type(self), Dict):
for key, value in self.items():
result[key] = value

return result

def to_str(self) -> str:
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self) -> str:
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other) -> bool:
"""Returns true if both objects are equal"""
if not isinstance(other, type(self)):
return False
return self.to_dict() == other.to_dict()

def __ne__(self, other) -> bool:
"""Returns true if both objects are not equal"""
return not self.__eq__(other)
55 changes: 3 additions & 52 deletions fingerprint_pro_server_api_sdk/models/asn.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

import pprint
import re # noqa: F401
from fingerprint_pro_server_api_sdk.base_model import BaseModel

class ASN(object):

class ASN(BaseModel):
"""NOTE: This class is auto generated by the swagger code generator program.

Do not edit the class manually.
Expand Down Expand Up @@ -115,53 +116,3 @@ def name(self, name):

self._name = name

def to_dict(self):
"""Returns the model properties as a dict"""
result = {}

for attr, _ in self.swagger_types.items():
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
elif value is None:
continue
else:
result[attr] = value
if issubclass(ASN, dict):
for key, value in self.items():
result[key] = value

return result

def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, ASN):
return False

return self.to_dict() == other.to_dict()

def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, ASN):
return True

return self.to_dict() != other.to_dict()
55 changes: 3 additions & 52 deletions fingerprint_pro_server_api_sdk/models/botd_detection_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

import pprint
import re # noqa: F401
from fingerprint_pro_server_api_sdk.base_model import BaseModel

class BotdDetectionResult(object):

class BotdDetectionResult(BaseModel):
"""
Stores bot detection result

Expand Down Expand Up @@ -99,53 +100,3 @@ def type(self, type):

self._type = type

def to_dict(self):
"""Returns the model properties as a dict"""
result = {}

for attr, _ in self.swagger_types.items():
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
elif value is None:
continue
else:
result[attr] = value
if issubclass(BotdDetectionResult, dict):
for key, value in self.items():
result[key] = value

return result

def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, BotdDetectionResult):
return False

return self.to_dict() == other.to_dict()

def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, BotdDetectionResult):
return True

return self.to_dict() != other.to_dict()
55 changes: 3 additions & 52 deletions fingerprint_pro_server_api_sdk/models/botd_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

import pprint
import re # noqa: F401
from fingerprint_pro_server_api_sdk.base_model import BaseModel

class BotdResult(object):

class BotdResult(BaseModel):
"""
Contains all the information from Bot Detection product

Expand Down Expand Up @@ -232,53 +233,3 @@ def bot(self, bot):

self._bot = bot

def to_dict(self):
"""Returns the model properties as a dict"""
result = {}

for attr, _ in self.swagger_types.items():
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
elif value is None:
continue
else:
result[attr] = value
if issubclass(BotdResult, dict):
for key, value in self.items():
result[key] = value

return result

def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, BotdResult):
return False

return self.to_dict() == other.to_dict()

def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, BotdResult):
return True

return self.to_dict() != other.to_dict()
55 changes: 3 additions & 52 deletions fingerprint_pro_server_api_sdk/models/browser_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

import pprint
import re # noqa: F401
from fingerprint_pro_server_api_sdk.base_model import BaseModel

class BrowserDetails(object):

class BrowserDetails(BaseModel):
"""NOTE: This class is auto generated by the swagger code generator program.

Do not edit the class manually.
Expand Down Expand Up @@ -250,53 +251,3 @@ def bot_probability(self, bot_probability):

self._bot_probability = bot_probability

def to_dict(self):
"""Returns the model properties as a dict"""
result = {}

for attr, _ in self.swagger_types.items():
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
elif value is None:
continue
else:
result[attr] = value
if issubclass(BrowserDetails, dict):
for key, value in self.items():
result[key] = value

return result

def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, BrowserDetails):
return False

return self.to_dict() == other.to_dict()

def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, BrowserDetails):
return True

return self.to_dict() != other.to_dict()
Loading
Loading