Skip to content

Commit

Permalink
Merge pull request #59 from fingerprintjs/INTER-802-base-class-for-mo…
Browse files Browse the repository at this point in the history
…dels

Create base class for models and move here utility functions
  • Loading branch information
ilfa authored Jul 29, 2024
2 parents 8d5a989 + 31bee67 commit 4eefbd6
Show file tree
Hide file tree
Showing 93 changed files with 451 additions and 4,629 deletions.
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

0 comments on commit 4eefbd6

Please sign in to comment.