diff --git a/hvpy/api_groups/communications/__init__.py b/hvpy/api_groups/communications/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hvpy/api_groups/communications/get_news_feed.py b/hvpy/api_groups/communications/get_news_feed.py new file mode 100644 index 0000000..f95e28d --- /dev/null +++ b/hvpy/api_groups/communications/get_news_feed.py @@ -0,0 +1,29 @@ +from typing import Optional + +from hvpy.io import HvpyParameters, OutputType + + +class getNewsFeedInputParameters(HvpyParameters): + """ + Handles the input parameters of the ``getNewsFeed`` API. + + Attributes + ---------- + {Shared} + callback + Wrap the response object in a function call of your choosing. + Default is `None` (no wrapping), optional. + + References + ---------- + * ``__ + {Shared} + """ + + callback: Optional[str] = None + + def get_output_type(self) -> OutputType: + """ + Returns the output type of the API call. + """ + return OutputType.STRING diff --git a/hvpy/api_groups/communications/shorten_url.py b/hvpy/api_groups/communications/shorten_url.py new file mode 100644 index 0000000..79366aa --- /dev/null +++ b/hvpy/api_groups/communications/shorten_url.py @@ -0,0 +1,34 @@ +from typing import Optional + +from hvpy.io import HvpyParameters, OutputType + + +class shortenURLInputParameters(HvpyParameters): + """ + Handles the input parameters of the ``shortenURL`` API. + + Attributes + ---------- + {Shared} + queryString + The URL-encoded query string. + callback + Wrap the response object in a function call of your choosing. + Default is `None` (no wrapping), optional. + + References + ---------- + * ``__ + {Shared} + """ + + queryString: str + callback: Optional[str] = None + + def get_output_type(self) -> OutputType: + """ + Returns the output type of the API call. + """ + if self.callback: + return OutputType.STRING + return OutputType.JSON diff --git a/hvpy/api_groups/communications/tests/__init__.py b/hvpy/api_groups/communications/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hvpy/api_groups/communications/tests/test_get_news_feed.py b/hvpy/api_groups/communications/tests/test_get_news_feed.py new file mode 100644 index 0000000..a1084a0 --- /dev/null +++ b/hvpy/api_groups/communications/tests/test_get_news_feed.py @@ -0,0 +1,16 @@ +from hvpy import getNewsFeed +from hvpy.api_groups.communications.get_news_feed import getNewsFeedInputParameters + + +def test_string_response(): + response = getNewsFeed() + assert isinstance(response, str) + + response = getNewsFeed(callback="test") + assert isinstance(response, str) + assert response.startswith("test(") + + +def test_url_response(): + params = getNewsFeedInputParameters() + assert params.url == "https://api.beta.helioviewer.org/v2/getNewsFeed/" diff --git a/hvpy/api_groups/communications/tests/test_shorten_url.py b/hvpy/api_groups/communications/tests/test_shorten_url.py new file mode 100644 index 0000000..9e93d22 --- /dev/null +++ b/hvpy/api_groups/communications/tests/test_shorten_url.py @@ -0,0 +1,23 @@ +from hvpy import shortenURL +from hvpy.api_groups.communications.shorten_url import shortenURLInputParameters + + +def test_string_response(): + response = shortenURL( + queryString="https://api.helioviewer.org/v2/queueMovie/?startTime=2010-03-01T12:12:12Z&endTime=2010-03-04T12:12:12Z" + ) + assert isinstance(response, dict) + + response = shortenURL( + queryString="https://api.helioviewer.org/v2/queueMovie/?startTime=2010-03-01T12:12:12Z&endTime=2010-03-04T12:12:12Z", + callback="test", + ) + assert isinstance(response, str) + assert response.startswith("test(") + + +def test_url_response(): + params = shortenURLInputParameters( + queryString="https://www.google.com", + ) + assert params.url == "https://api.beta.helioviewer.org/v2/shortenURL/" diff --git a/hvpy/facade.py b/hvpy/facade.py index 9161ae4..12d8f35 100644 --- a/hvpy/facade.py +++ b/hvpy/facade.py @@ -19,6 +19,8 @@ "reQueueMovie", "getMovieStatus", "downloadMovie", + "getNewsFeed", + "shortenURL", ] @@ -474,3 +476,49 @@ def downloadMovie( hq=hq, ) return execute_api_call(input_parameters=params) + + +@add_shared_docstring(getNewsFeedInputParameters) +def getNewsFeed( + callback: Optional[str] = None, +) -> Union[bytes, str, Dict[str, Any]]: + """ + Get the XML RSS feed of the official Helioviewer Project Blog. + + Parameters + ---------- + {Insert} + Examples + -------- + >>> from hvpy import getNewsFeed + >>> getNewsFeed() + '...' + """ + params = getNewsFeedInputParameters( + callback=callback, + ) + return execute_api_call(input_parameters=params) + + +@add_shared_docstring(shortenURLInputParameters) +def shortenURL( + queryString: str, + callback: Optional[str] = None, +) -> Union[bytes, str, Dict[str, Any]]: + """ + Shorten a Helioviewer.org URL with the bit.ly URL shortening web service. + + Parameters + ---------- + {Insert} + Examples + -------- + >>> from hvpy import shortenURL + >>> shortenURL(queryString="https://api.helioviewer.org/v2/queueMovie/?startTime=2010-03-01T12:12:12Z&endTime=2010-03-04T12:12:12Z") + {'status_code': ..., 'status_txt': 'OK', 'data': {'long_url': ..., 'url': ...}} + """ + params = shortenURLInputParameters( + queryString=queryString, + callback=callback, + ) + return execute_api_call(input_parameters=params) diff --git a/hvpy/parameters.py b/hvpy/parameters.py index 1c4f3ce..effc17f 100644 --- a/hvpy/parameters.py +++ b/hvpy/parameters.py @@ -1,3 +1,5 @@ +from hvpy.api_groups.communications.get_news_feed import getNewsFeedInputParameters +from hvpy.api_groups.communications.shorten_url import shortenURLInputParameters from hvpy.api_groups.jpeg2000.get_jp2_header import getJP2HeaderInputParameters from hvpy.api_groups.jpeg2000.get_jp2_image import getJP2ImageInputParameters from hvpy.api_groups.jpeg2000.get_jpx import getJPXInputParameters @@ -26,4 +28,6 @@ "reQueueMovieInputParameters", "getMovieStatusInputParameters", "downloadMovieInputParameters", + "getNewsFeedInputParameters", + "shortenURLInputParameters", ]