refactor: move api calls to routes folder; feat: add update_banner user-friendly method; fix: change file data type
This commit is contained in:
19
itd/routes/comments.py
Normal file
19
itd/routes/comments.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from itd.request import fetch
|
||||
|
||||
def add_comment(token: str, post_id: str, content: str, reply_comment_id: str | None = None):
|
||||
data = {'content': content}
|
||||
if reply_comment_id:
|
||||
data['replyTo'] = str(reply_comment_id)
|
||||
return fetch(token, 'post', f'posts/{post_id}/comments', data)
|
||||
|
||||
def get_comments(token: str, post_id: str, limit: int = 20, cursor: int = 0, sort: str = 'popular'):
|
||||
return fetch(token, 'get', f'posts/{post_id}/comments', {'limit': limit, 'sort': sort, 'cursor': cursor})
|
||||
|
||||
def like_comment(token: str, comment_id: str):
|
||||
return fetch(token, 'post', f'comments/{comment_id}/like')
|
||||
|
||||
def unlike_comment(token: str, comment_id: str):
|
||||
return fetch(token, 'delete', f'comments/{comment_id}/like')
|
||||
|
||||
def delete_comment(token: str, comment_id: str):
|
||||
return fetch(token, 'delete', f'comments/{comment_id}')
|
||||
10
itd/routes/etc.py
Normal file
10
itd/routes/etc.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from itd.request import fetch
|
||||
|
||||
def get_top_clans(token: str):
|
||||
return fetch(token, 'get', 'users/stats/top-clans')
|
||||
|
||||
def get_who_to_follow(token: str):
|
||||
return fetch(token, 'get', 'users/suggestions/who-to-follow')
|
||||
|
||||
def get_platform_status(token: str):
|
||||
return fetch(token, 'get', 'platform/status')
|
||||
7
itd/routes/files.py
Normal file
7
itd/routes/files.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from _io import BufferedReader
|
||||
|
||||
from itd.request import fetch
|
||||
|
||||
|
||||
def upload_file(token: str, name: str, data: BufferedReader):
|
||||
return fetch(token, 'post', 'files/upload', files={'file': (name, data)})
|
||||
7
itd/routes/hashtags.py
Normal file
7
itd/routes/hashtags.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from itd.request import fetch
|
||||
|
||||
def get_hastags(token: str, limit: int = 10):
|
||||
return fetch(token, 'get', 'hashtags/trending', {'limit': limit})
|
||||
|
||||
def get_posts_by_hastag(token: str, hashtag: str, limit: int = 20, cursor: int = 0):
|
||||
return fetch(token, 'get', f'hashtags/{hashtag}/posts', {'limit': limit, 'cursor': cursor})
|
||||
16
itd/routes/notifications.py
Normal file
16
itd/routes/notifications.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from itd.request import fetch
|
||||
|
||||
def get_notifications(token: str, limit: int = 20, cursor: int = 0, type: str | None = None):
|
||||
data = {'limit': str(limit), 'cursor': str(cursor)}
|
||||
if type:
|
||||
data['type'] = type
|
||||
return fetch(token, 'get', 'notifications', data)
|
||||
|
||||
def mark_as_read(token: str, id: str):
|
||||
return fetch(token, 'post', f'notification/{id}/read')
|
||||
|
||||
def mark_all_as_read(token: str):
|
||||
return fetch(token, 'post', f'notification/read-all')
|
||||
|
||||
def get_unread_notifications_count(token: str):
|
||||
return fetch(token, 'get', 'notifications/count')
|
||||
42
itd/routes/posts.py
Normal file
42
itd/routes/posts.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from itd.request import fetch
|
||||
|
||||
def create_post(token: str, content: str, wall_recipient_id: int | None = None, attach_ids: list[str] = []):
|
||||
data: dict = {'content': content}
|
||||
if wall_recipient_id:
|
||||
data['wallRecipientId'] = wall_recipient_id
|
||||
if attach_ids:
|
||||
data['attachmentIds'] = attach_ids
|
||||
|
||||
return fetch(token, 'post', 'posts', data)
|
||||
|
||||
def get_posts(token: str, username: str | None = None, limit: int = 20, cursor: int = 0, sort: str = '', tab: str = ''):
|
||||
data: dict = {'limit': limit, 'cursor': cursor}
|
||||
if username:
|
||||
data['username'] = username
|
||||
if sort:
|
||||
data['sort'] = sort
|
||||
if tab:
|
||||
data['tab'] = tab
|
||||
|
||||
return fetch(token, 'get', 'posts', data)
|
||||
|
||||
def get_post(token: str, id: str):
|
||||
return fetch(token, 'get', f'posts/{id}')
|
||||
|
||||
def edit_post(token: str, id: str, content: str):
|
||||
return fetch(token, 'put', f'posts/{id}', {'content': content})
|
||||
|
||||
def delete_post(token: str, id: str):
|
||||
return fetch(token, 'delete', f'posts/{id}')
|
||||
|
||||
def pin_post(token: str, id: str):
|
||||
return fetch(token, 'post', f'posts/{id}/pin')
|
||||
|
||||
def repost(token: str, id: str, content: str | None = None):
|
||||
data = {}
|
||||
if content:
|
||||
data['content'] = content
|
||||
return fetch(token, 'post', f'posts/{id}/repost', data)
|
||||
|
||||
def view_post(token: str, id: str):
|
||||
return fetch(token, 'post', f'posts/{id}/view')
|
||||
4
itd/routes/reports.py
Normal file
4
itd/routes/reports.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from itd.request import fetch
|
||||
|
||||
def report(token: str, id: str, type: str = 'post', reason: str = 'other', description: str = ''):
|
||||
return fetch(token, 'post', 'reports', {'targetId': id, 'targetType': type, 'reason': reason, 'description': description})
|
||||
4
itd/routes/search.py
Normal file
4
itd/routes/search.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from itd.request import fetch
|
||||
|
||||
def search(token: str, query: str, user_limit: int = 5, hashtag_limit: int = 5):
|
||||
return fetch(token, 'get', 'search', {'userLimit': user_limit, 'hashtagLimit': hashtag_limit, 'q': query})
|
||||
29
itd/routes/users.py
Normal file
29
itd/routes/users.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from itd.request import fetch
|
||||
|
||||
|
||||
def get_user(token: str, username: str):
|
||||
return fetch(token, 'get', f'users/{username}')
|
||||
|
||||
def update_profile(token: str, bio: str | None = None, display_name: str | None = None, username: str | None = None, banner_id: str | None = None):
|
||||
data = {}
|
||||
if bio:
|
||||
data['bio'] = bio
|
||||
if display_name:
|
||||
data['displayName'] = display_name
|
||||
if username:
|
||||
data['username'] = username
|
||||
if banner_id:
|
||||
data['bannerId'] = banner_id
|
||||
return fetch(token, 'put', 'users/me', data)
|
||||
|
||||
def follow(token: str, username: str):
|
||||
return fetch(token, 'post', f'users/{username}/follow')
|
||||
|
||||
def unfollow(token: str, username: str):
|
||||
return fetch(token, 'delete', f'users/{username}/follow')
|
||||
|
||||
def get_followers(token: str, username: str, limit: int = 30, page: int = 1):
|
||||
return fetch(token, 'get', f'users/{username}/followers', {'limit': limit, 'page': page})
|
||||
|
||||
def get_following(token: str, username: str, limit: int = 30, page: int = 1):
|
||||
return fetch(token, 'get', f'users/{username}/following', {'limit': limit, 'page': page})
|
||||
Reference in New Issue
Block a user