Skip to content

Commit 7d015d1

Browse files
author
Andrey Dolgolev
committed
Add resource update and black formating.
1 parent e0584c3 commit 7d015d1

5 files changed

Lines changed: 40 additions & 37 deletions

File tree

bugout/app.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ def create_token(
147147
)
148148

149149
def create_token_restricted(
150-
self,
151-
token: Union[str, uuid.UUID],
152-
timeout: float = REQUESTS_TIMEOUT,
150+
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT,
153151
) -> data.BugoutToken:
154152
self.user.timeout = timeout
155153
return self.user.create_token_restricted(token=token)
@@ -372,6 +370,18 @@ def list_resources(
372370
self.resource.timeout = timeout
373371
return self.resource.list_resources(token=token, params=params)
374372

373+
def update_resource(
374+
self,
375+
token: Union[str, uuid.UUID],
376+
resource_id: Union[str, uuid.UUID],
377+
resource_data: Dict[str, Any],
378+
timeout: float = REQUESTS_TIMEOUT,
379+
) -> data.BugoutResource:
380+
self.resource.timeout = timeout
381+
return self.resource.update_resource(
382+
token=token, resource_id=resource_id, resource_data_update=resource_data
383+
)
384+
375385
def delete_resource(
376386
self,
377387
token: Union[str, uuid.UUID],
@@ -533,9 +543,7 @@ def create_entries_pack(
533543
entries=[data.BugoutJournalEntryRequest(**entry) for entry in entries]
534544
)
535545
return self.journal.create_entries_pack(
536-
token=token,
537-
journal_id=journal_id,
538-
entries=entries_obj,
546+
token=token, journal_id=journal_id, entries=entries_obj,
539547
)
540548

541549
def get_entry(
@@ -681,9 +689,7 @@ def search(
681689

682690
# Public
683691
def check_journal_public(
684-
self,
685-
journal_id: Union[str, uuid.UUID],
686-
timeout: float = REQUESTS_TIMEOUT,
692+
self, journal_id: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT,
687693
) -> bool:
688694
self.journal.timeout = timeout
689695
return self.journal.check_journal_public(journal_id=journal_id)

bugout/exceptions.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ class BugoutResponseException(Exception):
1919
"""
2020

2121
def __init__(
22-
self,
23-
message,
24-
status_code: int,
25-
detail: Optional[Any] = None,
22+
self, message, status_code: int, detail: Optional[Any] = None,
2623
) -> None:
2724
super().__init__(message)
2825
self.status_code = status_code

bugout/group.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def get_group(
4545
return BugoutGroup(**result)
4646

4747
def find_group(
48-
self,
49-
token: Union[str, uuid.UUID],
50-
group_id: Union[str, uuid.UUID],
48+
self, token: Union[str, uuid.UUID], group_id: Union[str, uuid.UUID],
5149
) -> BugoutGroup:
5250
find_group_path = f"groups/find"
5351
query_params = {"group_id": group_id}
@@ -214,9 +212,7 @@ def create_application(
214212
return BugoutApplication(**result)
215213

216214
def get_application(
217-
self,
218-
token: Union[str, uuid.UUID],
219-
application_id: Union[str, uuid.UUID],
215+
self, token: Union[str, uuid.UUID], application_id: Union[str, uuid.UUID],
220216
) -> BugoutApplication:
221217
applications_path = f"applications/{application_id}"
222218
headers = {
@@ -246,9 +242,7 @@ def list_applications(
246242
return BugoutApplications(**result)
247243

248244
def delete_application(
249-
self,
250-
token: Union[str, uuid.UUID],
251-
application_id: Union[str, uuid.UUID],
245+
self, token: Union[str, uuid.UUID], application_id: Union[str, uuid.UUID],
252246
) -> BugoutApplication:
253247
applications_path = f"applications/{application_id}"
254248
headers = {

bugout/journal.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ def delete_journal_scopes(
135135

136136
# Journal module
137137
def create_journal(
138-
self,
139-
token: Union[str, uuid.UUID],
140-
name: str,
141-
journal_type: JournalTypes,
138+
self, token: Union[str, uuid.UUID], name: str, journal_type: JournalTypes,
142139
) -> BugoutJournal:
143140
journal_path = "journals/"
144141
json = {"name": name, "journal_type": journal_type.value}
@@ -305,10 +302,7 @@ def update_entry_content(
305302
"Authorization": f"Bearer {token}",
306303
}
307304
result = self._call(
308-
method=Method.put,
309-
path=entry_id_content_path,
310-
headers=headers,
311-
json=json,
305+
method=Method.put, path=entry_id_content_path, headers=headers, json=json,
312306
)
313307
return BugoutJournalEntryContent(**result)
314308

bugout/resource.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def create_resource(
4545
return BugoutResource(**result)
4646

4747
def get_resource(
48-
self,
49-
token: Union[str, uuid.UUID],
50-
resource_id: Union[str, uuid.UUID],
48+
self, token: Union[str, uuid.UUID], resource_id: Union[str, uuid.UUID],
5149
) -> BugoutResource:
5250
resources_path = f"resources/{resource_id}"
5351
headers = {
@@ -57,9 +55,7 @@ def get_resource(
5755
return BugoutResource(**result)
5856

5957
def list_resources(
60-
self,
61-
token: Union[str, uuid.UUID],
62-
params: Optional[Dict[str, Any]] = None,
58+
self, token: Union[str, uuid.UUID], params: Optional[Dict[str, Any]] = None,
6359
) -> BugoutResources:
6460
resources_path = "resources/"
6561
headers = {
@@ -70,10 +66,26 @@ def list_resources(
7066
)
7167
return BugoutResources(**result)
7268

73-
def delete_resource(
69+
def update_resource(
7470
self,
7571
token: Union[str, uuid.UUID],
7672
resource_id: Union[str, uuid.UUID],
73+
resource_data_update: Dict[str, Any],
74+
) -> BugoutResource:
75+
resources_path = f"resources/{resource_id}"
76+
headers = {
77+
"Authorization": f"Bearer {token}",
78+
}
79+
result = self._call(
80+
method=Method.put,
81+
path=resources_path,
82+
headers=headers,
83+
json=resource_data_update,
84+
)
85+
return BugoutResource(**result)
86+
87+
def delete_resource(
88+
self, token: Union[str, uuid.UUID], resource_id: Union[str, uuid.UUID],
7789
) -> BugoutResource:
7890
resources_path = f"resources/{resource_id}"
7991
headers = {

0 commit comments

Comments
 (0)