Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
29 changes: 29 additions & 0 deletions hvpy/api_groups/communications/get_news_feed.py
Original file line number Diff line number Diff line change
@@ -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
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/web_site.html#getnewsfeed>`__
{Shared}
"""

callback: Optional[str] = None

def get_output_type(self) -> OutputType:
"""
Returns the output type of the API call.
"""
return OutputType.STRING
34 changes: 34 additions & 0 deletions hvpy/api_groups/communications/shorten_url.py
Original file line number Diff line number Diff line change
@@ -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
----------
* `<https://api.helioviewer.org/docs/v2/api/api_groups/official_clients.html#shortenurl>`__
{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
Empty file.
16 changes: 16 additions & 0 deletions hvpy/api_groups/communications/tests/test_get_news_feed.py
Original file line number Diff line number Diff line change
@@ -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/"
23 changes: 23 additions & 0 deletions hvpy/api_groups/communications/tests/test_shorten_url.py
Original file line number Diff line number Diff line change
@@ -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/"
48 changes: 48 additions & 0 deletions hvpy/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"reQueueMovie",
"getMovieStatus",
"downloadMovie",
"getNewsFeed",
"shortenURL",
]


Expand Down Expand Up @@ -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()
'<?xml version="1.0" encoding="utf-8"?><feed xmlns="..." >...</summary></entry></feed>'
"""
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)
4 changes: 4 additions & 0 deletions hvpy/parameters.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -26,4 +28,6 @@
"reQueueMovieInputParameters",
"getMovieStatusInputParameters",
"downloadMovieInputParameters",
"getNewsFeedInputParameters",
"shortenURLInputParameters",
]