From 41bb98875a59924d5a6b2a00debb52caf00f4f03 Mon Sep 17 00:00:00 2001 From: andy blair Date: Wed, 23 Oct 2024 20:21:52 +0100 Subject: [PATCH 1/2] feat: add get my data by name --- nyx_client/nyx_client/client.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nyx_client/nyx_client/client.py b/nyx_client/nyx_client/client.py index a2fdccc..bb5c1f3 100644 --- a/nyx_client/nyx_client/client.py +++ b/nyx_client/nyx_client/client.py @@ -517,6 +517,27 @@ def get_data( for resp in resps ] + def get_my_data_by_name(self, name: str) -> Data: + """Retrieve a data based on its unique name. + This only works on data you own + Args: + name: The data unique name. + Returns: + The `Data` instance identified with the provided name. + """ + resp = self._nyx_get(f"{NYX_PRODUCTS_ENDPOINT}/{name}") + return Data( + name=resp["name"], + title=resp["title"], + description=resp["description"], + url=resp["accessURL"], + content_type=resp["contentType"], + creator=resp["creator"], + org=self.org, + categories=resp["categories"], + genre=resp["genre"], + ) + @ensure_setup def create_data( self, From 5ac784b7501ffc34a0799bbbb0d2ec9b056666e6 Mon Sep 17 00:00:00 2001 From: andy blair Date: Thu, 24 Oct 2024 10:39:06 +0100 Subject: [PATCH 2/2] fix: url encode to handle slash in creator --- nyx_client/nyx_client/client.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/nyx_client/nyx_client/client.py b/nyx_client/nyx_client/client.py index bb5c1f3..d99febc 100644 --- a/nyx_client/nyx_client/client.py +++ b/nyx_client/nyx_client/client.py @@ -21,6 +21,7 @@ from collections.abc import Sequence from enum import Enum, unique from typing import Any, Literal +from urllib.parse import quote_plus import requests from requests_toolbelt.multipart.encoder import MultipartEncoder @@ -518,12 +519,18 @@ def get_data( ] def get_my_data_by_name(self, name: str) -> Data: - """Retrieve a data based on its unique name. + """Retrieve your own data based on its unique name. + This only works on data you own + Args: - name: The data unique name. + name: The data unique name (unique per organization). + Returns: - The `Data` instance identified with the provided name. + Your `Data` instance identified with the provided name. + + Raises: + requests.HTTPError: If the API request fails. """ resp = self._nyx_get(f"{NYX_PRODUCTS_ENDPOINT}/{name}") return Data( @@ -760,4 +767,6 @@ def unsubscribe(self, data: Data): Raises: requests.HTTPError: If the API request fails. """ - self._nyx_delete(f"{NYX_PURCHASES_TRANSACTIONS_ENDPOINT}/{data.creator}/{data.name}") + # Creator is expected to be double encoded + creator = quote_plus(quote_plus(data.creator)) + self._nyx_delete(f"{NYX_PURCHASES_TRANSACTIONS_ENDPOINT}/{creator}/{data.name}")