Skip to content

Commit

Permalink
Merge branch 'main' of github.com:seamapi/python-next into update-str…
Browse files Browse the repository at this point in the history
…ucture-and-imports
  • Loading branch information
andrii-balitskyi committed May 21, 2024
2 parents 3c31b65 + 9b051f9 commit a4a29f1
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 17 deletions.
18 changes: 18 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ Using the ``wait_for_action_attempt`` option:
except SeamActionAttemptTimeoutError as e:
print("Door took too long to unlock")
Interacting with Multiple Workspaces
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Some Seam API endpoints interact with multiple workspaces. The ``SeamMultiWorkspace`` client is not bound to a specific workspace and may use those endpoints with a personal access token authentication method.

A Personal Access Token is scoped to a Seam Console user. Obtain one from the Seam Console.

.. code-block:: python
# Pass as an option the constructor
seam = SeamMultiWorkspace(personal_access_token="your-personal-access-token")
# Use the factory method
seam = SeamMultiWorkspace.from_personal_access_token("your-personal-access-token")
# List workspaces authorized for this Personal Access Token
workspaces = seam.workspaces.list()
Advanced Usage
~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "seam"
version = "0.7.0"
version = "0.7.1"
description = "SDK for the Seam API written in Python."
authors = ["Seam Labs, Inc. <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion seam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .options import SeamHttpInvalidOptionsError
from .auth import SeamHttpInvalidTokenError
from .exceptions import (
SeamApiException,
SeamHttpApiError,
SeamActionAttemptError,
SeamActionAttemptFailedError,
SeamActionAttemptTimeoutError,
Expand Down
2 changes: 1 addition & 1 deletion seam/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# HTTP
class SeamApiException(Exception):
class SeamHttpApiError(Exception):
def __init__(
self,
response: Response,
Expand Down
6 changes: 3 additions & 3 deletions seam/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from importlib.metadata import version

from .models import AbstractRequestMixin
from .exceptions import SeamApiException
from .exceptions import SeamHttpApiError


class RequestMixin(AbstractRequestMixin):
Expand All @@ -21,7 +21,7 @@ def make_request(self, method: str, path: str, **kwargs):
Raises
------
SeamApiException: If the response status code is not successful.
SeamHttpApiError: If the response status code is not successful.
"""

url = self._endpoint + path
Expand All @@ -40,7 +40,7 @@ def make_request(self, method: str, path: str, **kwargs):
response = requests.request(method, url, headers=headers, **kwargs)

if response.status_code != 200:
raise SeamApiException(response)
raise SeamHttpApiError(response)

if "application/json" in response.headers["content-type"]:
return response.json()
Expand Down
4 changes: 2 additions & 2 deletions test/access_codes/test_access_codes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from seam import Seam, SeamApiException
from seam import Seam, SeamHttpApiError
import pytest


Expand Down Expand Up @@ -30,7 +30,7 @@ def test_access_codes(seam: Seam):
)
assert access_code.code == "4444"

with pytest.raises(SeamApiException):
with pytest.raises(SeamHttpApiError):
seam.access_codes.create(
device_id=some_device.device_id, name="Duplicate Access Code", code="4444"
)
Expand Down
4 changes: 2 additions & 2 deletions test/connected_accounts/test_connected_accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from seam import Seam, SeamApiException
from seam import Seam, SeamHttpApiError

EMAIL = "[email protected]"

Expand Down Expand Up @@ -26,5 +26,5 @@ def test_connected_accounts(seam: Seam):
# connected_account and email parameters are not provided.
try:
seam.connected_accounts.get()
except SeamApiException as e:
except SeamHttpApiError as e:
assert e.metadata["message"] == "Invalid input"
4 changes: 2 additions & 2 deletions test/devices/test_devices.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from seam import Seam, SeamApiException
from seam import Seam, SeamHttpApiError


def test_devices(seam: Seam):
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_devices(seam: Seam):
try:
seam.devices.get(name="foo")
assert False
except SeamApiException as error:
except SeamHttpApiError as error:
assert error.status_code == 404
assert type(error.request_id) == str
assert error.metadata["type"] == "device_not_found"
Expand Down
4 changes: 2 additions & 2 deletions test/events/test_events.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from seam import Seam, SeamApiException
from seam import Seam, SeamHttpApiError


SINCE = "2021-01-01T00:00:00.000Z"
Expand All @@ -22,5 +22,5 @@ def test_events(seam: Seam):

try:
seam.events.get(event_id=FAKE_UUID)
except SeamApiException as e:
except SeamHttpApiError as e:
assert e.metadata["message"] == "Event not found"
4 changes: 1 addition & 3 deletions test/noise_sensors/noise_thresholds/test_noise_thresholds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import time
from seam import Seam, SeamApiException
import pytest
from seam import Seam


def test_noise_thresholds(seam: Seam):
Expand Down

0 comments on commit a4a29f1

Please sign in to comment.