22import uuid
33
44from .calls import make_request , InvalidUrlSpec
5- from .data import BugoutJournal , Method
5+ from .data import BugoutJournal , BugoutJournals , Method
66
77
88class Journal :
@@ -20,17 +20,55 @@ def _call(self, method: Method, path: str, **kwargs):
2020 result = make_request (method = method , url = url , ** kwargs )
2121 return result
2222
23- def get_journal (self , journal_id : uuid .UUID , token : uuid .UUID ) -> BugoutJournal :
24- get_group_path = f"journals/{ journal_id } "
23+ # Journal module
24+ def create_journal (self , token : uuid .UUID , name : str ) -> BugoutJournal :
25+ journal_path = "journals/"
26+ json = {
27+ "name" : name ,
28+ }
2529 headers = {
2630 "Authorization" : f"Bearer { token } " ,
2731 }
28- result = self ._call (method = Method .get , path = get_group_path , headers = headers )
29- return BugoutJournal (
30- id = result .get ("id" ),
31- bugout_user_id = result .get ("bugout_user_id" ),
32- holder_ids = result .get ("holder_ids" ),
33- name = result .get ("name" ),
34- created_at = result .get ("created_at" ),
35- updated_at = result .get ("updated_at" ),
32+ result = self ._call (
33+ method = Method .post , path = journal_path , headers = headers , json = json
3634 )
35+ return BugoutJournal (** result )
36+
37+ def list_journals (self , token : uuid .UUID ) -> BugoutJournals :
38+ journal_path = "journals/"
39+ headers = {
40+ "Authorization" : f"Bearer { token } " ,
41+ }
42+ result = self ._call (method = Method .get , path = journal_path , headers = headers )
43+ return BugoutJournals (** result )
44+
45+ def get_journal (self , token : uuid .UUID , journal_id : uuid .UUID ) -> BugoutJournal :
46+ journal_id_path = f"journals/{ journal_id } "
47+ headers = {
48+ "Authorization" : f"Bearer { token } " ,
49+ }
50+ result = self ._call (method = Method .get , path = journal_id_path , headers = headers )
51+ return BugoutJournal (** result )
52+
53+ def update_journal (
54+ self , token : uuid .UUID , journal_id : uuid .UUID , name : str
55+ ) -> BugoutJournal :
56+ journal_id_path = f"journals/{ journal_id } "
57+ json = {
58+ "name" : name ,
59+ }
60+ headers = {
61+ "Authorization" : f"Bearer { token } " ,
62+ }
63+ result = self ._call (
64+ method = Method .put , path = journal_id_path , headers = headers , json = json
65+ )
66+ return BugoutJournal (** result )
67+
68+ def delete_journal (self , token : uuid .UUID , journal_id : uuid .UUID ) -> BugoutJournal :
69+ journal_id_path = f"journals/{ journal_id } "
70+ headers = {
71+ "Authorization" : f"Bearer { token } " ,
72+ }
73+ result = self ._call (method = Method .delete , path = journal_id_path , headers = headers )
74+ return BugoutJournal (** result )
0 commit comments