Skip to content

Commit 5b3effd

Browse files
authored
Merge pull request #23 from bugout-dev/entries-pack
Added handler create entries pack
2 parents 08077c7 + 47f6e23 commit 5b3effd

File tree

5 files changed

+75
-21
lines changed

5 files changed

+75
-21
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.1.9"
10+
__version__ = "0.1.10"
1111

1212
__all__ = (
1313
"__author__",

bugout/app.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,11 @@ def get_group(
211211
def find_group(
212212
self,
213213
token: Union[str, uuid.UUID],
214-
group_id: Optional[Union[str, uuid.UUID]] = None,
215-
name: Optional[str] = None,
214+
group_id: Union[str, uuid.UUID],
216215
timeout: float = REQUESTS_TIMEOUT,
217216
) -> data.BugoutGroup:
218217
self.user.timeout = timeout
219-
return self.group.find_group(token=token, group_id=group_id, name=name)
218+
return self.group.find_group(token=token, group_id=group_id)
220219

221220
def get_user_groups(
222221
self, token: Union[str, uuid.UUID], timeout: float = REQUESTS_TIMEOUT
@@ -422,6 +421,23 @@ def create_entry(
422421
context_type=context_type,
423422
)
424423

424+
def create_entries_pack(
425+
self,
426+
token: Union[str, uuid.UUID],
427+
journal_id: Union[str, uuid.UUID],
428+
entries: List[Dict[str, Any]],
429+
timeout: float = REQUESTS_TIMEOUT,
430+
) -> data.BugoutJournalEntries:
431+
self.journal.timeout = timeout
432+
entries_obj = data.BugoutJournalEntriesRequest(
433+
entries=[data.BugoutJournalEntryRequest(**entry) for entry in entries]
434+
)
435+
return self.journal.create_entries_pack(
436+
token=token,
437+
journal_id=journal_id,
438+
entries=entries_obj,
439+
)
440+
425441
def get_entry(
426442
self,
427443
token: Union[str, uuid.UUID],
@@ -552,13 +568,16 @@ def search(
552568
token: Union[str, uuid.UUID],
553569
journal_id: Union[str, uuid.UUID],
554570
query: str,
571+
filters: Optional[List[str]] = None,
555572
limit: int = 10,
556573
offset: int = 0,
557574
content: bool = True,
558575
timeout: float = REQUESTS_TIMEOUT,
559576
) -> data.BugoutSearchResults:
560577
self.journal.timeout = timeout
561-
return self.journal.search(token, journal_id, query, limit, offset, content)
578+
return self.journal.search(
579+
token, journal_id, query, filters, limit, offset, content
580+
)
562581

563582
# Humbug
564583
def get_humbug_integrations(

bugout/data.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class BugoutUserTokens(BaseModel):
7575

7676
class BugoutGroup(BaseModel):
7777
id: uuid.UUID
78-
group_name: Optional[str]
78+
group_name: Optional[str] = Field(alias="name")
7979
autogenerated: bool
8080

8181

@@ -133,13 +133,13 @@ class BugoutJournals(BaseModel):
133133

134134
class BugoutJournalEntry(BaseModel):
135135
id: uuid.UUID
136-
journal_url: str
136+
journal_url: Optional[str]
137137
content_url: Optional[str]
138138
title: Optional[str]
139139
content: Optional[str]
140140
tags: List[str] = Field(default_factory=list)
141-
created_at: datetime
142-
updated_at: datetime
141+
created_at: Optional[datetime]
142+
updated_at: Optional[datetime]
143143
context_url: Optional[str]
144144
context_type: Optional[str]
145145

@@ -148,6 +148,19 @@ class BugoutJournalEntries(BaseModel):
148148
entries: List[BugoutJournalEntry]
149149

150150

151+
class BugoutJournalEntryRequest(BaseModel):
152+
title: str
153+
content: str
154+
tags: List[str] = Field(default_factory=list)
155+
context_url: Optional[str]
156+
context_id: Optional[str]
157+
context_type: Optional[str]
158+
159+
160+
class BugoutJournalEntriesRequest(BaseModel):
161+
entries: List[BugoutJournalEntryRequest] = Field(default_factory=list)
162+
163+
151164
class BugoutJournalEntryContent(BaseModel):
152165
title: str
153166
content: str

bugout/group.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,10 @@ def get_group(
5050
def find_group(
5151
self,
5252
token: Union[str, uuid.UUID],
53-
group_id: Optional[Union[str, uuid.UUID]] = None,
54-
name: Optional[str] = None,
53+
group_id: Union[str, uuid.UUID],
5554
) -> BugoutGroup:
56-
find_group_path = f"group/find"
57-
if group_id is None and name is None:
58-
raise GroupInvalidParameters(
59-
"In order to find group, at least one of name, or id must be specified"
60-
)
61-
query_params = {}
62-
if group_id is not None:
63-
query_params.update({"group_id": group_id})
64-
if name is not None:
65-
query_params.update({"name": name})
55+
find_group_path = f"groups/find"
56+
query_params = {"group_id": group_id}
6657
headers = {
6758
"Authorization": f"Bearer {token}",
6859
}

bugout/journal.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
BugoutJournalScopeSpecs,
1010
BugoutJournalEntry,
1111
BugoutJournalEntries,
12+
BugoutJournalEntriesRequest,
1213
BugoutJournalEntryContent,
1314
BugoutJournalEntryTags,
1415
BugoutSearchResults,
@@ -196,6 +197,34 @@ def create_entry(
196197
)
197198
return BugoutJournalEntry(**result)
198199

200+
def create_entries_pack(
201+
self,
202+
token: Union[str, uuid.UUID],
203+
journal_id: Union[str, uuid.UUID],
204+
entries: BugoutJournalEntriesRequest,
205+
) -> BugoutJournalEntries:
206+
entry_path = f"journals/{journal_id}/bulk"
207+
headers = {
208+
"Authorization": f"Bearer {token}",
209+
}
210+
json = {
211+
"entries": [
212+
{
213+
"title": entry.title,
214+
"content": entry.content,
215+
"tags": entry.tags,
216+
"context_url": entry.context_url,
217+
"context_id": entry.context_id,
218+
"context_type": entry.context_type,
219+
}
220+
for entry in entries.entries
221+
]
222+
}
223+
result = self._call(
224+
method=Method.post, path=entry_path, headers=headers, json=json
225+
)
226+
return BugoutJournalEntries(**result)
227+
199228
def get_entry(
200229
self,
201230
token: Union[str, uuid.UUID],
@@ -352,6 +381,7 @@ def search(
352381
token: Union[str, uuid.UUID],
353382
journal_id: Union[str, uuid.UUID],
354383
query: str,
384+
filters: Optional[List[str]] = None,
355385
limit: int = 10,
356386
offset: int = 0,
357387
content: bool = True,
@@ -362,6 +392,7 @@ def search(
362392
}
363393
query_params = {
364394
"q": query,
395+
"filters": filters if filters is not None else [],
365396
"limit": limit,
366397
"offset": offset,
367398
"content": content,

0 commit comments

Comments
 (0)