|
| 1 | +import json |
1 | 2 | import uuid |
2 | 3 | from enum import Enum |
3 | | -import json |
4 | 4 | from typing import Any, Dict, List, Optional, Union |
5 | 5 |
|
6 | 6 | from .calls import make_request |
7 | 7 | from .data import ( |
8 | 8 | AuthType, |
9 | 9 | BugoutJournal, |
| 10 | + BugoutJournalEntities, |
| 11 | + BugoutJournalEntity, |
| 12 | + BugoutJournalEntityRequest, |
10 | 13 | BugoutJournalEntries, |
11 | 14 | BugoutJournalEntriesRequest, |
| 15 | + BugoutJournalEntriesTagsRequest, |
12 | 16 | BugoutJournalEntry, |
13 | 17 | BugoutJournalEntryContent, |
14 | 18 | BugoutJournalEntryTags, |
15 | | - BugoutJournalEntriesTagsRequest, |
16 | 19 | BugoutJournalPermissions, |
17 | 20 | BugoutJournals, |
18 | 21 | BugoutJournalScopeSpecs, |
@@ -571,6 +574,150 @@ def delete_entries_tags( |
571 | 574 | entries=[BugoutJournalEntry(**entry) for entry in result] |
572 | 575 | ) |
573 | 576 |
|
| 577 | + # Entity module |
| 578 | + def create_entity( |
| 579 | + self, |
| 580 | + token: Union[str, uuid.UUID], |
| 581 | + journal_id: Union[str, uuid.UUID], |
| 582 | + title: str, |
| 583 | + address: str, |
| 584 | + blockchain: str, |
| 585 | + required_fields: List[Dict[str, Union[str, bool, int, list]]] = [], |
| 586 | + secondary_fields: Dict[str, Any] = {}, |
| 587 | + auth_type: AuthType = AuthType.bearer, |
| 588 | + **kwargs: Dict[str, Any], |
| 589 | + ) -> BugoutJournalEntity: |
| 590 | + path = f"journals/{journal_id}/entities" |
| 591 | + json = { |
| 592 | + "title": title, |
| 593 | + "address": address, |
| 594 | + "blockchain": blockchain, |
| 595 | + "required_fields": required_fields, |
| 596 | + **secondary_fields, |
| 597 | + } |
| 598 | + headers = { |
| 599 | + "Authorization": f"{auth_type.value} {token}", |
| 600 | + } |
| 601 | + if "headers" in kwargs.keys(): |
| 602 | + headers.update(kwargs["headers"]) |
| 603 | + result = self._call(method=Method.post, path=path, headers=headers, json=json) |
| 604 | + return BugoutJournalEntity(**result) |
| 605 | + |
| 606 | + def create_entities_pack( |
| 607 | + self, |
| 608 | + token: Union[str, uuid.UUID], |
| 609 | + journal_id: Union[str, uuid.UUID], |
| 610 | + entities: List[BugoutJournalEntityRequest], |
| 611 | + auth_type: AuthType = AuthType.bearer, |
| 612 | + **kwargs: Dict[str, Any], |
| 613 | + ) -> BugoutJournalEntities: |
| 614 | + path = f"journals/{journal_id}/entities/bulk" |
| 615 | + headers = { |
| 616 | + "Authorization": f"{auth_type.value} {token}", |
| 617 | + } |
| 618 | + if "headers" in kwargs.keys(): |
| 619 | + headers.update(kwargs["headers"]) |
| 620 | + json = { |
| 621 | + "entities": [ |
| 622 | + { |
| 623 | + "title": entity.title, |
| 624 | + "address": entity.address, |
| 625 | + "blockchain": entity.blockchain, |
| 626 | + "required_fields": entity.required_fields, |
| 627 | + **entity.extra, |
| 628 | + } |
| 629 | + for entity in entities |
| 630 | + ] |
| 631 | + } |
| 632 | + result = self._call(method=Method.post, path=path, headers=headers, json=json) |
| 633 | + return BugoutJournalEntities(**result) |
| 634 | + |
| 635 | + def get_entity( |
| 636 | + self, |
| 637 | + token: Union[str, uuid.UUID], |
| 638 | + journal_id: Union[str, uuid.UUID], |
| 639 | + entity_id: Union[str, uuid.UUID], |
| 640 | + auth_type: AuthType = AuthType.bearer, |
| 641 | + **kwargs: Dict[str, Any], |
| 642 | + ) -> BugoutJournalEntity: |
| 643 | + path = f"journals/{journal_id}/entities/{entity_id}" |
| 644 | + headers = { |
| 645 | + "Authorization": f"{auth_type.value} {token}", |
| 646 | + } |
| 647 | + if "headers" in kwargs.keys(): |
| 648 | + headers.update(kwargs["headers"]) |
| 649 | + result = self._call(method=Method.get, path=path, headers=headers) |
| 650 | + return BugoutJournalEntity(**result) |
| 651 | + |
| 652 | + def get_entities( |
| 653 | + self, |
| 654 | + token: Union[str, uuid.UUID], |
| 655 | + journal_id: Union[str, uuid.UUID], |
| 656 | + auth_type: AuthType = AuthType.bearer, |
| 657 | + **kwargs: Dict[str, Any], |
| 658 | + ) -> BugoutJournalEntities: |
| 659 | + path = f"journals/{journal_id}/entities" |
| 660 | + headers = { |
| 661 | + "Authorization": f"{auth_type.value} {token}", |
| 662 | + } |
| 663 | + if "headers" in kwargs.keys(): |
| 664 | + headers.update(kwargs["headers"]) |
| 665 | + result = self._call(method=Method.get, path=path, headers=headers) |
| 666 | + return BugoutJournalEntities(**result) |
| 667 | + |
| 668 | + def update_entity( |
| 669 | + self, |
| 670 | + token: Union[str, uuid.UUID], |
| 671 | + journal_id: Union[str, uuid.UUID], |
| 672 | + entity_id: Union[str, uuid.UUID], |
| 673 | + title: str, |
| 674 | + address: str, |
| 675 | + blockchain: str, |
| 676 | + required_fields: List[Dict[str, Union[str, bool, int, list]]] = [], |
| 677 | + secondary_fields: Dict[str, Any] = {}, |
| 678 | + auth_type: AuthType = AuthType.bearer, |
| 679 | + **kwargs: Dict[str, Any], |
| 680 | + ) -> BugoutJournalEntity: |
| 681 | + path = f"journals/{journal_id}/entities/{entity_id}" |
| 682 | + params: Dict[str, str] = {} |
| 683 | + json = { |
| 684 | + "title": title, |
| 685 | + "address": address, |
| 686 | + "blockchain": blockchain, |
| 687 | + "required_fields": required_fields, |
| 688 | + **secondary_fields, |
| 689 | + } |
| 690 | + headers = { |
| 691 | + "Authorization": f"{auth_type.value} {token}", |
| 692 | + } |
| 693 | + if "headers" in kwargs.keys(): |
| 694 | + headers.update(kwargs["headers"]) |
| 695 | + result = self._call( |
| 696 | + method=Method.put, |
| 697 | + path=path, |
| 698 | + headers=headers, |
| 699 | + json=json, |
| 700 | + params=params, |
| 701 | + ) |
| 702 | + return BugoutJournalEntity(**result) |
| 703 | + |
| 704 | + def delete_entity( |
| 705 | + self, |
| 706 | + token: Union[str, uuid.UUID], |
| 707 | + journal_id: Union[str, uuid.UUID], |
| 708 | + entity_id: Union[str, uuid.UUID], |
| 709 | + auth_type: AuthType = AuthType.bearer, |
| 710 | + **kwargs: Dict[str, Any], |
| 711 | + ) -> BugoutJournalEntity: |
| 712 | + path = f"journals/{journal_id}/entities/{entity_id}" |
| 713 | + headers = { |
| 714 | + "Authorization": f"{auth_type.value} {token}", |
| 715 | + } |
| 716 | + if "headers" in kwargs.keys(): |
| 717 | + headers.update(kwargs["headers"]) |
| 718 | + result = self._call(method=Method.delete, path=path, headers=headers) |
| 719 | + return BugoutJournalEntity(**result) |
| 720 | + |
574 | 721 | # Search module |
575 | 722 | def search( |
576 | 723 | self, |
|
0 commit comments