|
| 1 | +# -*- encoding: utf-8 -*- |
| 2 | +# https://github.com/justintv/Twitch-API/blob/master/v3_resources/follows.md |
| 3 | + |
| 4 | +from twitch import keys |
| 5 | +from twitch.api.parameters import Direction, SortBy |
| 6 | +from twitch.queries import V5Query as Qry |
| 7 | +from twitch.queries import query |
| 8 | +from twitch.api.parameters import Boolean |
| 9 | + |
| 10 | + |
| 11 | +@query |
| 12 | +def by_channel(name, limit=25, offset=0, direction=Direction.DESC): |
| 13 | + q = Qry('channels/{channel}/follows') |
| 14 | + q.add_urlkw(keys.CHANNEL, name) |
| 15 | + q.add_param(keys.LIMIT, limit, 25) |
| 16 | + q.add_param(keys.OFFSET, offset, 0) |
| 17 | + q.add_param(keys.DIRECTION, direction, Direction.DESC) |
| 18 | + return q |
| 19 | + |
| 20 | + |
| 21 | +@query |
| 22 | +def by_id(identification, limit=25, offset=0, direction=Direction.DESC, |
| 23 | + sort_by=SortBy.CREATED_AT): |
| 24 | + q = Qry('users/{id}/follows/channels') |
| 25 | + q.add_urlkw(keys.ID, identification) |
| 26 | + q.add_param(keys.LIMIT, limit, 25) |
| 27 | + q.add_param(keys.OFFSET, offset, 0) |
| 28 | + q.add_param(keys.DIRECTION, direction, Direction.DESC) |
| 29 | + q.add_param(keys.SORT_BY, sort_by, SortBy.CREATED_AT) |
| 30 | + return q |
| 31 | + |
| 32 | + |
| 33 | +@query |
| 34 | +def status(identification, target): |
| 35 | + q = Qry('users/{id}/follows/channels/{target}') |
| 36 | + q.add_urlkw(keys.ID, identification) |
| 37 | + q.add_urlkw(keys.TARGET, target) |
| 38 | + return q |
| 39 | + |
| 40 | + |
| 41 | +# Needs Auth, needs PUT |
| 42 | +@query |
| 43 | +def follow(identification, target, notification=Boolean.FALSE): |
| 44 | + q = Qry('users/{id}/follows/channels/{target}', method='PUT') |
| 45 | + q.add_urlkw(keys.ID, identification) |
| 46 | + q.add_urlkw(keys.TARGET, target) |
| 47 | + q.add_data('notification', notification) |
| 48 | + return q |
| 49 | + |
| 50 | + |
| 51 | +# Needs Auth, needs DELETE |
| 52 | +@query |
| 53 | +def unfollow(identification, target): |
| 54 | + q = Qry('users/{id}/follows/channels/{target}', method='DELETE') |
| 55 | + q.add_urlkw(keys.ID, identification) |
| 56 | + q.add_urlkw(keys.TARGET, target) |
| 57 | + return q |
| 58 | + |
| 59 | +# Needs Auth |
| 60 | +@query |
| 61 | +def streams(): |
| 62 | + raise NotImplementedError |
0 commit comments