1+ import requests
2+
3+ class GISAPIClient :
4+ def __init__ (self ):
5+ self .base_url = "https://www.gisapi.io/api/data"
6+
7+ def _make_request (self , url ):
8+ """
9+ Internal method to make HTTP GET requests.
10+ :param url: The full URL to make the request to.
11+ :return: JSON response data.
12+ """
13+ try :
14+ response = requests .get (url )
15+ response .raise_for_status () # Raises an HTTPError if the HTTP request returned an unsuccessful status code
16+ return response .json ()
17+ except requests .exceptions .HTTPError as e :
18+ print (f"HTTP error occurred: { e } " )
19+ except requests .exceptions .ConnectionError as e :
20+ print (f"Connection error occurred: { e } " )
21+ except requests .exceptions .Timeout as e :
22+ print (f"Request timed out: { e } " )
23+ except requests .exceptions .RequestException as e :
24+ print (f"An error occurred during the request: { e } " )
25+
26+ def search_data (self , query ):
27+ """
28+ Searches for data based on the given query.
29+ :param query: The search query.
30+ :return: A list of search results.
31+ """
32+ req_url = f"{ self .base_url } /search/{ query } "
33+ return self ._make_request (req_url )
34+
35+ def get_data_by_category (self , category ):
36+ """
37+ Retrieves data for a specific category.
38+ :param category: The category to search.
39+ :return: Data for the specified category.
40+ """
41+ req_url = f"{ self .base_url } /category/{ category } "
42+ return self ._make_request (req_url )
43+
44+ def get_data_by_id (self , record_id ):
45+ """
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.
50+ """
51+ req_url = f"{ self .base_url } /data/record/{ record_id } "
52+ return self ._make_request (req_url )
0 commit comments