This repository was archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
action attempts implementation initial #4
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e85d8f0
action attempts implementation initial
seveibar 36cf914
add device routes, access code routes
dawnho b396cde
fix reset
dawnho b2b9023
fix lock unlock functions
dawnho 3bae89b
fix typing error
dawnho 38ce033
action attempt polling, fixes for devices lock actions
seveibar efc0f96
access codes fixes
seveibar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from seamapi.types import ( | ||
| AbstractActionAttempts, | ||
| ActionAttemptError, | ||
| ActionAttempt, | ||
| AbstractSeam as Seam, | ||
| ActionAttemptId, | ||
| ) | ||
| import time | ||
| import requests | ||
| from typing import Union | ||
|
|
||
|
|
||
| def to_action_attempt_id(action_attempt: Union[ActionAttemptId, ActionAttempt]) -> str: | ||
| if isinstance(action_attempt, str): | ||
| return action_attempt | ||
| return action_attempt.action_attempt_id | ||
|
|
||
|
|
||
| class ActionAttempts(AbstractActionAttempts): | ||
| seam: Seam | ||
|
|
||
| def __init__(self, seam: Seam): | ||
| self.seam = seam | ||
|
|
||
| def get( | ||
| self, action_attempt: Union[ActionAttemptId, ActionAttempt] | ||
| ) -> ActionAttempt: | ||
| action_attempt_id = to_action_attempt_id(action_attempt) | ||
| res = requests.get( | ||
| f"{self.seam.api_url}/action_attempts/get", | ||
| headers={"Authorization": f"Bearer {self.seam.api_key}"}, | ||
| params={"action_attempt_id": action_attempt_id}, | ||
| ) | ||
| if not res.ok: | ||
| raise Exception(res.text) | ||
| json_aa = res.json()["action_attempt"] | ||
| error = None | ||
| if "error" in json_aa and json_aa["error"] is not None: | ||
| error = ActionAttemptError( | ||
| type=json_aa["error"]["type"], | ||
| message=json_aa["error"]["message"], | ||
| ) | ||
| return ActionAttempt( | ||
| action_attempt_id=json_aa["action_attempt_id"], | ||
| status=json_aa["status"], | ||
| action_type=json_aa["action_type"], | ||
| result=json_aa["result"], | ||
| error=error, | ||
| ) | ||
|
|
||
| def poll_until_ready( | ||
| self, action_attempt: Union[ActionAttemptId, ActionAttempt] | ||
| ) -> ActionAttempt: | ||
| updated_action_attempt = None | ||
| while ( | ||
| updated_action_attempt is None or updated_action_attempt.status == "pending" | ||
| ): | ||
| updated_action_attempt = self.get(action_attempt) | ||
| time.sleep(0.25) | ||
| return updated_action_attempt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,9 +29,7 @@ def get(self, workspace_id: Optional[str] = None) -> Workspace: | |
| is_sandbox=res_json["workspace"]["is_sandbox"], | ||
| ) | ||
|
|
||
| def reset_sandbox( | ||
| self, workspace_id: Optional[str] = None, sandbox_type: Optional[str] = None | ||
| ) -> None: | ||
| def reset_sandbox(self) -> None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. workspaces.reset_sandbox makes it sounds like it applies to multiple workspaces. |
||
| res = requests.post( | ||
| f"{self.seam.api_url}/workspaces/reset_sandbox", | ||
| headers={"Authorization": f"Bearer {self.seam.api_key}"}, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a time out here in the future