Esempio n. 1
0
    def channels(self, query, limit=25, offset=0):
        if limit > 100:
            raise TwitchAttributeException(
                "Maximum number of objects returned in one request is 100")

        params = {"query": query, "limit": limit, "offset": offset}
        response = self._request_get("search/channels", params=params)
        return [Channel.construct_from(x) for x in response["channels"] or []]
Esempio n. 2
0
    def channels(self, query, limit=25, offset=0):
        if limit > 100:
            raise TwitchAttributeException(
                'Maximum number of objects returned in one request is 100')

        params = {'query': query, 'limit': limit, 'offset': offset}
        response = self._request_get('search/channels', params=params)
        return [Channel.construct_from(x) for x in response['channels'] or []]
Esempio n. 3
0
    def update(self, channel_id, status=None, game=None, delay=None, channel_feed_enabled=None):
        data = {}
        if status is not None:
            data['status'] = status
        if game is not None:
            data['game'] = game
        if delay is not None:
            data['delay'] = delay
        if channel_feed_enabled is not None:
            data['channel_feed_enabled'] = channel_feed_enabled

        post_data = {
            'channel': data
        }
        response = self._request_put('channels/{}'.format(channel_id), post_data)
        return Channel.construct_from(response)
Esempio n. 4
0
    def update(
        self, channel_id, status=None, game=None, delay=None, channel_feed_enabled=None
    ):
        data = {}
        if status is not None:
            data["status"] = status
        if game is not None:
            data["game"] = game
        if delay is not None:
            data["delay"] = delay
        if channel_feed_enabled is not None:
            data["channel_feed_enabled"] = channel_feed_enabled

        post_data = {"channel": data}
        response = self._request_put("channels/{}".format(channel_id), post_data)
        return Channel.construct_from(response)
    def test_announce_raid(self):
        with mock.patch(
                "dragonmanbot.twitchuser.TwitchUserRepository.findByUsername"
        ) as mocked_return:
            with mock.patch(
                    'dragonmanbot.twitch_http_client.channels.get_by_id'
            ) as mocked_http_return:
                mocked_return.return_value = twitchuser.TwitchUser(
                    username="******", gold=100)
                mocked_http_return.return_value = Channel.construct_from(
                    json.loads(
                        '{"display_name": "testuser", "game": "Cool Game"}'))
                message = "@badges=premium/1;color=#00FF7F;display-name=testuser;emotes=;flags=;id=7532d5b2-ddeb-4e85-992a-999999999999;login=testuser;mod=0;msg-id=raid;msg-param-displayName=testuser;msg-param-login=testuser;msg-param-profileImageURL=https://static-cdn.jtvnw.net/jtv_user_pictures/85896964-219d-4a32-837e-999999999999-profile_image-70x70.jpg;msg-param-viewerCount=7;room-id=68573026;subscriber=0;system-msg=7\sraiders\sfrom\testuser\shave\sjoined\n!;tmi-sent-ts=1547441871162;turbo=0;user-id=999999;user-type= :tmi.twitch.tv USERNOTICE #dragonmantank"
                response = listener.announce_raid({
                    "username": "",
                    "message": "",
                    "raw": message
                })

                self.assertEqual(
                    "testuser was playing \"Cool Game\" and is raiding with 7 viewers! Show some love and check them out some time! https://twitch.tv/testuser",
                    response)
Esempio n. 6
0
    sensor.DOMAIN: {
        "platform": "twitch",
        CONF_CLIENT_ID: "1234",
        "channels": ["channel123"],
        "token": "9876",
    }
}

USER_ID = User({"id": 123, "display_name": "channel123", "logo": "logo.png"})
STREAM_OBJECT_ONLINE = Stream(
    {
        "channel": {"game": "Good Game", "status": "Title"},
        "preview": {"medium": "stream-medium.png"},
    }
)
CHANNEL_OBJECT = Channel({"followers": 42, "views": 24})
OAUTH_USER_ID = User({"id": 987})
SUB_ACTIVE = Subscription({"created_at": "2020-01-20T21:22:42", "is_gift": False})
FOLLOW_ACTIVE = Follow({"created_at": "2020-01-20T21:22:42"})


async def test_init(hass):
    """Test initial config."""

    channels = MagicMock()
    channels.get_by_id.return_value = CHANNEL_OBJECT
    streams = MagicMock()
    streams.get_stream_by_user.return_value = None

    twitch_mock = MagicMock()
    twitch_mock.users.translate_usernames_to_ids.return_value = [USER_ID]
Esempio n. 7
0
 def get_by_id(self, channel_id):
     response = self._request_get('channels/{}'.format(channel_id))
     return Channel.construct_from(response)
Esempio n. 8
0
 def reset_stream_key(self, channel_id):
     response = self._request_delete('channels/{}/stream_key'.format(channel_id))
     return Channel.construct_from(response)
Esempio n. 9
0
 def get(self):
     response = self._request_get('channel')
     return Channel.construct_from(response)
Esempio n. 10
0
 def get_by_id(self, channel_id):
     response = self._request_get('channels/%s' % channel_id)
     return Channel.construct_from(response)
Esempio n. 11
0
 def reset_stream_key(self, channel_id):
     response = self._request_delete('channels/%s/stream_key' % channel_id)
     return Channel.construct_from(response)