Skip to content

Commit 006a1dd

Browse files
committed
add Cursor to parameters for validation
1 parent 85c18ef commit 006a1dd

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

resources/lib/twitch/api/parameters.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- encoding: utf-8 -*-
2+
from base64 import b64decode
23

34

45
class _Parameter(object):
@@ -62,3 +63,13 @@ class StreamType(_Parameter):
6263
ALL = 'all'
6364

6465
_valid = [LIVE, PLAYLIST, ALL]
66+
67+
68+
class Cursor(_Parameter):
69+
@classmethod
70+
def validate(cls, value):
71+
try:
72+
decoded = int(b64decode(value))
73+
return value
74+
except ValueError:
75+
raise ValueError(value)

resources/lib/twitch/api/v5/channel_feed.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# https://dev.twitch.tv/docs/v5/reference/channel-feed/
33

44
from twitch import keys
5-
from twitch.api.parameters import Boolean
5+
from twitch.api.parameters import Boolean, Cursor
66
from twitch import methods
77
from twitch.queries import V5Query as Qry
88
from twitch.queries import query
99

1010

1111
@query
12-
def get_posts(channel_id, limit=10, cursor=0, comments=5):
12+
def get_posts(channel_id, limit=10, cursor='MA==', comments=5):
1313
q = Qry('feed/{channel_id}/posts')
1414
q.add_urlkw(keys.CHANNEL_ID, channel_id)
1515
q.add_param(keys.LIMIT, limit, 10)
16-
q.add_param(keys.CURSOR, cursor, 0)
16+
q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==')
1717
q.add_param(keys.COMMENTS, comments, 5)
1818
return q
1919

@@ -63,12 +63,12 @@ def delete_post_reaction(channel_id, post_id, emote_id):
6363

6464

6565
@query
66-
def get_comments(channel_id, post_id, limit=10, cursor=0):
66+
def get_comments(channel_id, post_id, limit=10, cursor='MA=='):
6767
q = Qry('feed/{channel_id}/posts/{post_id}/comments')
6868
q.add_urlkw(keys.CHANNEL_ID, channel_id)
6969
q.add_urlkw(keys.POST_ID, post_id)
7070
q.add_param(keys.LIMIT, limit, 10)
71-
q.add_param(keys.CURSOR, cursor, 0)
71+
q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==')
7272
return q
7373

7474

resources/lib/twitch/api/v5/collections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from twitch import keys
55
from twitch.queries import V5Query as Qry
66
from twitch.queries import query
7-
from twitch.api.parameters import Boolean
7+
from twitch.api.parameters import Boolean, Cursor
88
from twitch import methods
99

1010

@@ -24,11 +24,11 @@ def get_collection(collection_id, include_all=Boolean.FALSE):
2424

2525

2626
@query
27-
def get_collections(channel_id, limit=10, cursor=0, containing_item=None):
27+
def get_collections(channel_id, limit=10, cursor='MA==', containing_item=None):
2828
q = Qry('channels/{channel_id}/collections')
2929
q.add_urlkw(keys.CHANNEL_ID, channel_id)
3030
q.add_param(keys.LIMIT, limit, 10)
31-
q.add_param(keys.CURSOR, cursor, 0)
31+
q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==')
3232
q.add_param(keys.CONTAINING_ITEM, containing_item, None) # 'video:<video_id>'
3333
return q
3434

resources/lib/twitch/api/v5/communities.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
# https://dev.twitch.tv/docs/v5/reference/communities/
33

44
from twitch import keys
5+
from twitch.api.parameters import Cursor
56
from twitch.queries import V5Query as Qry
67
from twitch.queries import query
78

89

910
@query
10-
def top(limit=10, cursor=0):
11+
def top(limit=10, cursor='MA=='):
1112
q = Qry('communities/top')
1213
q.add_param(keys.LIMIT, limit, 10)
13-
q.add_param(keys.CURSOR, cursor, 0)
14+
q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==')
1415
return q
1516

1617

0 commit comments

Comments
 (0)