Skip to content

Commit 58f01ee

Browse files
committed
[v5] add missing end-points to communities, descriptive function naming
1 parent 66d6e47 commit 58f01ee

2 files changed

Lines changed: 147 additions & 8 deletions

File tree

Lines changed: 140 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,161 @@
11
# -*- encoding: utf-8 -*-
22
# https://dev.twitch.tv/docs/v5/reference/communities/
33

4-
from twitch import keys
4+
from twitch import keys, methods
55
from twitch.api.parameters import Cursor
66
from twitch.queries import V5Query as Qry
77
from twitch.queries import query
88

99

1010
@query
11-
def top(limit=10, cursor='MA=='):
11+
def get_community_by_name(name):
12+
q = Qry('communities')
13+
q.add_param(keys.NAME, name)
14+
return q
15+
16+
17+
@query
18+
def get_community_by_id(community_id):
19+
q = Qry('communities/{community_id}')
20+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
21+
return q
22+
23+
24+
@query
25+
def update_community(community_id, summary=None, description=None,
26+
rules=None, email=None):
27+
q = Qry('communities/{community_id}', method=methods.PUT)
28+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
29+
q.add_data(keys.SUMMARY, summary)
30+
q.add_data(keys.DESCRIPTION, description)
31+
q.add_data(keys.RULES, rules)
32+
q.add_data(keys.EMAIL, email)
33+
return q
34+
35+
36+
@query
37+
def get_top_communities(limit=10, cursor='MA=='):
1238
q = Qry('communities/top')
1339
q.add_param(keys.LIMIT, limit, 10)
1440
q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==')
1541
return q
1642

1743

1844
@query
19-
def by_name(name):
20-
q = Qry('communities')
21-
q.add_param(keys.NAME, name)
45+
def get_community_bans(community_id, limit=10, cursor='MA=='):
46+
q = Qry('communities/{community_id}/bans')
47+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
48+
q.add_param(keys.LIMIT, limit, 10)
49+
q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==')
50+
return q
51+
52+
53+
@query
54+
def ban_community_user(community_id, user_id):
55+
q = Qry('communities/{community_id}/bans/{user_id}', method=methods.PUT)
56+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
57+
q.add_urlkw(keys.USER_ID, user_id)
58+
return q
59+
60+
61+
@query
62+
def unban_community_user(community_id, user_id):
63+
q = Qry('communities/{community_id}/bans/{user_id}', method=methods.DELETE)
64+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
65+
q.add_urlkw(keys.USER_ID, user_id)
66+
return q
67+
68+
69+
@query
70+
def create_community_avatar(community_id, avatar_image):
71+
q = Qry('communities/{community_id}/images/avatar', method=methods.POST)
72+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
73+
q.add_urlkw(keys.AVATAR_IMAGE, avatar_image)
74+
return q
75+
76+
77+
@query
78+
def delete_community_avatar(community_id):
79+
q = Qry('communities/{community_id}/images/avatar', method=methods.DELETE)
80+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
81+
return q
82+
83+
84+
@query
85+
def create_community_cover(community_id, cover_image):
86+
q = Qry('communities/{community_id}/images/cover', method=methods.POST)
87+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
88+
q.add_urlkw(keys.COVER_IMAGE, cover_image)
89+
return q
90+
91+
92+
@query
93+
def delete_community_cover(community_id):
94+
q = Qry('communities/{community_id}/images/cover', method=methods.DELETE)
95+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
96+
return q
97+
98+
99+
@query
100+
def get_community_moderators(community_id):
101+
q = Qry('communities/{community_id}/moderators')
102+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
103+
return q
104+
105+
106+
@query
107+
def add_community_moderator(community_id, user_id):
108+
q = Qry('communities/{community_id}/moderators/{user_id}', method=methods.PUT)
109+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
110+
q.add_urlkw(keys.USER_ID, user_id)
111+
return q
112+
113+
114+
@query
115+
def delete_community_moderator(community_id, user_id):
116+
q = Qry('communities/{community_id}/moderators/{user_id}', method=methods.DELETE)
117+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
118+
q.add_urlkw(keys.USER_ID, user_id)
119+
return q
120+
121+
122+
@query
123+
def get_community_permissions(community_id):
124+
q = Qry('communities/{community_id}/permissions')
125+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
126+
return q
127+
128+
129+
@query
130+
def report_community_violation(community_id, channel_id):
131+
q = Qry('communities/{community_id}/report_channel', method=methods.POST)
132+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
133+
q.add_data(keys.CHANNEL_ID, channel_id)
134+
return q
135+
136+
137+
@query
138+
def get_community_timeouts(community_id, limit=10, cursor='MA=='):
139+
q = Qry('communities/{community_id}/timeouts')
140+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
141+
q.add_param(keys.LIMIT, limit, 10)
142+
q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==')
143+
return q
144+
145+
146+
@query
147+
def add_community_timeout(community_id, user_id, duration=1, reason=None):
148+
q = Qry('communities/{community_id}/timeouts/{user_id}', method=methods.PUT)
149+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
150+
q.add_urlkw(keys.USER_ID, user_id)
151+
q.add_data(keys.DURATION, duration)
152+
q.add_data(keys.REASON, reason)
22153
return q
23154

24155

25156
@query
26-
def by_id(community_id):
27-
q = Qry('communities/{id}')
28-
q.add_urlkw(keys.ID, community_id)
157+
def delete_community_timeout(community_id, user_id):
158+
q = Qry('communities/{community_id}/timeouts/{user_id}', method=methods.DELETE)
159+
q.add_urlkw(keys.COMMUNITY_ID, community_id)
160+
q.add_urlkw(keys.USER_ID, user_id)
29161
return q

resources/lib/twitch/keys.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
ALLOW_SOURCE = 'allow_source'
99
ALLOW_SPECTRE = 'allow_spectre'
10+
AVATAR_IMAGE = 'avatar_image'
1011
BROADCAST_TYPE = 'broadcast_type'
1112
BROADCASTS = 'broadcasts'
1213
CHANNEL = 'channel'
@@ -19,11 +20,14 @@
1920
COMMUNITY_ID = 'community_id'
2021
CONTAINING_ITEM = 'containing_item'
2122
CONTENT = 'content'
23+
COVER_IMAGE = 'cover_image'
2224
CURSOR = 'cursor'
2325
CLIENT_ID = 'client_id'
2426
DELAY = 'delay'
27+
DESCRIPTION = 'description'
2528
DIRECTION = 'direction'
2629
DURATION = 'duration'
30+
EMAIL = 'email'
2731
EMOTE_ID = 'emote_id'
2832
EMOTESETS = 'emotesets'
2933
ERROR = 'error'
@@ -48,12 +52,15 @@
4852
POSITION = 'position'
4953
POST_ID = 'post_id'
5054
QUERY = 'query'
55+
REASON = 'reason'
56+
RULES = 'rules'
5157
SHARE = 'share'
5258
SIG = 'sig'
5359
SORT = 'sort'
5460
SORT_BY = 'sortby'
5561
STATUS = 'status'
5662
STREAM_TYPE = 'stream_type'
63+
SUMMARY = 'summary'
5764
TARGET = 'target'
5865
TEAM = 'team'
5966
TITLE = 'title'

0 commit comments

Comments
 (0)