11from __future__ import annotations
2+ from array import array
23from enum import Enum
34from typing import Any , Dict , Optional , TypedDict
45
@@ -20,12 +21,15 @@ class GeocachingApiEnvironment(Enum):
2021
2122class GeocachingSettings :
2223 """Class to hold the Geocaching Api settings"""
23- fetch_trackables : bool
24+ trackable_codes : array ( str )
2425 environment : GeocachingApiEnvironment
2526
26- def __init__ (self , fetch_trackables : bool = False , environment : GeocachingApiEnvironment = GeocachingApiEnvironment . Production ) -> None :
27+ def __init__ (self , environment : GeocachingApiEnvironment = GeocachingApiEnvironment . Production , trackables : array ( str ) = [] ) -> None :
2728 """Initialize settings"""
28- self .fetch_trackables = fetch_trackables
29+ self .trackable_codes = trackables
30+
31+ def set_trackables (self , trackables :array (str )):
32+ self .trackable_codes = trackables
2933
3034@dataclass
3135class GeocachingUser :
@@ -37,6 +41,7 @@ class GeocachingUser:
3741 favorite_points : Optional [int ] = None
3842 souvenir_count : Optional [int ] = None
3943 awarded_favorite_points : Optional [int ] = None
44+ membership_level_id : Optional [int ] = None
4045
4146 def update_from_dict (self , data : Dict [str , Any ]) -> None :
4247 """Update user from the API result"""
@@ -47,6 +52,7 @@ def update_from_dict(self, data: Dict[str, Any]) -> None:
4752 self .favorite_points = try_get_from_dict (data , "favoritePoints" , self .favorite_points )
4853 self .souvenir_count = try_get_from_dict (data , "souvenirCount" , self .souvenir_count )
4954 self .awarded_favorite_points = try_get_from_dict (data , "awardedFavoritePoints" , self .awarded_favorite_points )
55+ self .membership_level_id = try_get_from_dict (data , "membershipLevelId" , self .membership_level_id )
5056
5157@dataclass
5258class GeocachingCoordinate :
@@ -73,6 +79,27 @@ def __init__(self, *, data: Dict[str, Any]) -> GeocachingTrackableJourney:
7379 self .coordinates = None
7480 self .logged_date = try_get_from_dict (data , "loggedDate" , self .logged_date )
7581
82+ @dataclass
83+ class GeocachingTrackableLog :
84+ reference_code : Optional [str ] = None
85+ owner : GeocachingUser = None
86+ text : Optional [str ] = None
87+ log_type : Optional [str ] = None
88+ logged_date : Optional [datetime ] = None
89+
90+ def __init__ (self , * , data : Dict [str , Any ]) -> GeocachingTrackableLog :
91+ self .reference_code = try_get_from_dict (data , 'referenceCode' ,self .reference_code )
92+ if self .owner is None :
93+ self .owner = GeocachingUser ()
94+ if 'owner' in data :
95+ self .owner .update_from_dict (data ['owner' ])
96+ else :
97+ self .owner = None
98+ self .log_type = try_get_from_dict (data ['trackableLogType' ], 'name' ,self .log_type )
99+ self .logged_date = try_get_from_dict (data , 'loggedDate' ,self .logged_date )
100+ self .text = try_get_from_dict (data , 'text' ,self .text )
101+
102+
76103@dataclass
77104class GeocachingTrackable :
78105 """Class to hold the Geocaching trackable information"""
@@ -85,7 +112,10 @@ class GeocachingTrackable:
85112 current_geocache_code : Optional [str ] = None
86113 current_geocache_name : Optional [str ] = None
87114 latest_journey : GeocachingTrackableJourney = None
88- is_missing : bool = False
115+ is_missing : bool = False ,
116+ trackable_type : str = None ,
117+ latest_log : GeocachingTrackableLog = None
118+
89119
90120 def update_from_dict (self , data : Dict [str , Any ]) -> None :
91121 """Update trackable from the API"""
@@ -104,6 +134,10 @@ def update_from_dict(self, data: Dict[str, Any]) -> None:
104134 self .current_geocache_code = try_get_from_dict (data , "currectGeocacheCode" , self .current_geocache_code )
105135 self .current_geocache_name = try_get_from_dict (data , "currentGeocacheName" , self .current_geocache_name )
106136 self .is_missing = try_get_from_dict (data , "isMissing" , self .is_missing )
137+ self .trackable_type = try_get_from_dict (data , "type" , self .trackable_type )
138+ if "trackableLogs" in data and len (data ["trackableLogs" ]) > 0 :
139+ self .latest_log = GeocachingTrackableLog (data = data ["trackableLogs" ][0 ])
140+
107141
108142class GeocachingStatus :
109143 """Class to hold all account status information"""
0 commit comments