def by_channel(name, limit=10, offset=0, broadcasts=Boolean.FALSE, hls=Boolean.FALSE): q = Qry('channels/{channel}/videos') q.add_urlkw(keys.CHANNEL, name) q.add_param(keys.LIMIT, limit, 10) q.add_param(keys.OFFSET, offset, 0) q.add_param(keys.BROADCASTS, Boolean.validate(broadcasts), Boolean.FALSE) q.add_param(keys.HLS, Boolean.validate(hls), Boolean.FALSE) return q
def follow_channel(user_id, channel_id, notifications=Boolean.FALSE): q = Qry('users/{user_id}/follows/channels/{channel_id}', method=methods.PUT) q.add_urlkw(keys.USER_ID, user_id) q.add_urlkw(keys.CHANNEL_ID, channel_id) q.add_data(keys.NOTIFICATIONS, Boolean.validate(notifications), Boolean.FALSE) return q
def get_followed(trending=Boolean.FALSE, language=Language.ALL, cursor='MA==', limit=10): q = Qry('clips/followed') q.add_param(keys.TRENDING, Boolean.validate(trending), Boolean.FALSE) q.add_param(keys.LANGUAGE, Language.validate(language), Language.ALL) q.add_param(keys.LIMIT, limit, 10) q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==') return q
def get_videos(channel_id, limit=10, offset=0, broadcast_type=BroadcastType.HIGHLIGHT, hls=Boolean.FALSE, sort_by=VideoSort.TIME, language=Language.ALL): q = Qry('channels/{id}/videos') q.add_urlkw(keys.ID, channel_id) q.add_param(keys.LIMIT, limit, 10) q.add_param(keys.OFFSET, offset, 0) q.add_param(keys.BROADCAST_TYPE, BroadcastType.validate(broadcast_type)) q.add_param(keys.SORT, VideoSort.validate(sort_by), VideoSort.TIME) q.add_param(keys.LANGUAGE, Language.validate(language), Language.ALL) q.add_param(keys.HLS, Boolean.validate(hls), Boolean.FALSE) return q
def get_top(channels=None, games=None, period=ClipPeriod.WEEK, trending=Boolean.FALSE, language=Language.ALL, cursor='MA==', limit=10): q = Qry('clips/top') q.add_param(keys.CHANNEL, channels, None) q.add_param(keys.GAME, games, None) q.add_param(keys.PERIOD, ClipPeriod.validate(period), ClipPeriod.WEEK) q.add_param(keys.TRENDING, Boolean.validate(trending), Boolean.FALSE) q.add_param(keys.LANGUAGE, Language.validate(language), Language.ALL) q.add_param(keys.LIMIT, limit, 10) q.add_param(keys.CURSOR, Cursor.validate(cursor), 'MA==') return q
def update(channel_id, status=None, game=None, delay=None, channel_feed_enabled=None): q = Qry('channels/{channel_id}', method=methods.PUT) q.add_urlkw(keys.CHANNEL_ID, channel_id) channel = {} if status is not None: channel[keys.STATUS] = status if game is not None: channel[keys.GAME] = game if delay is not None: channel[keys.DELAY] = delay if channel_feed_enabled is not None: channel[keys.CHANNEL_FEED_ENABLED] = Boolean.validate( channel_feed_enabled) q.add_data(keys.CHANNEL, channel) return q
def test_boolean(self): Boolean.validate(Boolean.TRUE) Boolean.validate(Boolean.FALSE) Boolean.validate('true') Boolean.validate('false') with self.assertRaises(ValueError): Boolean.validate(True) with self.assertRaises(ValueError): Boolean.validate(False) with self.assertRaises(ValueError): Boolean.validate('')
def create_post(channel_id, content, share=Boolean.FALSE): q = Qry('feed/{channel_id}/posts/', method=methods.POST) q.add_urlkw(keys.CHANNEL_ID, channel_id) q.add_param(keys.SHARE, Boolean.validate(share)) q.add_data(keys.CONTENT, content) return q
def by_id(collection_id, include_all=Boolean.FALSE): q = Qry('collections/{collection_id}/items', use_token=False) q.add_urlkw(keys.COLLECTION_ID, collection_id) q.add_param(keys.INCLUDE_ALL_ITEMS, Boolean.validate(include_all), Boolean.FALSE) return q