Skip to content

Commit

Permalink
add route to get Isogeo coordinate systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Apr 4, 2018
1 parent becf2e0 commit 45f7162
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
38 changes: 38 additions & 0 deletions isogeo_pysdk/isogeo_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,44 @@ def get_directives(self, token, prot="https"):
# end of method
return req.json()

def get_coordinate_systems(self, token, srs_code=None, prot="https"):
"""Get available coordinate systems in Isogeo API.
:param str token: API auth token
:param str srs_code: code of a specific coordinate system
:param str prot: https [DEFAULT] or http
(use it only for dev and tracking needs).
"""
# checking bearer validity
token = checker.check_bearer_validity(token, self.connect(self.app_id,
self.ct))

# if specific format
if isinstance(srs_code, string_types):
specific_srs = "/{}".format(srs_code)
else:
specific_srs = ""

# search request
head = {"Authorization": "Bearer " + token[0],
"user-agent": self.app_name}

req_url = "{}://v1.{}.isogeo.com/coordinate-systems{}"\
.format(prot,
self.api_url,
specific_srs)

req = requests.get(req_url,
headers=head,
proxies=self.proxies,
verify=self.ssl)

# checking response
checker.check_api_response(req)

# end of method
return req.json()

def get_formats(self, token, format_code=None, prot="https"):
"""Get formats.
Expand Down
16 changes: 16 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ def test_get_formats(self):
self.assertEqual(len(bad_specific_format), 32)
self.assertEqual(bad_specific_format, formats)

def test_get_srs(self):
"""Test coordinate-systmes requests."""
# all Isoego srs
srs = self.isogeo.get_coordinate_systems(self.bearer)
self.assertEqual(len(srs), 4301)
self.assertEqual(len(srs[0]), 3)
# a specific srs
wgs84 = self.isogeo.get_coordinate_systems(self.bearer,
srs_code="4326")
self.assertEqual(len(wgs84), 7)
# if specific srs is bad formatted, so show all srs
bad_specific_srs = self.isogeo.get_coordinate_systems(self.bearer,
srs_code=["4326", ])
self.assertEqual(len(bad_specific_srs), 4301)
self.assertEqual(bad_specific_srs, srs)


# ##############################################################################
# ##### Stand alone program ########
Expand Down

0 comments on commit 45f7162

Please sign in to comment.