|
| 1 | +from .api import Api |
| 2 | +from .types import * |
| 3 | + |
| 4 | + |
| 5 | +class Client(object): |
| 6 | + """ |
| 7 | + Initializes the API for the client |
| 8 | +
|
| 9 | + :param token: Authorization token |
| 10 | + :type token: str |
| 11 | +
|
| 12 | + :param headers: Additional headers **except Authorization** |
| 13 | + :type headers: dict |
| 14 | + """ |
| 15 | + |
| 16 | + def __init__(self, token: str, headers=None): |
| 17 | + """ |
| 18 | + Initializes the API for the client |
| 19 | +
|
| 20 | + :param token: Authorization token |
| 21 | + :type token: str |
| 22 | + """ |
| 23 | + self.api = Api(token, headers) |
| 24 | + |
| 25 | + def follow(self, id: str) -> Response: |
| 26 | + """ |
| 27 | + Subscribes to a user |
| 28 | +
|
| 29 | + :param id: User id |
| 30 | + :type id: str |
| 31 | +
|
| 32 | +
|
| 33 | + :rtype: :class:`Response` |
| 34 | + """ |
| 35 | + response = self.api.put('account/id/{}/follow'.format(id)) |
| 36 | + return Response.de_json(response) |
| 37 | + |
| 38 | + def unfollow(self, id: str) -> Response: |
| 39 | + """ |
| 40 | + Unsubscribes to a user |
| 41 | +
|
| 42 | + :param id: User id |
| 43 | + :type id: str |
| 44 | +
|
| 45 | +
|
| 46 | + :rtype: :class:`Response` |
| 47 | + """ |
| 48 | + response = self.api.delete('account/id/{}/follow'.format(id)) |
| 49 | + return Response.de_json(response) |
| 50 | + |
| 51 | + def get_user(self, id: str) -> Response: |
| 52 | + """ |
| 53 | + Gets a user profile |
| 54 | +
|
| 55 | + :param id: User id |
| 56 | + :type id: str |
| 57 | +
|
| 58 | +
|
| 59 | + :rtype: :class:`Response`, :class:`Account` |
| 60 | + """ |
| 61 | + response = self.api.get('account/id/{}'.format(id)) |
| 62 | + response = Response.de_json(response) |
| 63 | + data = None |
| 64 | + error = None |
| 65 | + if hasattr(response, 'data'): |
| 66 | + data = Account.de_json(response.data) |
| 67 | + if hasattr(response, 'error'): |
| 68 | + error = Error.de_json(response.error) |
| 69 | + return Response(response.success, data=data, error=error) |
| 70 | + |
| 71 | + def like(self, id: str) -> Response: |
| 72 | + """ |
| 73 | + Likes a byte |
| 74 | +
|
| 75 | + :param id: Byte (post) id |
| 76 | + :type id: str |
| 77 | +
|
| 78 | +
|
| 79 | + :rtype: :class:`Response` |
| 80 | + """ |
| 81 | + response = self.api.put('post/id/{}/feedback/like'.format(id)) |
| 82 | + return Response.de_json(response) |
| 83 | + |
| 84 | + def dislike(self, id: str) -> Response: |
| 85 | + """ |
| 86 | + Removes like from a byte |
| 87 | +
|
| 88 | + :param id: Byte (post) id |
| 89 | + :type id: str |
| 90 | +
|
| 91 | +
|
| 92 | + :rtype: :class:`Response` |
| 93 | + """ |
| 94 | + response = self.api.delete('post/id/{}/feedback/like'.format(id)) |
| 95 | + return Response.de_json(response) |
| 96 | + |
| 97 | + def comment(self, id: str, text: str) -> Response: |
| 98 | + """ |
| 99 | + Comments a byte |
| 100 | +
|
| 101 | + :param id: Byte (post) id |
| 102 | + :type id: str |
| 103 | +
|
| 104 | + :param text: Comment text |
| 105 | + :type id: str |
| 106 | +
|
| 107 | +
|
| 108 | + :rtype: :class:`Response`, :class:`Comment` |
| 109 | + """ |
| 110 | + response = self.api.post('post/id/{}/feedback/comment'.format(id), |
| 111 | + json_data={ |
| 112 | + 'postID': id, |
| 113 | + 'body': text |
| 114 | + }) |
| 115 | + response = Response.de_json(response) |
| 116 | + data = None |
| 117 | + error = None |
| 118 | + if hasattr(response, 'data'): |
| 119 | + data = Comment.de_json(response.data) |
| 120 | + if hasattr(response, 'error'): |
| 121 | + error = Error.de_json(response.error) |
| 122 | + return Response(response.success, data=data, error=error) |
| 123 | + |
| 124 | + def delete_comment(self, id: str) -> Response: |
| 125 | + """ |
| 126 | + Deletes a comment |
| 127 | +
|
| 128 | + :param id: Comment id patterned by **{post id}-{comment id}** |
| 129 | + :type id: str |
| 130 | +
|
| 131 | +
|
| 132 | + :rtype: :class:`Response` |
| 133 | + """ |
| 134 | + response = self.api.post('feedback/comment/id/{}'.format(id), |
| 135 | + json_data={ |
| 136 | + 'commentID': id |
| 137 | + }) |
| 138 | + response = Response.de_json(response) |
| 139 | + return Response.de_json(response) |
| 140 | + |
| 141 | + def loop(self, id: str) -> Response: |
| 142 | + """ |
| 143 | + Increments loop counter |
| 144 | +
|
| 145 | + :param id: Byte (post) id |
| 146 | + :type id: str |
| 147 | +
|
| 148 | +
|
| 149 | + :rtype: :class:`Response` |
| 150 | + """ |
| 151 | + response = self.api.post('post/id/{}/loop'.format(id)) |
| 152 | + response = Response.de_json(response) |
| 153 | + data = None |
| 154 | + error = None |
| 155 | + if hasattr(response, 'data'): |
| 156 | + data = LoopCounter.de_json(response.data) |
| 157 | + if hasattr(response, 'error'): |
| 158 | + error = Error.de_json(response.error) |
| 159 | + return Response(response.success, data=data, error=error) |
| 160 | + |
| 161 | + def rebyte(self, id: str) -> Response: |
| 162 | + """ |
| 163 | + Increments loop counter |
| 164 | +
|
| 165 | + :param id: Byte (post) id |
| 166 | + :type id: str |
| 167 | +
|
| 168 | +
|
| 169 | + :rtype: :class:`Response` |
| 170 | + """ |
| 171 | + response = self.api.post('rebyte', |
| 172 | + json_data={ |
| 173 | + 'postID': id |
| 174 | + }) |
| 175 | + response = Response.de_json(response) |
| 176 | + data = None |
| 177 | + error = None |
| 178 | + if hasattr(response, 'data'): |
| 179 | + data = Rebyte.de_json(response.data) |
| 180 | + if hasattr(response, 'error'): |
| 181 | + error = response.error |
| 182 | + return Response(response.success, data=data, error=error) |
| 183 | + |
| 184 | + def get_colors(self) -> Response: |
| 185 | + """ |
| 186 | + Gets available color schemes |
| 187 | +
|
| 188 | +
|
| 189 | + :rtype: :class:`Response` |
| 190 | + """ |
| 191 | + response = self.api.get('account/me/colors') |
| 192 | + response = Response.de_json(response) |
| 193 | + data = None |
| 194 | + error = None |
| 195 | + if hasattr(response, 'data'): |
| 196 | + data = Colors.de_json(response.data) |
| 197 | + if hasattr(response, 'error'): |
| 198 | + error = response.error |
| 199 | + return Response(response.success, data=data, error=error) |
| 200 | + |
| 201 | + def set_info(self, bio: str = None, display_name: str = None, |
| 202 | + username: str = None, color_scheme: int = None) -> Response: |
| 203 | + """ |
| 204 | + Sets profile info |
| 205 | +
|
| 206 | + :param bio: New bio |
| 207 | + :type bio: str |
| 208 | +
|
| 209 | + :param display_name: New name to display |
| 210 | + :type display_name: str |
| 211 | +
|
| 212 | + :param username: New username |
| 213 | + :type username: str |
| 214 | +
|
| 215 | + :param color_scheme: Id of new color scheme |
| 216 | + :type color_scheme: int |
| 217 | +
|
| 218 | +
|
| 219 | + :rtype: :class:`Response` |
| 220 | + """ |
| 221 | + data = {} |
| 222 | + if bio: |
| 223 | + data['bio'] = bio |
| 224 | + if display_name: |
| 225 | + data['displayName'] = display_name |
| 226 | + if username: |
| 227 | + data['username'] = username |
| 228 | + if color_scheme: |
| 229 | + data['colorScheme'] = color_scheme |
| 230 | + response = self.api.put('account/me', |
| 231 | + data=data) |
| 232 | + return Response.de_json(response) |
| 233 | + |
| 234 | + def set_username(self, username: str) -> Response: |
| 235 | + """ |
| 236 | + Sets username |
| 237 | +
|
| 238 | + :param username: New username |
| 239 | + :type username: str |
| 240 | +
|
| 241 | +
|
| 242 | + :rtype: :class:`Response` |
| 243 | + """ |
| 244 | + return self.set_info(username=username) |
| 245 | + |
| 246 | + def set_bio(self, bio: str) -> Response: |
| 247 | + """ |
| 248 | + Sets bio |
| 249 | +
|
| 250 | + :param bio: New bio |
| 251 | + :type bio: str |
| 252 | +
|
| 253 | +
|
| 254 | + :rtype: :class:`Response` |
| 255 | + """ |
| 256 | + return self.set_info(bio=bio) |
| 257 | + |
| 258 | + def set_display_name(self, display_name: str) -> Response: |
| 259 | + """ |
| 260 | + Sets name to display |
| 261 | +
|
| 262 | + :param display_name: New name to display |
| 263 | + :type display_name: str |
| 264 | +
|
| 265 | +
|
| 266 | + :rtype: :class:`Response` |
| 267 | + """ |
| 268 | + return self.set_info(display_name=display_name) |
| 269 | + |
| 270 | + def set_color_scheme(self, color_scheme: int) -> Response: |
| 271 | + """ |
| 272 | + Sets color scheme |
| 273 | +
|
| 274 | + :param color_scheme: Id of new color scheme |
| 275 | + :type color_scheme: str |
| 276 | +
|
| 277 | +
|
| 278 | + :rtype: :class:`Response` |
| 279 | + """ |
| 280 | + return self.set_info(color_scheme=color_scheme) |
0 commit comments