Coverage for fingerprint_server_sdk / models / geolocation.py: 70%
47 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-11 18:41 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-11 18:41 +0000
1"""
2Server API
3Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios.
4Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device.
6The version of the OpenAPI document: 4
7Contact: support@fingerprint.com
8Generated by OpenAPI Generator (https://openapi-generator.tech)
10Do not edit the class manually.
11""" # noqa: E501
13from __future__ import annotations
15import json
16import pprint
17import re # noqa: F401
18from typing import Annotated, Any, ClassVar, Optional, Union
20from pydantic import BaseModel, ConfigDict, Field, StrictStr
21from typing_extensions import Self
23from fingerprint_server_sdk.models.geolocation_subdivisions_inner import (
24 GeolocationSubdivisionsInner,
25)
28class Geolocation(BaseModel):
29 """
30 Geolocation
31 """
33 accuracy_radius: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(
34 default=None,
35 description='The IP address is likely to be within this radius (in km) of the specified location.',
36 )
37 latitude: Optional[
38 Union[
39 Annotated[float, Field(le=90, strict=True, ge=-90)],
40 Annotated[int, Field(le=90, strict=True, ge=-90)],
41 ]
42 ] = None
43 longitude: Optional[
44 Union[
45 Annotated[float, Field(le=180, strict=True, ge=-180)],
46 Annotated[int, Field(le=180, strict=True, ge=-180)],
47 ]
48 ] = None
49 postal_code: Optional[StrictStr] = None
50 timezone: Optional[StrictStr] = None
51 city_name: Optional[StrictStr] = None
52 country_code: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=2)]] = None
53 country_name: Optional[StrictStr] = None
54 continent_code: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=2)]] = None
55 continent_name: Optional[StrictStr] = None
56 subdivisions: Optional[list[GeolocationSubdivisionsInner]] = None
57 __properties: ClassVar[list[str]] = [
58 'accuracy_radius',
59 'latitude',
60 'longitude',
61 'postal_code',
62 'timezone',
63 'city_name',
64 'country_code',
65 'country_name',
66 'continent_code',
67 'continent_name',
68 'subdivisions',
69 ]
71 model_config = ConfigDict(
72 populate_by_name=True,
73 validate_assignment=True,
74 protected_namespaces=(),
75 )
77 def to_str(self) -> str:
78 """Returns the string representation of the model using alias"""
79 return pprint.pformat(self.model_dump(by_alias=True))
81 def to_json(self) -> str:
82 """Returns the JSON representation of the model using alias"""
83 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
84 return json.dumps(self.to_dict())
86 @classmethod
87 def from_json(cls, json_str: str) -> Optional[Self]:
88 """Create an instance of Geolocation from a JSON string"""
89 return cls.from_dict(json.loads(json_str))
91 def to_dict(self) -> dict[str, Any]:
92 """Return the dictionary representation of the model using alias.
94 This has the following differences from calling pydantic's
95 `self.model_dump(by_alias=True)`:
97 * `None` is only added to the output dict for nullable fields that
98 were set at model initialization. Other fields with value `None`
99 are ignored.
100 """
101 excluded_fields: set[str] = set([])
103 _dict = self.model_dump(
104 by_alias=True,
105 exclude=excluded_fields,
106 exclude_none=True,
107 )
108 # override the default output from pydantic by calling `to_dict()` of each item in subdivisions (list)
109 _items = []
110 if self.subdivisions:
111 for _item_subdivisions in self.subdivisions:
112 if _item_subdivisions:
113 _items.append(_item_subdivisions.to_dict())
114 _dict['subdivisions'] = _items
115 return _dict
117 @classmethod
118 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]:
119 """Create an instance of Geolocation from a dict"""
120 if obj is None:
121 return None
123 if not isinstance(obj, dict):
124 return cls.model_validate(obj)
126 _obj = cls.model_validate(
127 {
128 'accuracy_radius': obj.get('accuracy_radius'),
129 'latitude': obj.get('latitude'),
130 'longitude': obj.get('longitude'),
131 'postal_code': obj.get('postal_code'),
132 'timezone': obj.get('timezone'),
133 'city_name': obj.get('city_name'),
134 'country_code': obj.get('country_code'),
135 'country_name': obj.get('country_name'),
136 'continent_code': obj.get('continent_code'),
137 'continent_name': obj.get('continent_name'),
138 'subdivisions': [
139 GeolocationSubdivisionsInner.from_dict(_item) for _item in obj['subdivisions']
140 ]
141 if obj.get('subdivisions') is not None
142 else None,
143 }
144 )
145 return _obj