Skip to content

Commit

Permalink
Merge pull request #330 from ingwinlu/add_kraken_api_key
Browse files Browse the repository at this point in the history
Add Client-Id
  • Loading branch information
ingwinlu committed Jul 13, 2016
2 parents d361945 + e822833 commit 2a13b90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/test_api_usher.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_vod(self):
('c5928479', '/cobaltstreak/c/5928479')
]

@unittest.skip("skipping legacy video tests as our samples are no longer available")
def test_legacy_videos():
for id, path in legacy_video_mapping:
yield check_video, id, path
Expand Down
8 changes: 5 additions & 3 deletions tests/test_api_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_root(self):
u'teams': u'https://api.twitch.tv/kraken/teams',
u'user': u'https://api.twitch.tv/kraken/user'
},
u'identified': True,
u'token': {
u'authorization': None,
u'valid': False
Expand Down Expand Up @@ -156,7 +157,7 @@ class TestApiV3Videos(unittest.TestCase):
u'_links', u'fps', u'broadcast_id', u'broadcast_type',
u'preview', u'resolutions', u'_id', u'created_at',
u'channel']
test_video = 'c6055863'
test_video = 'v77655920'

def test_by_name(self):
result = twitch.videos.by_id(self.test_video).keys()
Expand All @@ -174,7 +175,8 @@ def test_by_channel(self):


class TestApiV3Games(unittest.TestCase):
game_keys = [u'name', u'box', u'logo', u'_links', u'_id', u'giantbomb_id']
game_keys = [u'name', u'box', u'logo', u'_links', u'_id',
u'giantbomb_id', u'popularity']

def test_top(self):
result = twitch.games.top().get('top')[0].get('game')
Expand All @@ -196,7 +198,7 @@ def test_streams(self):

def test_games(self):
result = twitch.search.games('starcraft').get('games')[0].keys()
six.assertCountEqual(self, result, TestApiV3Games.game_keys + [u'popularity'])
six.assertCountEqual(self, result, TestApiV3Games.game_keys)


class TestApiV3Follows(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import-order-style=cryptography
[testenv:flake8]
basepython = python2.7
deps =
flake8 <= 2.4.1
git+https://github.com/public/flake8-import-order@2ac7052a4e02b4a8a0125a106d87465a3b9fd688
flake8
flake8-import-order
commands =
flake8 --version
flake8 twitch
1 change: 1 addition & 0 deletions twitch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-

VERSION = '1.2.0'
CLIENT_ID = 'conc17x2vpauvp2youhs3legi90c6jx'
14 changes: 8 additions & 6 deletions twitch/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

from six.moves.urllib.parse import urljoin

from twitch import CLIENT_ID
from twitch.exceptions import ResourceUnavailableException
from twitch.logging import log
from twitch.scraper import download, get_json

_api_baseurl = 'https://api.twitch.tv/kraken/'
_hidden_api_baseurl = 'http://api.twitch.tv/api/'
_kraken_baseurl = 'https://api.twitch.tv/kraken/'
_hidden_baseurl = 'http://api.twitch.tv/api/'
_usher_baseurl = 'http://usher.twitch.tv/'

_v2_headers = {'ACCEPT': 'application/vnd.twitchtv.v2+json'}
Expand Down Expand Up @@ -67,25 +68,26 @@ def execute(self, f):

class DownloadQuery(_Query):
def execute(self):
# TODO implement download completly here
# TODO implement download completely here
return super(DownloadQuery, self).execute(download)


class JsonQuery(_Query):
def execute(self):
# TODO implement get_json completly here
# TODO implement get_json completely here
return super(JsonQuery, self).execute(get_json)


class ApiQuery(JsonQuery):
def __init__(self, path, headers={}):
super(ApiQuery, self).__init__(_api_baseurl, headers)
headers.setdefault('Client-Id', CLIENT_ID)
super(ApiQuery, self).__init__(_kraken_baseurl, headers)
self.add_path(path)


class HiddenApiQuery(JsonQuery):
def __init__(self, path, headers={}):
super(HiddenApiQuery, self).__init__(_hidden_api_baseurl, headers)
super(HiddenApiQuery, self).__init__(_hidden_baseurl, headers)
self.add_path(path)


Expand Down

0 comments on commit 2a13b90

Please sign in to comment.