Skip to content

Commit

Permalink
Adapt new attributes api to mwdblib (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
KWMORALE committed Jan 4, 2022
1 parent 590e3e6 commit e37037b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions mwdblib/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ def shares(self) -> List["MWDBShare"]:
)
return [MWDBShare(self.api, share, self) for share in self.data["shares"]]

@property
def attributes(self) -> Dict[str, List[Any]]:
"""
Returns dict object with attributes.
:return: Dict object containing attributes
"""
if "attributes" not in self.data:
self._load("object/{id}/attribute")
result = defaultdict(list)
for m in self.data["attributes"]:
result[m["key"]].append(m["value"])
return dict(result)

@property
def metakeys(self) -> Dict[str, List[str]]:
"""
Expand Down Expand Up @@ -285,6 +299,21 @@ def add_comment(self, comment: str) -> None:
)
self._expire("comments")

def add_attribute(self, key: str, value: Any) -> None:
"""
Adds attribute
:param key: Attribute key
:type key: str
:param value: Attribute value
:type value: Any (JSON-like object)
"""
self.api.post(
"object/{id}/attribute".format(**self.data),
json={"key": key, "value": value},
)
self._expire("attributes")

def add_metakey(self, key: str, value: str) -> None:
"""
Adds metakey attribute
Expand Down

0 comments on commit e37037b

Please sign in to comment.