Skip to content

Commit ff9428d

Browse files
authored
Implement status check for extension (#6)
1 parent e15188b commit ff9428d

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ options = Options(
2525

2626
client = Client(options)
2727

28-
client.submit(
28+
# Upload extension
29+
operation_id = client.submit(
2930
file_path="/path/to/extension.zip",
3031
notes="Your upload notes"
3132
)
3233

34+
# Check publish status
35+
client.fetch_publish_status(operation_id)
3336
```
3437

3538
## License

edge_addons_api/client.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import requests
77

88
from edge_addons_api.exceptions import UploadException
9-
from edge_addons_api.responses import SubmitResponse
109

1110
logger = logging.getLogger(__name__)
1211

@@ -32,18 +31,28 @@ class Client:
3231
def __init__(self, options: Options):
3332
self.options = options
3433

35-
def submit(self, file_path: str, notes: str) -> SubmitResponse:
34+
def submit(self, file_path: str, notes: str) -> str:
3635
if not path.exists(file_path):
3736
raise FileNotFoundError(f"Unable to locate file at {file_path}")
3837

3938
access_token = self._get_access_token()
4039
operation_id = self._upload(file_path, access_token)
4140
self._check_upload(operation_id, access_token)
42-
publish = self._publish(notes, access_token)
41+
return self._publish(notes, access_token)
4342

44-
return SubmitResponse({}, publish)
43+
def fetch_publish_status(self, operation_id: str) -> dict:
44+
access_token = self._get_access_token()
45+
response = requests.get(
46+
self._publish_status_endpoint(operation_id),
47+
headers={
48+
"Authorization": f"Bearer {access_token}",
49+
},
50+
)
4551

46-
def _publish(self, notes: str, access_token: str) -> dict:
52+
response.raise_for_status()
53+
return response.json()
54+
55+
def _publish(self, notes: str, access_token: str) -> str:
4756
response = requests.post(
4857
self._publish_endpoint(),
4958
data={"notes": notes},
@@ -56,7 +65,7 @@ def _publish(self, notes: str, access_token: str) -> dict:
5665

5766
logger.debug(f"Publish response: {response.content.decode()}")
5867

59-
return response.json()
68+
return response.headers["Location"]
6069

6170
def _upload(self, file_path: str, access_token: str) -> str:
6271

@@ -138,3 +147,6 @@ def _upload_endpoint(self) -> str:
138147

139148
def _status_endpoint(self, operation_id: str) -> str:
140149
return f"{self._upload_endpoint()}/operations/{operation_id}"
150+
151+
def _publish_status_endpoint(self, operation_id: str) -> str:
152+
return f"{self._publish_endpoint()}/operations/{operation_id}"

edge_addons_api/responses.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)