-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbase.py
More file actions
80 lines (64 loc) · 1.78 KB
/
base.py
File metadata and controls
80 lines (64 loc) · 1.78 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from abc import ABC, abstractmethod
class AbstractReactions(ABC):
@abstractmethod
def add(
self,
kind,
activity_id,
user_id,
data=None,
target_feeds=None,
target_feeds_extra_data=None,
moderation_template=None,
):
pass
@abstractmethod
def get(self, reaction_id):
pass
@abstractmethod
def update(self, reaction_id, data=None, target_feeds=None):
pass
@abstractmethod
def delete(self, reaction_id, soft=False):
pass
@abstractmethod
def restore(self, reaction_id):
pass
@abstractmethod
def add_child(
self,
kind,
parent_id,
user_id,
data=None,
target_feeds=None,
target_feeds_extra_data=None,
moderation_template=None,
):
pass
@abstractmethod
def filter(self, **params):
pass
class BaseReactions(AbstractReactions, ABC):
API_ENDPOINT = "reaction/"
SERVICE_NAME = "api"
def __init__(self, client, token):
self.client = client
self.token = token
def _prepare_endpoint_for_filter(self, **params):
lookup_field = ""
lookup_value = ""
kind = params.pop("kind", None)
if params.get("reaction_id"):
lookup_field = "reaction_id"
lookup_value = params.pop("reaction_id")
elif params.get("activity_id"):
lookup_field = "activity_id"
lookup_value = params.pop("activity_id")
elif params.get("user_id"):
lookup_field = "user_id"
lookup_value = params.pop("user_id")
endpoint = f"{self.API_ENDPOINT}{lookup_field}/{lookup_value}/"
if kind is not None:
endpoint += f"{kind}/"
return endpoint