Skip to content

Commit 2ef9b50

Browse files
committed
0.1.2
1 parent 801691b commit 2ef9b50

File tree

4 files changed

+121
-21
lines changed

4 files changed

+121
-21
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
# gisapi-sdk-python
22
Python SDK for GISAPI.io
33

4+
# Install
5+
```console
6+
pip install gisapi-sdk
7+
```
8+
49
## Usage
5-
Not currently on PyPi (coming soon).
6-
clone repo into project or download and move gisapi.py file into project.
710
```python
8-
import gisapi
11+
from gisapi import client
12+
13+
api = client.GISAPIClient()
14+
15+
# regular search query. returns 200 raw results data
16+
search_results = api.search_results = client.search_data("Florida")
17+
18+
# category search. returns 200 raw results from given category
19+
category_results = api.category_results = client.get_data_by_category("Education and Research")
920

10-
client = gisapi.GISAPIClient()
21+
# returns dictionary of layer results in a list
22+
layer_details = api.parse_layer_details(search_results)
1123

12-
# regular search query. returns 200 results
13-
search_results = client.search_data("Florida")
24+
# returns just a list of layer urls
25+
layer_urls = api.get_layer_urls(search_results)
1426

15-
# returns 200 results from given category
16-
category_results = client.get_data_by_category("Education and Research")
27+
# returns list of host urls with no duplicates
28+
host_urls = api.get_host_urls(search_results)
1729
```

gisapi/client.py

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import requests
2+
import json
23

34
class 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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='GISAPI-SDK',
5-
version='0.1.07',
5+
version='0.1.2',
66
author='Parker Dinkins',
77
author_email='parkerdinkins@gmail.com',
88
description='GISAPI SDK enabling geospatial data search and discovery',

test.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,42 @@
1+
#from .gisapi import client
2+
#from . import gisapi
13
import gisapi
4+
from gisapi import client
25

3-
client = gisapi.GISAPIClient()
6+
api = client.GISAPIClient()
47

5-
search_results = client.search_data("Florida")
6-
print(search_results)
8+
try:
9+
search_results = api.search_data("Florida")
10+
print(search_results)
11+
except:
12+
print("search_results FAILED")
713

8-
category_results = client.get_data_by_category("Education and Research")
9-
print(search_results)
14+
try:
15+
category_results = api.get_data_by_category("Education and Research")
16+
print(search_results)
17+
except:
18+
print("category_results FAILED")
19+
20+
try:
21+
layer_details = api.parse_layer_details(search_results)
22+
print(layer_details)
23+
except:
24+
print("layer_details FAILED")
25+
26+
try:
27+
xata_details = api.parse_xata_details(search_results)
28+
print(xata_details)
29+
except:
30+
print("xata_details FAILED")
31+
32+
try:
33+
layer_urls = api.get_layer_urls(search_results)
34+
print(layer_urls)
35+
except:
36+
print("layer_urls FAILED")
37+
38+
try:
39+
host_urls = api.get_host_urls(search_results)
40+
print(host_urls)
41+
except:
42+
print("host_urls FAILED")

0 commit comments

Comments
 (0)