Download query results data endpoint

pull/687/head
kompotkot 2022-10-27 11:35:35 +00:00
rodzic b2e598e0f8
commit c8f4d4efdc
2 zmienionych plików z 30 dodań i 0 usunięć

Wyświetl plik

@ -10,6 +10,7 @@ from .data import (
MoonstreamQueries,
MoonstreamQuery,
MoonstreamQueryResultUrl,
OutputType,
)
from .exceptions import MoonstreamResponseException, MoonstreamUnexpectedResponse
from .settings import MOONSTREAM_API_URL, MOONSTREAM_REQUEST_TIMEOUT
@ -198,6 +199,30 @@ class Moonstream:
return MoonstreamQueryResultUrl(url=response["url"])
def download_query_results(
self,
url: str,
output_type: OutputType = OutputType.JSON,
timeout: float = MOONSTREAM_REQUEST_TIMEOUT,
**kwargs,
) -> Any:
"""
Fetch results of query from url.
"""
try:
response = requests.request(
Method.GET.value, url=url, timeout=timeout, **kwargs
)
response.raise_for_status()
except Exception as e:
raise Exception(str(e))
output = response
if output_type == OutputType.JSON:
output = response.json()
return output
def delete_query(
self,
token: Union[str, uuid.UUID],

Wyświetl plik

@ -23,6 +23,11 @@ class Method(Enum):
PUT = "put"
class OutputType(Enum):
CSV = "csv"
JSON = "json"
@dataclass(frozen=True)
class MoonstreamQuery:
id: uuid.UUID