Skip to content

Commit d4ba790

Browse files
committed
Public journal endpoints
1 parent 7b53d67 commit d4ba790

3 files changed

Lines changed: 173 additions & 8 deletions

File tree

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.4"
10+
__version__ = "0.2.5"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,14 +841,78 @@ def search(
841841
**kwargs,
842842
)
843843

844-
# Public
844+
# Public journals
845845
def check_journal_public(
846846
self,
847847
journal_id: Union[str, uuid.UUID],
848848
timeout: float = REQUESTS_TIMEOUT,
849+
**kwargs: Dict[str, Any],
849850
) -> bool:
850851
self.journal.timeout = timeout
851-
return self.journal.check_journal_public(journal_id=journal_id)
852+
return self.journal.check_journal_public(journal_id=journal_id, **kwargs)
853+
854+
def list_public_journals(
855+
self,
856+
user_id: Union[str, uuid.UUID],
857+
timeout: float = REQUESTS_TIMEOUT,
858+
**kwargs: Dict[str, Any],
859+
) -> data.BugoutJournals:
860+
self.journal.timeout = timeout
861+
return self.journal.list_public_journals(user_id=user_id, **kwargs)
862+
863+
def get_public_journal(
864+
self,
865+
journal_id: Union[str, uuid.UUID],
866+
timeout: float = REQUESTS_TIMEOUT,
867+
**kwargs: Dict[str, Any],
868+
) -> data.BugoutJournal:
869+
self.journal.timeout = timeout
870+
return self.journal.get_public_journal(journal_id=journal_id, **kwargs)
871+
872+
def get_public_journal_entries(
873+
self,
874+
journal_id: Union[str, uuid.UUID],
875+
timeout: float = REQUESTS_TIMEOUT,
876+
**kwargs: Dict[str, Any],
877+
) -> data.BugoutJournalEntries:
878+
self.journal.timeout = timeout
879+
return self.journal.get_public_journal_entries(journal_id=journal_id, **kwargs)
880+
881+
def get_public_journal_entry(
882+
self,
883+
journal_id: Union[str, uuid.UUID],
884+
entry_id: Union[str, uuid.UUID],
885+
timeout: float = REQUESTS_TIMEOUT,
886+
**kwargs: Dict[str, Any],
887+
) -> data.BugoutJournalEntry:
888+
self.journal.timeout = timeout
889+
return self.journal.get_public_journal_entry(
890+
journal_id=journal_id, entry_id=entry_id, **kwargs
891+
)
892+
893+
def public_search(
894+
self,
895+
journal_id: Union[str, uuid.UUID],
896+
query: str,
897+
filters: Optional[List[str]] = None,
898+
limit: int = 10,
899+
offset: int = 0,
900+
content: bool = True,
901+
timeout: float = REQUESTS_TIMEOUT,
902+
order: SearchOrder = SearchOrder.DESCENDING,
903+
**kwargs: Dict[str, Any],
904+
) -> data.BugoutSearchResults:
905+
self.journal.timeout = timeout
906+
return self.journal.public_search(
907+
journal_id,
908+
query,
909+
filters,
910+
limit,
911+
offset,
912+
content,
913+
order=order,
914+
**kwargs,
915+
)
852916

853917
# Humbug
854918
def get_humbug_integrations(

bugout/journal.py

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,110 @@ def search(
556556
)
557557
return BugoutSearchResults(**result)
558558

559-
# Public module
560-
def check_journal_public(self, journal_id: Union[str, uuid.UUID]) -> bool:
561-
journal_path = "public/check"
562-
query_params = {"journal_id": journal_id}
563-
result = self._call(method=Method.get, path=journal_path, params=query_params)
559+
# Public journals module
560+
def check_journal_public(
561+
self,
562+
journal_id: Union[str, uuid.UUID],
563+
**kwargs: Dict[str, Any],
564+
) -> bool:
565+
check_path = f"public/{journal_id}/check"
566+
headers = {}
567+
if "headers" in kwargs.keys():
568+
headers.update(kwargs["headers"])
569+
result = self._call(method=Method.get, path=check_path, headers=headers)
564570
return result
571+
572+
def list_public_journals(
573+
self,
574+
user_id: Union[str, uuid.UUID],
575+
**kwargs: Dict[str, Any],
576+
) -> BugoutJournals:
577+
public_journals_path = "public"
578+
headers = {}
579+
if "headers" in kwargs.keys():
580+
headers.update(kwargs["headers"])
581+
query_params = {"user_id": user_id}
582+
result = self._call(
583+
method=Method.get,
584+
path=public_journals_path,
585+
params=query_params,
586+
headers=headers,
587+
)
588+
return BugoutJournals(**result)
589+
590+
def get_public_journal(
591+
self,
592+
journal_id: Union[str, uuid.UUID],
593+
**kwargs: Dict[str, Any],
594+
) -> BugoutJournal:
595+
public_journal_path = f"public/{journal_id}"
596+
headers = {}
597+
if "headers" in kwargs.keys():
598+
headers.update(kwargs["headers"])
599+
result = self._call(
600+
method=Method.get,
601+
path=public_journal_path,
602+
headers=headers,
603+
)
604+
return BugoutJournal(**result)
605+
606+
def get_public_journal_entries(
607+
self,
608+
journal_id: Union[str, uuid.UUID],
609+
**kwargs: Dict[str, Any],
610+
) -> BugoutJournalEntries:
611+
public_journal_path = f"public/{journal_id}/entries"
612+
headers = {}
613+
if "headers" in kwargs.keys():
614+
headers.update(kwargs["headers"])
615+
result = self._call(
616+
method=Method.get,
617+
path=public_journal_path,
618+
headers=headers,
619+
)
620+
return BugoutJournalEntries(**result)
621+
622+
def get_public_journal_entry(
623+
self,
624+
journal_id: Union[str, uuid.UUID],
625+
entry_id: Union[str, uuid.UUID],
626+
**kwargs: Dict[str, Any],
627+
) -> BugoutJournalEntry:
628+
public_journal_path = f"public/{journal_id}/entries/{entry_id}"
629+
headers = {}
630+
if "headers" in kwargs.keys():
631+
headers.update(kwargs["headers"])
632+
result = self._call(
633+
method=Method.get,
634+
path=public_journal_path,
635+
headers=headers,
636+
)
637+
return BugoutJournalEntry(**result)
638+
639+
def public_search(
640+
self,
641+
journal_id: Union[str, uuid.UUID],
642+
query: str,
643+
filters: Optional[List[str]] = None,
644+
limit: int = 10,
645+
offset: int = 0,
646+
content: bool = True,
647+
order: SearchOrder = SearchOrder.DESCENDING,
648+
**kwargs: Dict[str, Any],
649+
) -> BugoutSearchResults:
650+
search_path = f"public/{journal_id}/search"
651+
headers = {}
652+
if "headers" in kwargs.keys():
653+
headers.update(kwargs["headers"])
654+
query_params = {
655+
"q": query,
656+
"filters": filters if filters is not None else [],
657+
"limit": limit,
658+
"offset": offset,
659+
"content": content,
660+
"order": order.value,
661+
}
662+
result = self._call(
663+
method=Method.get, path=search_path, params=query_params, headers=headers
664+
)
665+
return BugoutSearchResults(**result)

0 commit comments

Comments
 (0)