11import requests
2+ import json
23
34class GISAPIClient :
45 def __init__ (self ):
@@ -40,13 +41,67 @@ def get_data_by_category(self, category):
4041 """
4142 req_url = f"{ self .base_url } /category/{ category } "
4243 return self ._make_request (req_url )
44+
45+ def parse_layer_details (self , response_data ):
46+ """
47+ Parses layer details from the API response.
48+ :param response_data: The JSON response data.
49+ :return: Parsed layer details.
50+ """
51+ layer_details = []
52+ for item in response_data ["new_layer_details" ]:
53+ detail = {
54+ "category" : item ["CATEGORY" ],
55+ "crs" : item ["CRS" ],
56+ "url" : item ["URL" ],
57+ "layer" : item ["LAYER" ],
58+ "type" : item ["TYPE" ],
59+ "host" : item ["HOSTURL" ],
60+ #"extent": json.loads(item["EXTENT"].replace("'", "\"")) # Safely parse the string
61+ }
62+ layer_details .append (detail )
63+ return layer_details
4364
44- def get_data_by_id (self , record_id ):
65+ def parse_xata_details (self , response_data ):
66+ """
67+ Parses xata details from the API response.
68+ :param response_data: The JSON response data.
69+ :return: Parsed xata details.
70+ """
71+ xata_details = []
72+ for item in response_data ["new_layer_details" ]:
73+ xata = item .get ("xata" , {})
74+ xata_detail = {
75+ "createdAt" : xata .get ("createdAt" ),
76+ "updatedAt" : xata .get ("updatedAt" ),
77+ "score" : xata .get ("score" )
78+ }
79+ xata_details .append (xata_detail )
80+ return xata_details
81+
82+ def get_layer_urls (self , response_data ):
83+ """
84+ Extracts and returns all the layer URLs from the API response.
85+ :param response_data: The JSON response data.
86+ :return: List of layer URLs.
87+ """
88+ urls = []
89+ for item in response_data .get ("new_layer_details" , []):
90+ url = item .get ("URL" )
91+ if url :
92+ urls .append (url )
93+ return urls
94+
95+ def get_host_urls (self , response_data ):
4596 """
46- NOT YET IMPLEMENTED
47- Retrieves data for a specific record ID.
48- :param record_id: The ID of the record to retrieve.
49- :return: Data for the specified record.
97+ Extracts and returns all the Host URLs from the API response.
98+ :param response_data: The JSON response data.
99+ :return: List of layer URLs.
50100 """
51- req_url = f"{ self .base_url } /data/record/{ record_id } "
52- return self ._make_request (req_url )
101+ urls = []
102+ for item in response_data .get ("new_layer_details" , []):
103+ url = item .get ("HOSTURL" )
104+ if url :
105+ urls .append (url )
106+ urls = list (set (urls ))
107+ return urls
0 commit comments