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
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ The following Squonk2 Data Manager API functions are available: -
- ``DmApi.get_job_definition_schema_version()``
- ``DmApi.get_job_exchange_rates()``
- ``DmApi.get_job_by_version()``
- ``DmApi.get_input_handler()``
- ``DmApi.get_instance()``
- ``DmApi.get_mode()``
- ``DmApi.get_project()``
- ``DmApi.get_project_instances()``
- ``DmApi.get_service_errors()``
Expand Down Expand Up @@ -119,6 +121,7 @@ The following Squonk2 Account Server API functions are available: -
- ``AsApi.disable_asset()``
- ``AsApi.enable_asset()``
- ``AsApi.get_asset()``
- ``AsApi.get_actions()``
- ``AsApi.get_available_assets()``
- ``AsApi.get_available_units()``
- ``AsApi.get_available_products()``
Expand Down
2 changes: 1 addition & 1 deletion src/squonk2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@dataclass
class ApiRv:
"""The return value from most of the the AsApi class public methods.
"""The return value from most of the class public methods.

:param success: True if the call was successful, False otherwise.
:param msg: API request response content
Expand Down
52 changes: 52 additions & 0 deletions src/squonk2/as_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1750,3 +1750,55 @@ def get_default_organisation(
error_message="Failed getting default organisation",
timeout=timeout_s,
)[0]

@classmethod
@synchronized
def get_actions(
cls,
access_token: str,
*,
from_: Optional[date] = None,
until: Optional[date] = None,
merchant_id: int = 0,
product_id: str = "",
unit_id: str = "",
org_id: str = "",
action_format: EventStreamFormat = EventStreamFormat.PROTOCOL_STRING,
timeout_s: int = _READ_TIMEOUT_S,
) -> ApiRv:
"""Gets the Action records (protocol buffers).

:param access_token: A valid AS API access token
:param action_format: The action format
:param from_: An optional start
:param until: An optional end
:param merchant_id: An optional merchant
:param product_id: An optional Product UUID
:param unit_id: An optional Unit UUID
:param org_id: An optional Organisation UUID
:param timeout_s: The underlying request timeout
"""
assert access_token

params: Dict[str, Any] = {"format": action_format.name}
if from_:
params["from"] = str(from_)
if until:
params["until"] = str(until)
if merchant_id:
params["m_id"] = merchant_id
if product_id:
params["product_id"] = product_id
if unit_id:
params["unit_id"] = unit_id
if org_id:
params["org_id"] = org_id

return AsApi.__request(
"GET",
"/action",
access_token=access_token,
params=params,
error_message="Failed getting actions",
timeout=timeout_s,
)[0]
38 changes: 34 additions & 4 deletions src/squonk2/dm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,50 @@ def ping(cls, access_token: str, *, timeout_s: int = _READ_TIMEOUT_S) -> ApiRv:

@classmethod
@synchronized
def get_version(
def get_version(cls, *, timeout_s: int = _READ_TIMEOUT_S) -> ApiRv:
"""Returns the DM-API service version.

:param timeout_s: The underlying request timeout
"""

return DmApi.__request(
"GET",
"/version",
error_message="Failed getting version",
timeout=timeout_s,
)[0]

@classmethod
@synchronized
def get_mode(cls, *, timeout_s: int = _READ_TIMEOUT_S) -> ApiRv:
"""Returns the DM-API service mode.

:param timeout_s: The underlying request timeout
"""

return DmApi.__request(
"GET",
"/mode",
error_message="Failed getting mode",
timeout=timeout_s,
)[0]

@classmethod
@synchronized
def get_input_handler(
cls, access_token: Optional[str] = None, *, timeout_s: int = _READ_TIMEOUT_S
) -> ApiRv:
"""Returns the DM-API service version.
"""Returns the DM-API input handler response.

:param access_token: An optional valid DM API access token (deprecated)
:param timeout_s: The underlying request timeout
"""

return DmApi.__request(
"GET",
"/version",
"/input-handler",
access_token=access_token,
error_message="Failed getting version",
error_message="Failed getting input-handler",
timeout=timeout_s,
)[0]

Expand Down