Skip to content

Commit d0dac7d

Browse files
Merge pull request #47 from bugout-dev/add-entries-tags-handlers
Add entries tags support.
2 parents 50288f0 + 4447d0a commit d0dac7d

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed

bugout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
__email__ = "engineering@bugout.dev"
99
__license__ = "MIT"
10-
__version__ = "0.2.7"
10+
__version__ = "0.2.8"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,31 @@ def create_tags(
787787
**kwargs,
788788
)
789789

790+
def create_entries_tags(
791+
self,
792+
token: Union[str, uuid.UUID],
793+
journal_id: Union[str, uuid.UUID],
794+
entries_tags: List[Dict[str, Any]],
795+
timeout: float = REQUESTS_TIMEOUT,
796+
auth_type: str = data.AuthType.bearer.name,
797+
**kwargs: Dict[str, Any],
798+
) -> data.BugoutJournalEntries:
799+
self.journal.timeout = timeout
800+
801+
entries_tags_obj = data.BugoutJournalEntriesTagsRequest(
802+
entries=[
803+
data.BugoutJournalEntryTagsRequest(**entry_tags)
804+
for entry_tags in entries_tags
805+
]
806+
)
807+
return self.journal.create_entries_tags(
808+
token=token,
809+
journal_id=journal_id,
810+
entries_tags=entries_tags_obj,
811+
auth_type=data.AuthType[auth_type],
812+
**kwargs,
813+
)
814+
790815
def get_tags(
791816
self,
792817
token: Union[str, uuid.UUID],
@@ -845,6 +870,30 @@ def delete_tag(
845870
**kwargs,
846871
)
847872

873+
def delete_entries_tags(
874+
self,
875+
token: Union[str, uuid.UUID],
876+
journal_id: Union[str, uuid.UUID],
877+
entries_tags: List[Dict[str, Any]],
878+
timeout: float = REQUESTS_TIMEOUT,
879+
auth_type: str = data.AuthType.bearer.name,
880+
**kwargs: Dict[str, Any],
881+
) -> data.BugoutJournalEntries:
882+
self.journal.timeout = timeout
883+
entries_tags_obj = data.BugoutJournalEntriesTagsRequest(
884+
entries=[
885+
data.BugoutJournalEntryTagsRequest(**entry_tags)
886+
for entry_tags in entries_tags
887+
]
888+
)
889+
return self.journal.delete_entries_tags(
890+
token=token,
891+
journal_id=journal_id,
892+
entries_tags=entries_tags_obj,
893+
auth_type=data.AuthType[auth_type],
894+
**kwargs,
895+
)
896+
848897
# Search
849898
def search(
850899
self,

bugout/calls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict
22

3-
import requests
3+
import requests # type: ignore
44

55
from .data import Method
66
from .exceptions import BugoutResponseException, BugoutUnexpectedResponse

bugout/data.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ class BugoutJournalEntryTags(BaseModel):
239239
tags: List[str]
240240

241241

242+
class BugoutJournalEntryTagsRequest(BaseModel):
243+
journal_entry_id: uuid.UUID = Field(alias="entry_id")
244+
tags: List[str]
245+
246+
class Config:
247+
# Required configuration because in Spire we use "journal_entry_id" instead of "entry_id"
248+
# during creation and deletion of new tags for journal entry
249+
allow_population_by_field_name = True
250+
251+
252+
class BugoutJournalEntriesTagsRequest(BaseModel):
253+
entries: List[BugoutJournalEntryTagsRequest] = Field(default_factory=list)
254+
255+
242256
class BugoutSearchResult(BaseModel):
243257
entry_url: str
244258
content_url: str

bugout/journal.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import uuid
22
from enum import Enum
3+
import json
34
from typing import Any, Dict, List, Optional, Union
45

56
from .calls import make_request
@@ -11,6 +12,7 @@
1112
BugoutJournalEntry,
1213
BugoutJournalEntryContent,
1314
BugoutJournalEntryTags,
15+
BugoutJournalEntriesTagsRequest,
1416
BugoutJournalPermissions,
1517
BugoutJournals,
1618
BugoutJournalScopeSpecs,
@@ -464,6 +466,29 @@ def create_tags(
464466
)
465467
return result
466468

469+
def create_entries_tags(
470+
self,
471+
token: Union[str, uuid.UUID],
472+
journal_id: Union[str, uuid.UUID],
473+
entries_tags: BugoutJournalEntriesTagsRequest,
474+
auth_type: AuthType = AuthType.bearer,
475+
**kwargs: Dict[str, Any],
476+
) -> BugoutJournalEntries:
477+
tags_path = f"journals/{journal_id}/bulk_entries_tags"
478+
headers = {
479+
"Authorization": f"{auth_type.value} {token}",
480+
}
481+
json_body = json.loads(entries_tags.json())
482+
if "headers" in kwargs.keys():
483+
headers.update(kwargs["headers"])
484+
result = self._call(
485+
method=Method.post, path=tags_path, headers=headers, json=json_body
486+
)
487+
488+
return BugoutJournalEntries(
489+
entries=[BugoutJournalEntry(**entry) for entry in result]
490+
)
491+
467492
def get_tags(
468493
self,
469494
token: Union[str, uuid.UUID],
@@ -523,6 +548,29 @@ def delete_tag(
523548
)
524549
return BugoutJournalEntryTags(**result)
525550

551+
def delete_entries_tags(
552+
self,
553+
token: Union[str, uuid.UUID],
554+
journal_id: Union[str, uuid.UUID],
555+
entries_tags: BugoutJournalEntriesTagsRequest,
556+
auth_type: AuthType = AuthType.bearer,
557+
**kwargs: Dict[str, Any],
558+
) -> BugoutJournalEntries:
559+
tags_path = f"journals/{journal_id}/bulk_entries_tags"
560+
headers = {
561+
"Authorization": f"{auth_type.value} {token}",
562+
}
563+
json_body = json.loads(entries_tags.json())
564+
if "headers" in kwargs.keys():
565+
headers.update(kwargs["headers"])
566+
result = self._call(
567+
method=Method.delete, path=tags_path, headers=headers, json=json_body
568+
)
569+
570+
return BugoutJournalEntries(
571+
entries=[BugoutJournalEntry(**entry) for entry in result]
572+
)
573+
526574
# Search module
527575
def search(
528576
self,

0 commit comments

Comments
 (0)