Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bugout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

__email__ = "engineering@bugout.dev"
__license__ = "MIT"
__version__ = "0.2.7"
__version__ = "0.2.8"

__all__ = (
"__author__",
Expand Down
49 changes: 49 additions & 0 deletions bugout/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,31 @@ def create_tags(
**kwargs,
)

def create_entries_tags(
self,
token: Union[str, uuid.UUID],
journal_id: Union[str, uuid.UUID],
entries_tags: List[Dict[str, Any]],
timeout: float = REQUESTS_TIMEOUT,
auth_type: str = data.AuthType.bearer.name,
**kwargs: Dict[str, Any],
) -> data.BugoutJournalEntries:
self.journal.timeout = timeout

entries_tags_obj = data.BugoutJournalEntriesTagsRequest(
entries=[
data.BugoutJournalEntryTagsRequest(**entry_tags)
for entry_tags in entries_tags
]
)
return self.journal.create_entries_tags(
token=token,
journal_id=journal_id,
entries_tags=entries_tags_obj,
auth_type=data.AuthType[auth_type],
**kwargs,
)

def get_tags(
self,
token: Union[str, uuid.UUID],
Expand Down Expand Up @@ -845,6 +870,30 @@ def delete_tag(
**kwargs,
)

def delete_entries_tags(
self,
token: Union[str, uuid.UUID],
journal_id: Union[str, uuid.UUID],
entries_tags: List[Dict[str, Any]],
timeout: float = REQUESTS_TIMEOUT,
auth_type: str = data.AuthType.bearer.name,
**kwargs: Dict[str, Any],
) -> data.BugoutJournalEntries:
self.journal.timeout = timeout
entries_tags_obj = data.BugoutJournalEntriesTagsRequest(
entries=[
data.BugoutJournalEntryTagsRequest(**entry_tags)
for entry_tags in entries_tags
]
)
return self.journal.delete_entries_tags(
token=token,
journal_id=journal_id,
entries_tags=entries_tags_obj,
auth_type=data.AuthType[auth_type],
**kwargs,
)

# Search
def search(
self,
Expand Down
2 changes: 1 addition & 1 deletion bugout/calls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict

import requests
import requests # type: ignore

from .data import Method
from .exceptions import BugoutResponseException, BugoutUnexpectedResponse
Expand Down
14 changes: 14 additions & 0 deletions bugout/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ class BugoutJournalEntryTags(BaseModel):
tags: List[str]


class BugoutJournalEntryTagsRequest(BaseModel):
journal_entry_id: uuid.UUID = Field(alias="entry_id")
tags: List[str]

class Config:
# Required configuration because in Spire we use "journal_entry_id" instead of "entry_id"
# during creation and deletion of new tags for journal entry
allow_population_by_field_name = True


class BugoutJournalEntriesTagsRequest(BaseModel):
entries: List[BugoutJournalEntryTagsRequest] = Field(default_factory=list)


class BugoutSearchResult(BaseModel):
entry_url: str
content_url: str
Expand Down
48 changes: 48 additions & 0 deletions bugout/journal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import uuid
from enum import Enum
import json
from typing import Any, Dict, List, Optional, Union

from .calls import make_request
Expand All @@ -11,6 +12,7 @@
BugoutJournalEntry,
BugoutJournalEntryContent,
BugoutJournalEntryTags,
BugoutJournalEntriesTagsRequest,
BugoutJournalPermissions,
BugoutJournals,
BugoutJournalScopeSpecs,
Expand Down Expand Up @@ -464,6 +466,29 @@ def create_tags(
)
return result

def create_entries_tags(
self,
token: Union[str, uuid.UUID],
journal_id: Union[str, uuid.UUID],
entries_tags: BugoutJournalEntriesTagsRequest,
auth_type: AuthType = AuthType.bearer,
**kwargs: Dict[str, Any],
) -> BugoutJournalEntries:
tags_path = f"journals/{journal_id}/bulk_entries_tags"
headers = {
"Authorization": f"{auth_type.value} {token}",
}
json_body = json.loads(entries_tags.json())
if "headers" in kwargs.keys():
headers.update(kwargs["headers"])
result = self._call(
method=Method.post, path=tags_path, headers=headers, json=json_body
)

return BugoutJournalEntries(
entries=[BugoutJournalEntry(**entry) for entry in result]
)

def get_tags(
self,
token: Union[str, uuid.UUID],
Expand Down Expand Up @@ -523,6 +548,29 @@ def delete_tag(
)
return BugoutJournalEntryTags(**result)

def delete_entries_tags(
self,
token: Union[str, uuid.UUID],
journal_id: Union[str, uuid.UUID],
entries_tags: BugoutJournalEntriesTagsRequest,
auth_type: AuthType = AuthType.bearer,
**kwargs: Dict[str, Any],
) -> BugoutJournalEntries:
tags_path = f"journals/{journal_id}/bulk_entries_tags"
headers = {
"Authorization": f"{auth_type.value} {token}",
}
json_body = json.loads(entries_tags.json())
if "headers" in kwargs.keys():
headers.update(kwargs["headers"])
result = self._call(
method=Method.delete, path=tags_path, headers=headers, json=json_body
)

return BugoutJournalEntries(
entries=[BugoutJournalEntry(**entry) for entry in result]
)

# Search module
def search(
self,
Expand Down