Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
280 lines (211 loc) · 7.23 KB
/
Copy pathclient.py
File metadata and controls
280 lines (211 loc) · 7.23 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
from .api import Api
from .types import *
class Client(object):
"""
Initializes the API for the client
:param token: Authorization token
:type token: str
:param headers: Additional headers **except Authorization**
:type headers: dict
"""
def __init__(self, token: str, headers=None):
"""
Initializes the API for the client
:param token: Authorization token
:type token: str
"""
self.api = Api(token, headers)
def follow(self, id: str) -> Response:
"""
Subscribes to a user
:param id: User id
:type id: str
:rtype: :class:`Response`
"""
response = self.api.put('account/id/{}/follow'.format(id))
return Response.de_json(response)
def unfollow(self, id: str) -> Response:
"""
Unsubscribes to a user
:param id: User id
:type id: str
:rtype: :class:`Response`
"""
response = self.api.delete('account/id/{}/follow'.format(id))
return Response.de_json(response)
def get_user(self, id: str) -> Response:
"""
Gets a user profile
:param id: User id
:type id: str
:rtype: :class:`Response`, :class:`Account`
"""
response = self.api.get('account/id/{}'.format(id))
response = Response.de_json(response)
data = None
error = None
if hasattr(response, 'data'):
data = Account.de_json(response.data)
if hasattr(response, 'error'):
error = Error.de_json(response.error)
return Response(response.success, data=data, error=error)
def like(self, id: str) -> Response:
"""
Likes a byte
:param id: Byte (post) id
:type id: str
:rtype: :class:`Response`
"""
response = self.api.put('post/id/{}/feedback/like'.format(id))
return Response.de_json(response)
def dislike(self, id: str) -> Response:
"""
Removes like from a byte
:param id: Byte (post) id
:type id: str
:rtype: :class:`Response`
"""
response = self.api.delete('post/id/{}/feedback/like'.format(id))
return Response.de_json(response)
def comment(self, id: str, text: str) -> Response:
"""
Comments a byte
:param id: Byte (post) id
:type id: str
:param text: Comment text
:type id: str
:rtype: :class:`Response`, :class:`Comment`
"""
response = self.api.post('post/id/{}/feedback/comment'.format(id),
json_data={
'postID': id,
'body': text
})
response = Response.de_json(response)
data = None
error = None
if hasattr(response, 'data'):
data = Comment.de_json(response.data)
if hasattr(response, 'error'):
error = Error.de_json(response.error)
return Response(response.success, data=data, error=error)
def delete_comment(self, id: str) -> Response:
"""
Deletes a comment
:param id: Comment id patterned by **{post id}-{comment id}**
:type id: str
:rtype: :class:`Response`
"""
response = self.api.post('feedback/comment/id/{}'.format(id),
json_data={
'commentID': id
})
response = Response.de_json(response)
return Response.de_json(response)
def loop(self, id: str) -> Response:
"""
Increments loop counter
:param id: Byte (post) id
:type id: str
:rtype: :class:`Response`
"""
response = self.api.post('post/id/{}/loop'.format(id))
response = Response.de_json(response)
data = None
error = None
if hasattr(response, 'data'):
data = LoopCounter.de_json(response.data)
if hasattr(response, 'error'):
error = Error.de_json(response.error)
return Response(response.success, data=data, error=error)
def rebyte(self, id: str) -> Response:
"""
Increments loop counter
:param id: Byte (post) id
:type id: str
:rtype: :class:`Response`
"""
response = self.api.post('rebyte',
json_data={
'postID': id
})
response = Response.de_json(response)
data = None
error = None
if hasattr(response, 'data'):
data = Rebyte.de_json(response.data)
if hasattr(response, 'error'):
error = response.error
return Response(response.success, data=data, error=error)
def get_colors(self) -> Response:
"""
Gets available color schemes
:rtype: :class:`Response`
"""
response = self.api.get('account/me/colors')
response = Response.de_json(response)
data = None
error = None
if hasattr(response, 'data'):
data = Colors.de_json(response.data)
if hasattr(response, 'error'):
error = response.error
return Response(response.success, data=data, error=error)
def set_info(self, bio: str = None, display_name: str = None,
username: str = None, color_scheme: int = None) -> Response:
"""
Sets profile info
:param bio: New bio
:type bio: str
:param display_name: New name to display
:type display_name: str
:param username: New username
:type username: str
:param color_scheme: Id of new color scheme
:type color_scheme: int
:rtype: :class:`Response`
"""
data = {}
if bio:
data['bio'] = bio
if display_name:
data['displayName'] = display_name
if username:
data['username'] = username
if color_scheme:
data['colorScheme'] = color_scheme
response = self.api.put('account/me',
data=data)
return Response.de_json(response)
def set_username(self, username: str) -> Response:
"""
Sets username
:param username: New username
:type username: str
:rtype: :class:`Response`
"""
return self.set_info(username=username)
def set_bio(self, bio: str) -> Response:
"""
Sets bio
:param bio: New bio
:type bio: str
:rtype: :class:`Response`
"""
return self.set_info(bio=bio)
def set_display_name(self, display_name: str) -> Response:
"""
Sets name to display
:param display_name: New name to display
:type display_name: str
:rtype: :class:`Response`
"""
return self.set_info(display_name=display_name)
def set_color_scheme(self, color_scheme: int) -> Response:
"""
Sets color scheme
:param color_scheme: Id of new color scheme
:type color_scheme: str
:rtype: :class:`Response`
"""
return self.set_info(color_scheme=color_scheme)