Skip to content

Commit

Permalink
Implement twitch.api.v3.chat
Browse files Browse the repository at this point in the history
  • Loading branch information
ingwinlu committed Oct 2, 2015
1 parent d991812 commit 2a67dde
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_api_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions twitch/api/v3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions twitch/api/v3/chat.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2a67dde

Please sign in to comment.