Skip to content

Commit ddf813c

Browse files
authored
Merge pull request #44 from bugout-dev/public-journal-endpoints
Public journal endpoints
2 parents 7b53d67 + 1babb09 commit ddf813c

File tree

3 files changed

+254
-8
lines changed

3 files changed

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

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,14 +841,114 @@ 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 create_public_journal_entry(
882+
self,
883+
journal_id: Union[str, uuid.UUID],
884+
title: str,
885+
content: str,
886+
tags: List[str] = [],
887+
context_url: Optional[str] = None,
888+
context_id: Optional[str] = None,
889+
context_type: Optional[str] = None,
890+
timeout: float = REQUESTS_TIMEOUT,
891+
**kwargs: Dict[str, Any],
892+
) -> data.BugoutJournalEntry:
893+
self.journal.timeout = timeout
894+
return self.journal.create_public_journal_entry(
895+
journal_id=journal_id,
896+
title=title,
897+
content=content,
898+
tags=tags,
899+
context_url=context_url,
900+
context_id=context_id,
901+
context_type=context_type,
902+
**kwargs,
903+
)
904+
905+
def touch_public_journal_entry(
906+
self,
907+
journal_id: Union[str, uuid.UUID],
908+
entry_id: Union[str, uuid.UUID],
909+
timeout: float = REQUESTS_TIMEOUT,
910+
**kwargs: Dict[str, Any],
911+
) -> List[str]:
912+
self.journal.timeout = timeout
913+
return self.journal.touch_public_journal_entry(
914+
journal_id=journal_id, entry_id=entry_id, **kwargs
915+
)
916+
917+
def get_public_journal_entry(
918+
self,
919+
journal_id: Union[str, uuid.UUID],
920+
entry_id: Union[str, uuid.UUID],
921+
timeout: float = REQUESTS_TIMEOUT,
922+
**kwargs: Dict[str, Any],
923+
) -> data.BugoutJournalEntry:
924+
self.journal.timeout = timeout
925+
return self.journal.get_public_journal_entry(
926+
journal_id=journal_id, entry_id=entry_id, **kwargs
927+
)
928+
929+
def public_search(
930+
self,
931+
journal_id: Union[str, uuid.UUID],
932+
query: str,
933+
filters: Optional[List[str]] = None,
934+
limit: int = 10,
935+
offset: int = 0,
936+
content: bool = True,
937+
timeout: float = REQUESTS_TIMEOUT,
938+
order: SearchOrder = SearchOrder.DESCENDING,
939+
**kwargs: Dict[str, Any],
940+
) -> data.BugoutSearchResults:
941+
self.journal.timeout = timeout
942+
return self.journal.public_search(
943+
journal_id,
944+
query,
945+
filters,
946+
limit,
947+
offset,
948+
content,
949+
order=order,
950+
**kwargs,
951+
)
852952

853953
# Humbug
854954
def get_humbug_integrations(

bugout/journal.py

Lines changed: 151 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,155 @@ 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)
570+
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 create_public_journal_entry(
623+
self,
624+
journal_id: Union[str, uuid.UUID],
625+
title: str,
626+
content: str,
627+
tags: List[str] = [],
628+
context_url: Optional[str] = None,
629+
context_id: Optional[str] = None,
630+
context_type: Optional[str] = None,
631+
**kwargs: Dict[str, Any],
632+
) -> BugoutJournalEntry:
633+
entry_path = f"public/{journal_id}/entries"
634+
json = {
635+
"title": title,
636+
"content": content,
637+
"tags": tags,
638+
"context_url": context_url,
639+
"context_id": context_id,
640+
"context_type": context_type,
641+
}
642+
headers = {}
643+
if "headers" in kwargs.keys():
644+
headers.update(kwargs["headers"])
645+
result = self._call(
646+
method=Method.post, path=entry_path, headers=headers, json=json
647+
)
648+
return BugoutJournalEntry(**result)
649+
650+
def touch_public_journal_entry(
651+
self,
652+
journal_id: Union[str, uuid.UUID],
653+
entry_id: Union[str, uuid.UUID],
654+
**kwargs: Dict[str, Any],
655+
) -> List[str]:
656+
public_journal_path = f"public/{journal_id}/entries/{entry_id}"
657+
headers = {}
658+
if "headers" in kwargs.keys():
659+
headers.update(kwargs["headers"])
660+
result = self._call(
661+
method=Method.put,
662+
path=public_journal_path,
663+
headers=headers,
664+
)
564665
return result
666+
667+
def get_public_journal_entry(
668+
self,
669+
journal_id: Union[str, uuid.UUID],
670+
entry_id: Union[str, uuid.UUID],
671+
**kwargs: Dict[str, Any],
672+
) -> BugoutJournalEntry:
673+
public_journal_path = f"public/{journal_id}/entries/{entry_id}"
674+
headers = {}
675+
if "headers" in kwargs.keys():
676+
headers.update(kwargs["headers"])
677+
result = self._call(
678+
method=Method.get,
679+
path=public_journal_path,
680+
headers=headers,
681+
)
682+
return BugoutJournalEntry(**result)
683+
684+
def public_search(
685+
self,
686+
journal_id: Union[str, uuid.UUID],
687+
query: str,
688+
filters: Optional[List[str]] = None,
689+
limit: int = 10,
690+
offset: int = 0,
691+
content: bool = True,
692+
order: SearchOrder = SearchOrder.DESCENDING,
693+
**kwargs: Dict[str, Any],
694+
) -> BugoutSearchResults:
695+
search_path = f"public/{journal_id}/search"
696+
headers = {}
697+
if "headers" in kwargs.keys():
698+
headers.update(kwargs["headers"])
699+
query_params = {
700+
"q": query,
701+
"filters": filters if filters is not None else [],
702+
"limit": limit,
703+
"offset": offset,
704+
"content": content,
705+
"order": order.value,
706+
}
707+
result = self._call(
708+
method=Method.get, path=search_path, params=query_params, headers=headers
709+
)
710+
return BugoutSearchResults(**result)

0 commit comments

Comments
 (0)