Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get my data by name, and fix unsubscribe #32

Merged
merged 2 commits into from
Oct 24, 2024
Merged
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
32 changes: 31 additions & 1 deletion nyx_client/nyx_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -517,6 +518,33 @@ def get_data(
for resp in resps
]

def get_my_data_by_name(self, name: str) -> Data:
"""Retrieve your own data based on its unique name.

This only works on data you own

Args:
name: The data unique name (unique per organization).

Returns:
vtermanis marked this conversation as resolved.
Show resolved Hide resolved
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(
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,
Expand Down Expand Up @@ -739,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))
vtermanis marked this conversation as resolved.
Show resolved Hide resolved
self._nyx_delete(f"{NYX_PURCHASES_TRANSACTIONS_ENDPOINT}/{creator}/{data.name}")
Loading