-
Notifications
You must be signed in to change notification settings - Fork 54
Add simple version of get_queryables
#477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
359b12a
Add simple version of `get_queryables`
jsignell d3c4b63
Use Mixin
jsignell b78d5de
Move Mixin to its own file
jsignell faa0143
Add test for _stac_io is None
jsignell 0c4803e
Just use pystac.STACObject
jsignell 86c34c1
Tidy up
jsignell 65e2133
Update changelog
jsignell 04bc2ff
Merge branch 'main' into queryables
gadomski 9ba1647
Apply suggestions from code review
jsignell 56fc9b6
Lint
jsignell 76bc24d
Merge branch 'main' into queryables
gadomski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from typing import Optional, Dict, Any | ||
|
||
import pystac | ||
|
||
from pystac_client.exceptions import APIError | ||
from pystac_client.conformance import ConformanceClasses | ||
from pystac_client.stac_api_io import StacApiIO | ||
|
||
QUERYABLES_REL = "http://www.opengis.net/def/rel/ogc/1.0/queryables" | ||
QUERYABLES_ENDPOINT = "/queryables" | ||
|
||
|
||
class StacAPIObject(pystac.STACObject): | ||
_stac_io: Optional[StacApiIO] | ||
gadomski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class QueryablesMixin(StacAPIObject): | ||
"""Mixin for adding support for /queryables endpoint""" | ||
|
||
def get_queryables(self) -> Dict[str, Any]: | ||
"""Return all queryables. | ||
|
||
Output is a dictionary that can be used in ``jsonshema.validate`` | ||
|
||
Return: | ||
Dict[str, Any]: Dictionary containing queryable fields | ||
""" | ||
if self._stac_io is None: | ||
raise APIError("API access is not properly configured") | ||
|
||
self._stac_io.assert_conforms_to(ConformanceClasses.FILTER) | ||
url = self._get_queryables_href() | ||
|
||
result = self._stac_io.read_json(url) | ||
if "properties" not in result: | ||
raise APIError( | ||
f"Invalid response from {QUERYABLES_ENDPOINT}: " | ||
"expected 'properties' attribute" | ||
) | ||
|
||
return result | ||
|
||
def _get_queryables_href(self) -> str: | ||
link = self.get_single_link(QUERYABLES_REL) | ||
if link is not None: | ||
url = link.href | ||
else: | ||
# The queryables link should be defined at the root, but if it is not | ||
# try to guess the url | ||
url = f"{self.self_href.rstrip('/')}{QUERYABLES_ENDPOINT}" | ||
return url |
130 changes: 130 additions & 0 deletions
130
tests/cassettes/test_client/TestQueryables.test_get_queryables.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.28.2 | ||
method: GET | ||
uri: https://planetarycomputer.microsoft.com/api/stac/v1 | ||
response: | ||
body: | ||
string: !!binary | | ||
H4sIAHz3NmQC/81cbXPbNhL+KxjfzI0zF0ii5KSJb+4DTb1YPUtWRaW53k3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H4/7fONcH+g9Iywo/sYl2GDg | ||
GW0wcAIXVMAPwp2DiBCcBITAV0AI6ngQOMbb94y3bzmc1JxIMrjfdOIOaibZIYzxJIHANaw/44DO | ||
5+aOufrM8ZPkZszdnAM7nmNpc1jgxowz52aStQ69Trd7q3MCqbDdKx2GKFLSMK/FChZ3x5RG59Hw | ||
xqVj2OmEYJrYbea9UWtiqoNc7utCYQSvp4DAAKmOlqoC7jJprIhbH/U8ams9UguwecmrsYFT5zur | ||
tk/rYyS3BaS99dEhJlfTscvtSHM8lFKOLcPcH3yeOSujoR/4GNbTxG5rdfw2fhiGe8vKKoN5OC7s | ||
8ITwQeP80OJk+E00Cxcoup2b7ZGHLC7oDFyaYqpBoBkpMJX5TuO9ZZw+QVwfd3wMuecF8rbiBJh7 | ||
9sEQhLsi652opnBq5Z6byQChXQ/A19RxXlM3pwwN11bIj0HwE+QejO/JR2hhhr/7BJU7xD7d4ZOP | ||
lNZ47Dbr49UIInzg8Ph5dZIKSiu7fkU0vbk/WPf0kTpzIPUo+mlWEAql1pLVHwuBdxDhqx9wHOKL | ||
Ts9lYcAFTpOCcgX+HK/vsCZ/4uP5fbY/6cF6OPD3WHbe9uHDalc7WGNS4LGUZaHMGTGHjV2N1w19 | ||
u13rT8bEgEWZO92D5NJMod/zePRxILXnlGHzzbqnse7zpCMJrz7MBvSrzwX9vfkc3T8GVZg9Podp | ||
p4aLKWqIotMv57V6loZ3p5LbE+DlCXbzCbHutszE54BJujNNHgezr0AKXvqPv/wP4sZ9NH1QAAA= | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- 'true' | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Content-Encoding: | ||
- gzip | ||
Content-Length: | ||
- '2906' | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Wed, 12 Apr 2023 18:24:59 GMT | ||
Strict-Transport-Security: | ||
- max-age=15724800; includeSubDomains | ||
Vary: | ||
- Accept-Encoding | ||
X-Azure-Ref: | ||
- 0fPc2ZAAAAADutojn4rB+S6IokbBhkP27RVdSMzBFREdFMDUxMAA5MjdhYmZhNi0xOWY2LTRhZjEtYTA5ZC1jOTU5ZDlhMWU2NDQ= | ||
X-Cache: | ||
- CONFIG_NOCACHE | ||
status: | ||
code: 200 | ||
message: OK | ||
- request: | ||
body: null | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.28.2 | ||
method: GET | ||
uri: https://planetarycomputer.microsoft.com/api/stac/v1/queryables | ||
response: | ||
body: | ||
string: '{"$schema":"http://json-schema.org/draft-07/schema#","$id":"https://example.org/queryables","type":"object","title":"","properties":{"id":{"title":"Item | ||
ID","description":"Item identifier","$ref":"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json#/definitions/core/allOf/2/properties/id"}}}' | ||
headers: | ||
Access-Control-Allow-Credentials: | ||
- 'true' | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Content-Length: | ||
- '308' | ||
Content-Type: | ||
- application/schema+json | ||
Date: | ||
- Wed, 12 Apr 2023 18:25:04 GMT | ||
Strict-Transport-Security: | ||
- max-age=15724800; includeSubDomains | ||
X-Azure-Ref: | ||
- 0fPc2ZAAAAAD8HYLLizYsQorHSY/+cLX5RVdSMzBFREdFMDUxMAA5MjdhYmZhNi0xOWY2LTRhZjEtYTA5ZC1jOTU5ZDlhMWU2NDQ= | ||
X-Cache: | ||
- CONFIG_NOCACHE | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.