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

Upgrade users.current to v2 #131

Merged
merged 2 commits into from
Sep 12, 2024
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ Alternatively, if you have the [`pip`](https://pip.pypa.io/) package installed,
pip3 install axiom-py
```

Create an API token with the permissions you need in the
[Axiom settings](https://cloud.axiom.co/profile) and export it as
`AXIOM_TOKEN`.
If you use the [Axiom CLI](https://github.com/axiomhq/cli), run `eval $(axiom config export -f)` to configure your environment variables.

Otherwise create a personal token in [the Axiom settings](https://cloud.axiom.co/profile) and export it as `AXIOM_TOKEN`. Set `AXIOM_ORG_ID` to the organization ID from the settings page of the organization you want to access.

You can also configure the client using options passed to the client constructor:

```py
import axiom_py

client = axiom_py.Client("<api token>")
client = axiom_py.Client("<api token>", "<org id>")
```

Create and use a client like this:
Expand Down
3 changes: 3 additions & 0 deletions examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ def main():
client = Client()
dataset_name = "my-dataset"

# Get current user
print(client.users.current())

# List datasets
res = client.datasets.get_list()
for dataset in res:
Expand Down
12 changes: 9 additions & 3 deletions src/axiom_py/users.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from typing import List
from .util import Util
from dataclasses import dataclass
from requests import Session


@dataclass
class Role:
id: str
name: str


@dataclass
class User:
"""An authenticated axiom user."""

id: str
name: str
emails: List[str]
email: str
role: Role


class UsersClient:
Expand All @@ -25,6 +31,6 @@ def current(self) -> User:

See https://axiom.co/docs/restapi/endpoints/getCurrentUser
"""
res = self.session.get("/v1/user")
res = self.session.get("/v2/user")
user = Util.from_dict(User, res.json())
return user