diff --git a/tests/test_api_v3.py b/tests/test_api_v3.py index 3e6d285..40cae2d 100644 --- a/tests/test_api_v3.py +++ b/tests/test_api_v3.py @@ -5,6 +5,8 @@ from twitch.api import v3 as twitch from twitch.exceptions import ResourceUnavailableException +from . import ci + class TestApiV3Root(unittest.TestCase): def test_root(self): @@ -257,3 +259,27 @@ def test_add_block(self): def test_del_block(self): with self.assertRaises(NotImplementedError): twitch.blocks.del_block('a', 'b') + + +class TestApiV3Chat(unittest.TestCase): + + def test_channel(self): + r = twitch.chat.by_channel(TestApiV3Channels.channel_name) + expected = { + u'_links': { + u'emoticons': u'https://api.twitch.tv/kraken/chat/test_channel/emoticons', + u'self': u'https://api.twitch.tv/kraken/chat/test_channel', + u'badges': u'https://api.twitch.tv/kraken/chat/test_channel/badges' + } + } + self.assertEqual(r, expected) + + def test_badges(self): + r1 = twitch.chat.badges(TestApiV3Channels.channel_name) + r2 = twitch.chat.badges('tornis') + self.assertNotEqual(r1,r2) + + @unittest.skipIf(ci, "skip on ci since answer is not paginated") + def test_emoticons(self): + e = twitch.chat.emoticons()['emoticons'] + self.assertGreaterEqual(len(e), 36306) diff --git a/twitch/api/v3/__init__.py b/twitch/api/v3/__init__.py index 6dcc652..c609b44 100644 --- a/twitch/api/v3/__init__.py +++ b/twitch/api/v3/__init__.py @@ -3,6 +3,7 @@ from twitch.api.v3 import blocks # NOQA from twitch.api.v3 import channels # NOQA +from twitch.api.v3 import chat # NOQA from twitch.api.v3 import follows # NOQA from twitch.api.v3 import games # NOQA from twitch.api.v3 import search # NOQA diff --git a/twitch/api/v3/chat.py b/twitch/api/v3/chat.py new file mode 100644 index 0000000..049dde7 --- /dev/null +++ b/twitch/api/v3/chat.py @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +# https://github.com/justintv/Twitch-API/blob/master/v3_resources/chat.md + +from twitch import keys +from twitch.queries import V3Query as Qry +from twitch.queries import query + + +@query +def by_channel(name): + q = Qry('chat/{channel}') + q.add_urlkw(keys.CHANNEL, name) + return q + + +@query +def badges(name): + q = Qry('chat/{channel}/badges') + q.add_urlkw(keys.CHANNEL, name) + return q + + +@query +def emoticons(): + q = Qry('chat/emoticons') + return q