diff --git a/hvpy/api_groups/official_clients/get_data_sources.py b/hvpy/api_groups/official_clients/get_data_sources.py new file mode 100644 index 0000000..61d8842 --- /dev/null +++ b/hvpy/api_groups/official_clients/get_data_sources.py @@ -0,0 +1,37 @@ +from typing import Optional + +from hvpy.io import HvpyParameters, OutputType + + +class getDataSourcesInputParameters(HvpyParameters): + """ + Handles the input parameters of the getDataSources API. + + Attributes + ---------- + {Shared} + verbose : bool, optional + Output the hierarchical list of available datasources in a format that is compatible with the JHelioviewer desktop client, default is False. + enable : str, optional + Comma-separated list of observatories to enable. + callback : str, optional + Wrap the response object in a function call of your choosing. + + References + ---------- + * ``__ + {Shared} + """ + + verbose: Optional[bool] = False + enable: Optional[str] = None + callback: Optional[str] = None + + def get_output_type(self) -> OutputType: + """ + Returns the output type of the API call. + """ + if self.callback: + return OutputType.STRING + else: + return OutputType.JSON diff --git a/hvpy/api_groups/official_clients/tests/test_get_data_sources.py b/hvpy/api_groups/official_clients/tests/test_get_data_sources.py new file mode 100644 index 0000000..8754476 --- /dev/null +++ b/hvpy/api_groups/official_clients/tests/test_get_data_sources.py @@ -0,0 +1,17 @@ +from hvpy import getDataSources + + +def test_json_response(): + response = getDataSources() + assert isinstance(response, dict) + + +def test_str_response(): + response = getDataSources(callback="callback") + assert isinstance(response, str) + assert response.startswith("callback(") + + +def test_enable_parameter(): + response = getDataSources(verbose=False, enable="[Yohkoh,STEREO_A,STEREO_B]") + assert isinstance(response, dict) diff --git a/hvpy/facade.py b/hvpy/facade.py index d5a6835..1225a5e 100644 --- a/hvpy/facade.py +++ b/hvpy/facade.py @@ -5,7 +5,15 @@ from hvpy.parameters import * from hvpy.utils import add_shared_docstring -__all__ = ["getJP2Image", "getJP2Header", "getJPXClosestToMidPoint", "getJPX", "getStatus", "getClosestImage"] +__all__ = [ + "getJP2Image", + "getJP2Header", + "getJPXClosestToMidPoint", + "getJPX", + "getStatus", + "getClosestImage", + "getDataSources", +] @add_shared_docstring(getJP2ImageInputParameters) @@ -174,3 +182,30 @@ def getClosestImage( """ params = getClosestImageInputParameters(date=date, sourceId=sourceId, callback=callback) return execute_api_call(input_parameters=params) + + +@add_shared_docstring(getDataSourcesInputParameters) +def getDataSources( + verbose: Optional[bool] = False, + enable: Optional[str] = None, + callback: Optional[str] = None, +) -> Union[bytes, str, Dict[str, Any]]: + """ + Return a hierarchial list of the available datasources. + + Parameters + ---------- + {Insert} + Examples + -------- + >>> from hvpy import getDataSources + >>> getDataSources() + {'SDO': {'HMI': {'continuum': {'sourceId': 18, 'nickname': 'HMI Int', 'layeringOrder': 1, 'start': '2010-12-06 06:53:41', 'end': '2022-07-11 23:59:54', + 'uiLabels': [{'label': 'Observatory', 'name': 'SDO'}, {'label': 'Instrument', 'name': 'HMI'}, {'label': 'Measurement', 'name': 'continuum'}]}, ...} + """ + params = getDataSourcesInputParameters( + verbose=verbose, + enable=enable, + callback=callback, + ) + return execute_api_call(input_parameters=params) diff --git a/hvpy/parameters.py b/hvpy/parameters.py index 2a6cee2..e10de4f 100644 --- a/hvpy/parameters.py +++ b/hvpy/parameters.py @@ -4,6 +4,7 @@ from hvpy.api_groups.jpeg2000.get_jpx_closest_to_mid_point import getJPXClosestToMidPointInputParameters from hvpy.api_groups.jpeg2000.get_status import getStatusInputParameters from hvpy.api_groups.official_clients.get_closest_image import getClosestImageInputParameters +from hvpy.api_groups.official_clients.get_data_sources import getDataSourcesInputParameters __all__ = [ "getJP2ImageInputParameters", @@ -12,4 +13,5 @@ "getJPXInputParameters", "getStatusInputParameters", "getClosestImageInputParameters", + "getDataSourcesInputParameters", ]