forked from mollie/mollie-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
42 lines (34 loc) · 1.08 KB
/
base.py
File metadata and controls
42 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from ..error import EmbedNotFound
class ObjectBase(dict):
def __init__(self, data, client):
"""
Create a new object from API result data.
"""
super().__init__(data)
self.client = client
def _get_property(self, name):
"""Return the named property from dictionary values."""
if name not in self:
return None
return self[name]
def _get_link(self, name):
"""Return a link by its name."""
try:
return self["_links"][name]["href"]
except (KeyError, TypeError):
return None
def get_embedded(self, name: str) -> dict:
"""
Get embedded data by its name.
:param name: The name of the embedded data.
:type name: str
:raises EmbedNotFound: When no embedded data with the given name exists.
"""
try:
return self["_embedded"][name]
except KeyError:
raise EmbedNotFound(name)
@classmethod
def get_object_name(cls):
name = cls.__name__.lower()
return f"{name}s"