├── .editorconfig ├── .gitignore ├── changelog.md ├── composer.json ├── composer.lock ├── config └── twitch-api.php ├── docs ├── api.md ├── authentication.md ├── blocks.md ├── channels.md ├── chat.md ├── clips.md ├── follow.md ├── games.md ├── ingests.md ├── readme.md ├── root.md ├── search.md ├── streams.md ├── subscriptions.md ├── teams.md ├── users.md └── videos.md ├── license ├── readme.md └── src ├── API ├── Api.php ├── Authentication.php ├── Blocks.php ├── Channels.php ├── Chat.php ├── Clips.php ├── Follow.php ├── Games.php ├── Ingests.php ├── Root.php ├── Search.php ├── Streams.php ├── Subscriptions.php ├── Teams.php ├── Users.php └── Videos.php ├── Exceptions ├── RequestRequiresAuthenticationException.php └── RequestRequiresClientIdException.php ├── Facades └── TwitchApiServiceFacade.php ├── Providers └── TwitchApiServiceProvider.php └── Services └── TwitchApiService.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 4 9 | end_of_line = lf 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | insert_final_newline = false 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /vendor 3 | composer.phar -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.3.6 - 1.5.1 4 | - force-verify fix 5 | - Twitch Clips 6 | - Error handling 7 | - v5 compatability 8 | 9 | ## 1.3.5 10 | - Function name fix. 11 | 12 | ## 1.3.4 13 | 14 | - New function `getAccessObject($code, $state = null)` to retrieve full response object when requesting access_token from Twitch. Use this instead of `getAccessToken($code, $state = null)` which is now deprecated. 15 | 16 | ## 1.3.3 17 | 18 | - Twitch tokens can now be set again. 19 | - Fixes to make updating a channel work properly 20 | 21 | ## 1.3.2 22 | 23 | Improved headers and URL parameters. 24 | 25 | ## 1.3.1 26 | 27 | Small authentication function fixes 28 | 29 | ## 1.3.0 30 | 31 | ### News 32 | 33 | - Use `TwitchApi::getAuthenticationUrl($state, $forceVerify)` to get the redirection url for your users to sign in through Twitch. `$state` and `$forceVerify` are optional, read about them [here](https://github.com/justintv/Twitch-API/blob/master/authentication.md#authorization-code-flow). 34 | - Use `getAccessToken($code)` to retrieve the Twitch token after the user has signed in through Twitch and been redirected back to your application/website. 35 | 36 | ### Fixes 37 | 38 | - `chatBadges($channel)` and `chatEmoticons($channel)` were duplicates. 39 | 40 | ## 1.2.1 41 | 42 | - A client id [is now required](https://blog.twitch.tv/client-id-required-for-kraken-api-calls-afbb8e95f843) for Twitch API calls. Make sure your Twitch client id is set in either `.env` using the `TWITCH_KEY` variable, or directly in `config/twitch-api.php`. 43 | 44 | ## 1.2.0 45 | 46 | - Functions using the $option parameter has been fixed. This had to do with how headers were constructed in HTTP requests to the Twitch API using Guzzle. 47 | - The Twitch API is now using https by default. Replacing http with https is no longer necessary. 48 | 49 | ## 1.1.0 50 | 51 | - Function names are more friendly. 52 | 53 | ## 1.0.1 54 | 55 | - Packagist support 56 | 57 | ## 1.0.0 58 | 59 | - First release 60 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zarlach/laravel-twitch-api", 3 | "description": "Laravel Twitch RESTful API", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Petter Kraabøl", 8 | "email": "petter.zarlach@gmail.com" 9 | } 10 | ], 11 | "autoload": { 12 | "psr-4": { 13 | "Zarlach\\TwitchApi\\": "src" 14 | } 15 | }, 16 | "minimum-stability": "dev", 17 | "require": { 18 | "php": ">=5.5.9", 19 | "guzzlehttp/guzzle": "~6.1" 20 | }, 21 | "require-dev": { 22 | "phpunit/phpunit" : "5.*", 23 | "laravel/laravel": "5.*" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "f30b02388d0d210cdcdc4c24359eb774", 8 | "content-hash": "6f74a28e6a8ad66127e23c100f6dd5c5", 9 | "packages": [ 10 | { 11 | "name": "guzzlehttp/guzzle", 12 | "version": "dev-master", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/guzzle/guzzle.git", 16 | "reference": "4f11935f709ef5e279af9da062507e72bd356e1a" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4f11935f709ef5e279af9da062507e72bd356e1a", 21 | "reference": "4f11935f709ef5e279af9da062507e72bd356e1a", 22 | "shasum": "" 23 | }, 24 | "require": { 25 | "guzzlehttp/promises": "~1.0", 26 | "guzzlehttp/psr7": "~1.1", 27 | "php": ">=5.5.0" 28 | }, 29 | "require-dev": { 30 | "ext-curl": "*", 31 | "phpunit/phpunit": "~4.0", 32 | "psr/log": "~1.0" 33 | }, 34 | "type": "library", 35 | "extra": { 36 | "branch-alias": { 37 | "dev-master": "6.1-dev" 38 | } 39 | }, 40 | "autoload": { 41 | "files": [ 42 | "src/functions_include.php" 43 | ], 44 | "psr-4": { 45 | "GuzzleHttp\\": "src/" 46 | } 47 | }, 48 | "notification-url": "https://packagist.org/downloads/", 49 | "license": [ 50 | "MIT" 51 | ], 52 | "authors": [ 53 | { 54 | "name": "Michael Dowling", 55 | "email": "mtdowling@gmail.com", 56 | "homepage": "https://github.com/mtdowling" 57 | } 58 | ], 59 | "description": "Guzzle is a PHP HTTP client library", 60 | "homepage": "http://guzzlephp.org/", 61 | "keywords": [ 62 | "client", 63 | "curl", 64 | "framework", 65 | "http", 66 | "http client", 67 | "rest", 68 | "web service" 69 | ], 70 | "time": "2015-10-27 04:12:26" 71 | }, 72 | { 73 | "name": "guzzlehttp/promises", 74 | "version": "dev-master", 75 | "source": { 76 | "type": "git", 77 | "url": "https://github.com/guzzle/promises.git", 78 | "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea" 79 | }, 80 | "dist": { 81 | "type": "zip", 82 | "url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea", 83 | "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea", 84 | "shasum": "" 85 | }, 86 | "require": { 87 | "php": ">=5.5.0" 88 | }, 89 | "require-dev": { 90 | "phpunit/phpunit": "~4.0" 91 | }, 92 | "type": "library", 93 | "extra": { 94 | "branch-alias": { 95 | "dev-master": "1.0-dev" 96 | } 97 | }, 98 | "autoload": { 99 | "psr-4": { 100 | "GuzzleHttp\\Promise\\": "src/" 101 | }, 102 | "files": [ 103 | "src/functions_include.php" 104 | ] 105 | }, 106 | "notification-url": "https://packagist.org/downloads/", 107 | "license": [ 108 | "MIT" 109 | ], 110 | "authors": [ 111 | { 112 | "name": "Michael Dowling", 113 | "email": "mtdowling@gmail.com", 114 | "homepage": "https://github.com/mtdowling" 115 | } 116 | ], 117 | "description": "Guzzle promises library", 118 | "keywords": [ 119 | "promise" 120 | ], 121 | "time": "2015-10-15 22:28:00" 122 | }, 123 | { 124 | "name": "guzzlehttp/psr7", 125 | "version": "1.2.1", 126 | "source": { 127 | "type": "git", 128 | "url": "https://github.com/guzzle/psr7.git", 129 | "reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982" 130 | }, 131 | "dist": { 132 | "type": "zip", 133 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/4d0bdbe1206df7440219ce14c972aa57cc5e4982", 134 | "reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982", 135 | "shasum": "" 136 | }, 137 | "require": { 138 | "php": ">=5.4.0", 139 | "psr/http-message": "~1.0" 140 | }, 141 | "provide": { 142 | "psr/http-message-implementation": "1.0" 143 | }, 144 | "require-dev": { 145 | "phpunit/phpunit": "~4.0" 146 | }, 147 | "type": "library", 148 | "extra": { 149 | "branch-alias": { 150 | "dev-master": "1.0-dev" 151 | } 152 | }, 153 | "autoload": { 154 | "psr-4": { 155 | "GuzzleHttp\\Psr7\\": "src/" 156 | }, 157 | "files": [ 158 | "src/functions_include.php" 159 | ] 160 | }, 161 | "notification-url": "https://packagist.org/downloads/", 162 | "license": [ 163 | "MIT" 164 | ], 165 | "authors": [ 166 | { 167 | "name": "Michael Dowling", 168 | "email": "mtdowling@gmail.com", 169 | "homepage": "https://github.com/mtdowling" 170 | } 171 | ], 172 | "description": "PSR-7 message implementation", 173 | "keywords": [ 174 | "http", 175 | "message", 176 | "stream", 177 | "uri" 178 | ], 179 | "time": "2015-11-03 01:34:55" 180 | }, 181 | { 182 | "name": "psr/http-message", 183 | "version": "dev-master", 184 | "source": { 185 | "type": "git", 186 | "url": "https://github.com/php-fig/http-message.git", 187 | "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" 188 | }, 189 | "dist": { 190 | "type": "zip", 191 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", 192 | "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", 193 | "shasum": "" 194 | }, 195 | "require": { 196 | "php": ">=5.3.0" 197 | }, 198 | "type": "library", 199 | "extra": { 200 | "branch-alias": { 201 | "dev-master": "1.0.x-dev" 202 | } 203 | }, 204 | "autoload": { 205 | "psr-4": { 206 | "Psr\\Http\\Message\\": "src/" 207 | } 208 | }, 209 | "notification-url": "https://packagist.org/downloads/", 210 | "license": [ 211 | "MIT" 212 | ], 213 | "authors": [ 214 | { 215 | "name": "PHP-FIG", 216 | "homepage": "http://www.php-fig.org/" 217 | } 218 | ], 219 | "description": "Common interface for HTTP messages", 220 | "keywords": [ 221 | "http", 222 | "http-message", 223 | "psr", 224 | "psr-7", 225 | "request", 226 | "response" 227 | ], 228 | "time": "2015-05-04 20:22:00" 229 | } 230 | ], 231 | "packages-dev": [], 232 | "aliases": [], 233 | "minimum-stability": "dev", 234 | "stability-flags": [], 235 | "prefer-stable": false, 236 | "prefer-lowest": false, 237 | "platform": { 238 | "php": ">=5.5.9" 239 | }, 240 | "platform-dev": [] 241 | } 242 | -------------------------------------------------------------------------------- /config/twitch-api.php: -------------------------------------------------------------------------------- 1 | env('TWITCH_KEY', ''), 5 | 'client_secret' => env('TWITCH_SECRET', ''), 6 | 'redirect_url' => env('TWITCH_REDIRECT_URI', ''), 7 | 'scopes' => [ 8 | 'channel_check_subscription', 9 | 'channel_commercial', 10 | 'channel_editor', 11 | 'channel_feed_edit', 12 | 'channel_feed_read', 13 | 'channel_read', 14 | 'channel_stream', 15 | 'channel_subscriptions', 16 | 'chat_login', 17 | 'collections_edit', 18 | 'communities_edit', 19 | 'communities_moderate', 20 | 'openid', 21 | 'user_blocks_edit', 22 | 'user_blocks_read', 23 | 'user_follows_edit', 24 | 'user_read', 25 | 'user_subscriptions', 26 | 'viewing_activity_read' 27 | ], 28 | ]; -------------------------------------------------------------------------------- /docs/api.md: -------------------------------------------------------------------------------- 1 | # Api 2 | 3 | The Api class contains the core functions of the package. All other API functions extend from this. 4 | 5 | ## Functions 6 | 7 | ```php 8 | input('code'); 45 | $response = TwitchApi::getAccessObject($code); 46 | TwitchApi::setToken($response['access_token']); 47 | 48 | // Get user object from Twitch 49 | $twitchUser = Twitch::authUser(); 50 | 51 | /** 52 | * Find or create user (this expects a twitch_id column in your users table). 53 | * 54 | * It's recommended to identify Twitch users by twitch_id, rather than by name. 55 | * Names may be changed by Twitch staff, however, the twitch_id remains the same. 56 | */ 57 | $user = User::findOrNew(['twitch_id' => $twitchUser['_id']]); 58 | 59 | // Authenticate user 60 | Auth::login($user); 61 | } 62 | } 63 | ``` -------------------------------------------------------------------------------- /docs/blocks.md: -------------------------------------------------------------------------------- 1 | # Blocks 2 | 3 | For seeing blocked (ignored) users and (un)block a user. 4 | 5 | [Twitch API](https://github.com/justintv/Twitch-API/blob/master/blcoks.md) 6 | 7 | ## Functions 8 | 9 | `$token` is an optional parameter, but required to be set somewhere. 10 | 11 | ```php 12 | 'Kappa Stream', 23 | 'game' => 'RuneScape', 24 | 'delay' => 0 25 | ]; 26 | updateChannel($channel, $options, $token); 27 | 28 | // Delete (reset) stream key 29 | resetStreamKey($channel, $token); 30 | 31 | // Post (run) commercial 32 | runCommercial($channel, $length = 30, $token); 33 | ``` 34 | 35 | ## Example Usage 36 | 37 | File: `App/Https/Controllers/ChannelController.php` 38 | 39 | ```php 40 | 20, 19 | 'offset' => 0, 20 | 'direction' => 'DESC', 21 | ]; 22 | followers($channel, $options); 23 | 24 | // Get list of who the user is following 25 | $options = [ 26 | 'limit' => 20, 27 | 'offset' => 0, 28 | 'direction' => 'DESC', 29 | 'sortby' => 'created_at', 30 | ]; 31 | followings($user, $options); 32 | 33 | // Check if user follows a channel - 404 if not 34 | userIsFollowing($user, $channel); 35 | 36 | // Follow a channel 37 | $options = [ 38 | 'notifications' => false, 39 | ]; 40 | follow($user, $channel, $options, $token); 41 | 42 | // Unfollow a channel 43 | unfollow($user, $channel, $token); 44 | ``` 45 | 46 | ## Example Usage 47 | 48 | File: `App/Https/Controllers/FollowController.php` 49 | 50 | ```php 51 | 100, 64 | ]; 65 | return TwitchApi::followers('zarlach', $options); 66 | } 67 | 68 | public function followChannel() 69 | { 70 | return TwitchApi::follow('zarlach', 'kappa'); 71 | } 72 | } 73 | ``` -------------------------------------------------------------------------------- /docs/games.md: -------------------------------------------------------------------------------- 1 | # Games 2 | 3 | Game top lists. 4 | 5 | [Twitch API](https://github.com/justintv/Twitch-API/blob/master/games.md) 6 | 7 | ## Functions 8 | 9 | `$options` is an optional parameter. 10 | 11 | ```php 12 | 10, 17 | 'offset' => 0, 18 | ]; 19 | topGames($options); 20 | ``` 21 | 22 | ## Example Usage 23 | 24 | File: `App/Https/Controllers/GamesController.php` 25 | 26 | ```php 27 | 5, 40 | ]; 41 | return TwitchApi::topGames($options); 42 | } 43 | } 44 | ``` -------------------------------------------------------------------------------- /docs/ingests.md: -------------------------------------------------------------------------------- 1 | # Ingests 2 | 3 | Twitch streaming servers. 4 | 5 | [Twitch API](https://github.com/justintv/Twitch-API/blob/master/ingests.md) 6 | 7 | ## Functions 8 | 9 | ```php 10 | 'zarlach', 17 | 'limit' => 5, 18 | 'offset' => 0, 19 | ]; 20 | searchChannels($options); 21 | 22 | // Search channels 23 | $options = [ 24 | 'query' => 'zarlach', 25 | 'limit' => 5, 26 | 'offset' => 0, 27 | ]; 28 | searchStreams($options); 29 | 30 | // Search channels 31 | $options = [ 32 | 'query' => 'zarlach', 33 | 'limit' => 5, 34 | 'offset' => 0, 35 | ]; 36 | searchGames($options); 37 | ``` 38 | 39 | ## Example Usage 40 | 41 | File: `App/Https/Controllers/SearchController.php` 42 | 43 | ```php 44 | 'zarlach', 57 | ]; 58 | 59 | return TwitchApi::searchChannels($options); 60 | } 61 | } 62 | ``` -------------------------------------------------------------------------------- /docs/streams.md: -------------------------------------------------------------------------------- 1 | # Streams 2 | 3 | Twitch streams 4 | 5 | [Twitch API](https://github.com/justintv/Twitch-API/blob/master/streams.md) 6 | 7 | ## Functions 8 | 9 | `$options` is an optional parameter. 10 | 11 | ```php 12 | 'runescape', 20 | 'channel' => 'zarlach', 21 | 'limit' => 10, 22 | 'offset' => 0, 23 | 'client_id' => 'xxxxxxx', 24 | ]; 25 | streams($options); 26 | 27 | // Returns featured/promoted streams 28 | $options = [ 29 | 'limit' => 10, 30 | 'offset' => 0, 31 | ]; 32 | featuredStreams($options); 33 | 34 | // Get summary of active streams 35 | $options = [ 36 | 'game' => 'RuneScape', 37 | 'limit' => 10, 38 | 'offset' => 0, 39 | ]; 40 | streamSummaries($options); 41 | ``` 42 | 43 | ## Example Usage 44 | 45 | File: `App/Https/Controllers/StreamsController.php` 46 | 47 | ```php 48 | 'RuneScape', 66 | ]; 67 | 68 | return TwitchApi::streams($options); 69 | } 70 | } 71 | ``` -------------------------------------------------------------------------------- /docs/subscriptions.md: -------------------------------------------------------------------------------- 1 | # Subscriptions 2 | 3 | [Twitch API](https://github.com/justintv/Twitch-API/blob/master/subscribers.md) 4 | 5 | ## Functions 6 | 7 | `$token` is an optional parameter, but required to be set somewhere. 8 | 9 | `$options` is an optional parameter. 10 | 11 | ```php 12 | 20, 17 | 'offset' => 0, 18 | 'direction' => 'DESC', 19 | ]; 20 | subscribers($channel, $options, $token); 21 | 22 | // Get subscription object of a single channel subscribers 23 | subscriber($channel, $user, $token); 24 | 25 | // Get channel object of a single channel subscriber 26 | subscribedToChannel($channel, $user, $token); 27 | ``` 28 | 29 | ## Example Usage 30 | 31 | File: `App/Https/Controllers/SubscriptionController.php` 32 | 33 | ```php 34 | 100, 47 | ]; 48 | 49 | TwitchApi::setToken('xxxxxxxxxxxxxx'); 50 | 51 | return TwitchApi::subscribers($channel, $options); 52 | } 53 | } 54 | ``` -------------------------------------------------------------------------------- /docs/teams.md: -------------------------------------------------------------------------------- 1 | # Teams 2 | 3 | Team lists and objects. 4 | 5 | [Twitch API](https://github.com/justintv/Twitch-API/blob/master/teams.md) 6 | 7 | ## Functions 8 | 9 | `$options` is an optional parameter. 10 | 11 | ```php 12 | 20, 17 | 'offset' => 0, 18 | ]; 19 | teams($options); 20 | 21 | // Get team object 22 | team($team); 23 | ``` 24 | 25 | ## Example Usage 26 | 27 | File: `App/Https/Controllers/TeamController.php` 28 | 29 | ```php 30 | 'username', 20 | ]; 21 | users($options) 22 | 23 | // Authenticated user object 24 | authUser($token); 25 | 26 | // Followed streams who are live 27 | liveChannels($token); 28 | 29 | // Videos from channels you follow 30 | followedChannelVideos($token); 31 | ``` 32 | 33 | ## Example Usage 34 | 35 | File: `App/Https/Controllers/UsersController.php` 36 | 37 | ```php 38 | 'username', 56 | ]; 57 | 58 | return TwitchApi::users($options); 59 | } 60 | 61 | public function authUser() 62 | { 63 | TwitchApi::setToken('xxxxxxxxxxxxxx'); 64 | 65 | return TwitchApi::authUser(); 66 | } 67 | } 68 | ``` -------------------------------------------------------------------------------- /docs/videos.md: -------------------------------------------------------------------------------- 1 | # Users 2 | 3 | Video objects, top lists and channel videos. 4 | 5 | [Twitch API](https://github.com/justintv/Twitch-API/blob/master/videos.md) 6 | 7 | ## Functions 8 | 9 | `$token` is an optional parameter, but required to be set somewhere. 10 | 11 | ```php 12 | 10, 23 | 'offset' => 0, 24 | 'broadcasts' => '', 25 | 'hls' => '', 26 | ]; 27 | channelVideos($channel, $options); 28 | ``` 29 | 30 | ## Example Usage 31 | 32 | File: `App/Https/Controllers/VideosController.php` 33 | 34 | ```php 35 | 10, 48 | ]; 49 | return TwitchApi::topVideos($options); 50 | } 51 | } 52 | ``` -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Petter Kraabøl 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Twitch API for Laravel 2 | 3 | An easy-to-use API for Laravel 5 4 | 5 | ## Installation 6 | 7 | ```bash 8 | composer require zarlach/laravel-twitch-api 9 | ``` 10 | 11 | In `config/app.php`, add this provider in `providers` 12 | 13 | ```php 14 | Zarlach\TwitchApi\Providers\TwitchApiServiceProvider::class, 15 | ``` 16 | 17 | Add this facade in `aliases` 18 | 19 | ```php 20 | 'TwitchApi' => Zarlach\TwitchApi\Facades\TwitchApiServiceFacade::class, 21 | ``` 22 | 23 | Publish config, then configure your `config/twitch-api.php` 24 | 25 | ```php 26 | php artisan vendor:publish 27 | ``` 28 | 29 | ## Laravel environment variables 30 | 31 | It's recommended to add these variables in your `.env` file. 32 | 33 | ```bash 34 | TWITCH_KEY= 35 | TWITCH_SECRET= 36 | TWITCH_REDIRECT_URI= 37 | ``` 38 | 39 | ## Documentation 40 | 41 | You'll find documentation markdown files in the `docs` folder. 42 | 43 | ## Changelog 44 | 45 | A list of changes is found in `changelog.md` 46 | -------------------------------------------------------------------------------- /src/API/Api.php: -------------------------------------------------------------------------------- 1 | setToken($token); 48 | } 49 | 50 | // Set clientId if given else get from config 51 | if ($clientId) { 52 | $this->setClientId($clientId); 53 | } elseif (config('twitch-api.client_id')) { 54 | $this->setClientId(config('twitch-api.client_id')); 55 | } 56 | 57 | // GuzzleHttp Client with default parameters. 58 | $this->client = new Client([ 59 | 'base_uri' => 'https://api.twitch.tv/kraken/', 60 | 'headers' => array('Accept' => 'application/vnd.twitchtv.v5+json') 61 | ]); 62 | } 63 | 64 | /** 65 | * Set clientId. 66 | * 67 | * @param string $clientId Twitch client id 68 | */ 69 | public function setClientId($clientId) 70 | { 71 | $this->clientId = $clientId; 72 | } 73 | 74 | /** 75 | * Get clientId. 76 | * 77 | * @param string clientId optional 78 | * 79 | * @return string clientId 80 | */ 81 | public function getClientId($clientId = null) 82 | { 83 | 84 | // Return given parameter 85 | if ($clientId) { 86 | return $clientId; 87 | } 88 | 89 | // If clientId is null and no clientId has previously been set 90 | if (!$this->clientId) { 91 | throw new RequestRequiresClientIdException(); 92 | } 93 | 94 | // Return clientId that has previously been set 95 | return $this->clientId; 96 | } 97 | 98 | /** 99 | * Set Twitch OAuth Token. 100 | * 101 | * @param string $token OAuth token 102 | */ 103 | public function setToken($token) 104 | { 105 | $this->token = $token; 106 | } 107 | 108 | /** 109 | * Get Twitch token. 110 | * 111 | * @param string $token Twitch token 112 | * 113 | * @return string Twitch token 114 | */ 115 | public function getToken($token = null) 116 | { 117 | 118 | // If given parameter is not null, return this parameter 119 | if ($token) { 120 | return $token; 121 | } 122 | 123 | // If token is null and no token has previously been set 124 | if (!$this->token) { 125 | throw new RequestRequiresAuthenticationException(); 126 | } 127 | 128 | // Return token that has previously been set 129 | return $this->token; 130 | } 131 | 132 | /** 133 | * Send request to Twitch API. 134 | * 135 | * @param string $type Request type 136 | * @param string $path Request URL path 137 | * @param bool $token Twitch token 138 | * @param array $options URL queries 139 | * @param array $availableOptions Available URL queries 140 | * 141 | * @return JSON JSON object from Twitch 142 | */ 143 | public function sendRequest($type = 'GET', $path = '', $token = false, $options = [], $availableOptions = []) 144 | { 145 | 146 | /** 147 | * TODO: $availableOptions is currently not being used, as it's 148 | * just a limitation in case Twitch adds to, or makes changes to them. 149 | * This variable can either be removed completed or used for something 150 | * more useful, like telling developers what options they have. 151 | */ 152 | // URL parameters 153 | //$path = $this->generateUrl($path, $token, $options, $availableOptions); 154 | $path = $this->generateUrl($path, $token, $options, $availableOptions); 155 | 156 | // Headers 157 | $data = [ 158 | 'headers' => [ 159 | 'Client-ID' => $this->getClientId(), 160 | 'Accept' => 'application/vnd.twitchtv.v5+json', 161 | ], 162 | ]; 163 | 164 | // Twitch token 165 | if ($token) { 166 | $data['headers']['Authorization'] = 'OAuth '.$this->getToken($token); 167 | } 168 | 169 | try{ 170 | // Request object 171 | $request = new Request($type, $path, $data); 172 | // Send request 173 | $response = $this->client->send($request); 174 | 175 | // Return body in JSON data 176 | return json_decode($response->getBody(), true); 177 | } 178 | catch(RequestException $e){ 179 | if ($e->hasResponse()) { 180 | $exception = (string) $e->getResponse()->getBody(); 181 | $exception = json_decode($exception); 182 | return $exception; 183 | } else { 184 | //503 185 | return array( 186 | 'error' => 'Service Unavailable', 187 | 'status' => 503, 188 | 'message' => $e->getMessage() 189 | ); 190 | } 191 | } 192 | 193 | } 194 | 195 | /** 196 | * Generate URL with queries. 197 | * 198 | * @param string $url Original URL 199 | * @param array $options Parameter values 200 | * @param array $availableOptions Parameters 201 | * 202 | * @return string URL with queries 203 | */ 204 | public function generateUrl($url, $token, $options, $availableOptions) 205 | { 206 | 207 | // Append client id 208 | $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').'client_id='.$this->getClientId(); 209 | 210 | // Append token if provided 211 | if ($token) { 212 | $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').'oauth_token='.$this->getToken($token); 213 | } 214 | 215 | // Add options to the URL 216 | foreach ($options as $key => $value) { 217 | $url .= (parse_url($url, PHP_URL_QUERY) ? '&' : '?').$key.'='.$value; 218 | } 219 | 220 | return $url; 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /src/API/Authentication.php: -------------------------------------------------------------------------------- 1 | getAccessObject($code, $state); 41 | 42 | return $response['access_token']; 43 | } 44 | 45 | /** 46 | * Returns access_token, refresh_token and scope from Twitch. 47 | * 48 | * @param string $code code from redirect_uri 49 | * @param string $state optional state OAuth2 parameter to prevent cross-site scripting attacks 50 | * 51 | * @return JSON JSON response object from Twitch 52 | */ 53 | public function getAccessObject($code, $state = null) 54 | { 55 | $availableOptions = ['client_secret', 'grant_type', 'state', 'code', 'redirect_uri']; 56 | 57 | $options = [ 58 | 'client_secret' => config('twitch-api.client_secret'), 59 | 'grant_type' => 'authorization_code', 60 | 'code' => $code, 61 | 'state' => $state, 62 | 'redirect_uri' => config('twitch-api.redirect_url'), 63 | ]; 64 | 65 | return $this->sendRequest('POST', 'oauth2/token', false, $options, $availableOptions); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/API/Blocks.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'users/'.$user.'/blocks', $this->getToken($token)); 21 | } 22 | 23 | /** 24 | * Add target to user's block list. 25 | * 26 | * @param string $user Username 27 | * @param string $target Target's username 28 | * @param string $token Twitch token 29 | * 30 | * @return JSON Request result 31 | */ 32 | public function putBlock($user, $target, $token = null) 33 | { 34 | return $this->sendRequest('PUT', 'users/'.$user.'/blocks/'.$target, $this->getToken($token)); 35 | } 36 | 37 | /** 38 | * Delete target from user's block list. 39 | * 40 | * @param string $user Username 41 | * @param string $target Target's username 42 | * @param string $token Twitch token 43 | * 44 | * @return JSON Request result 45 | */ 46 | public function deleteBlock($user, $target, $token = null) 47 | { 48 | return $this->sendRequest('DELETE', 'users/'.$user.'/blocks/'.$target, $this->getToken($token)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/API/Channels.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'channels/'.$channel); 20 | } 21 | 22 | /** 23 | * Get authenticated channel object. 24 | * 25 | * @param string $token Twitch token 26 | * 27 | * @return JSON Channel object 28 | */ 29 | public function authenticatedChannel($token = null) 30 | { 31 | return $this->sendRequest('GET', 'channel', $this->getToken($token)); 32 | } 33 | 34 | /** 35 | * Update channel. 36 | * 37 | * @param string $channel Channel name 38 | * @param array $options Channel options 39 | * @param string $token Twitch token 40 | * 41 | * @return JSON Request result 42 | */ 43 | public function putChannel($channel, $rawOptions, $token = null) 44 | { 45 | $options = []; 46 | 47 | foreach ($rawOptions as $key => $value) { 48 | $options['channel['.$key.']'] = $value; 49 | } 50 | 51 | return $this->sendRequest('PUT', 'channels/'.$channel, $this->getToken($token), $options); 52 | } 53 | 54 | /** 55 | * Reset stream key. 56 | * 57 | * @param string $channel Channel name 58 | * @param string $token Twitch token 59 | * 60 | * @return JSON Request result with new stream key 61 | */ 62 | public function deleteStreamKey($channel, $token = null) 63 | { 64 | return $this->sendRequest('DELETE', 'channels/'.$channel.'/stream_key', $this->getToken($token)); 65 | } 66 | 67 | /** 68 | * Run commercial. 69 | * 70 | * @param string $channel Channel name 71 | * @param number $length Commercial length 72 | * @param string $token Twitch token 73 | * 74 | * @return JSON Request result 75 | */ 76 | public function postCommercial($channel, $length = 30, $token = null) 77 | { 78 | $availableOptions = ['length']; 79 | $options = ['length' => $length]; 80 | 81 | return $this->sendRequest('POST', 'channels/'.$channel.'/commercial', $this->getToken($token), $options, $availableOptions); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/API/Chat.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'chat/'.$channel); 20 | } 21 | 22 | /** 23 | * Get chat badges for channel. 24 | * 25 | * @param string $channel Channel name 26 | * 27 | * @return JSON Chat badges 28 | */ 29 | public function chatBadges($channel) 30 | { 31 | return $this->sendRequest('GET', 'chat/'.$channel.'/badges'); 32 | } 33 | 34 | /** 35 | * Get list of every emoticon object. 36 | * 37 | * @return JSON List of emoticons 38 | */ 39 | public function chatEmoticons() 40 | { 41 | return $this->sendRequest('GET', 'chat/emotes'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/API/Clips.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'clips/'.$slug); 20 | } 21 | 22 | /** 23 | * Get top clips by number of views. 24 | * 25 | * @param array $options Video list options 26 | * 27 | * @return JSON List of videos 28 | */ 29 | public function clipsTop($options = []) 30 | { 31 | $availableOptions = ['limit', 'offset', 'game', 'period','limit','trending']; 32 | 33 | return $this->sendRequest('GET', 'clips/top', false, $options, $availableOptions); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/API/Follow.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'channels/'.$channel.'/follows', false, $options, $availableOptions); 23 | } 24 | 25 | /** 26 | * Get list of who the user is following. 27 | * 28 | * @param string $user Username 29 | * @param array $options List options 30 | * 31 | * @return JSON List of who the user is following 32 | */ 33 | public function userFollowsChannels($user, $options = []) 34 | { 35 | $availableOptions = ['limit', 'offset', 'direction', 'sortby']; 36 | 37 | return $this->sendRequest('GET', 'users/'.$user.'/follows/channels', false, $options, $availableOptions); 38 | } 39 | 40 | /** 41 | * Check if user follows a channel - returns 404 if not. 42 | * 43 | * @param string $user Username 44 | * @param string $channel Channel name 45 | * 46 | * @return JSON Request result 47 | */ 48 | public function userFollowsChannel($user, $channel) 49 | { 50 | return $this->sendRequest('GET', 'users/'.$user.'/follows/channels/'.$channel); 51 | } 52 | 53 | /** 54 | * Follow a channel. 55 | * 56 | * @param string $user Username 57 | * @param string $channel Target channel's name 58 | * @param array $options Follow options 59 | * @param string $token Twitch token 60 | * 61 | * @return JSON Request result 62 | */ 63 | public function authenticatedUserFollowsChannel($user, $channel, $options = [], $token = null) 64 | { 65 | $availableOptions = ['notifications']; 66 | 67 | return $this->sendRequest('PUT', 'users/'.$user.'/follows/channels/'.$channel, $this->getToken($token), $options, $availableOptions); 68 | } 69 | 70 | /** 71 | * Unfollow a channel. 72 | * 73 | * @param string $user Username 74 | * @param string $channel Target channel's name 75 | * @param string $token Twitch token 76 | * 77 | * @return JSON Response result 78 | */ 79 | public function authenticatedUserUnfollowsChannel($user, $channel, $token = null) 80 | { 81 | return $this->sendRequest('DELETE', 'users/'.$user.'/follows/channels/'.$channel, $this->getToken($token)); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/API/Games.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'games/top', false, $options, $availableOptions); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/API/Ingests.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'ingests'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/API/Root.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET'); 18 | } 19 | 20 | /** 21 | * Authenticated Twitch Kraken API root. 22 | * 23 | * @param string $token Twitch token 24 | * 25 | * @return JSON Authenticated API root object 26 | */ 27 | public function authRoot($token = null) 28 | { 29 | return $this->sendRequest('GET', '', $this->getToken($token)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/API/Search.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'search/channels', false, $options, $availableOptions); 22 | } 23 | 24 | public function searchGames($options) 25 | { 26 | $availableOptions = ['query', 'limit', 'offset']; 27 | 28 | return $this->sendRequest('GET', 'search/games', false, $options, $availableOptions); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/API/Streams.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'streams/'.$channel); 20 | } 21 | 22 | /** 23 | * List of streams, ordered by the number of viewers. 24 | * 25 | * @param arrat $options List options 26 | * 27 | * @return JSON List of streams 28 | */ 29 | public function streams($options) 30 | { 31 | $availableOptions = ['game', 'channel', 'limit', 'offset', 'client_id']; 32 | 33 | return $this->sendRequest('GET', 'streams', false, $options, $availableOptions); 34 | } 35 | 36 | /** 37 | * Return featured/promoted streams. 38 | * 39 | * @param array $options Featured stream list options 40 | * 41 | * @return JSON List of featured/promoted streams 42 | */ 43 | public function streamsFeatured($options = []) 44 | { 45 | $availableOptions = ['limit', 'offset']; 46 | 47 | return $this->sendRequest('GET', 'streams/featured', false, $options, $availableOptions); 48 | } 49 | 50 | /** 51 | * Summary of active streams. 52 | * 53 | * @param array $options Active streams list options 54 | * 55 | * @return JSON List of active streams 56 | */ 57 | public function streamSummaries($options = []) 58 | { 59 | $availableOptions = ['game', 'limit', 'offset']; 60 | 61 | return $this->sendRequest('GET', 'streams/summary', false, $options, $availableOptions); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/API/Subscriptions.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'channels/'.$channel.'/subscriptions', $this->getToken($token), $options, $availableOptions); 24 | } 25 | 26 | /** 27 | * Get subscription object of a single channel subscriber. 28 | * 29 | * @param string $channel Channel name 30 | * @param string $user Username 31 | * @param string $token Twitch name 32 | * 33 | * @return JSON A channel subscriber 34 | */ 35 | public function channelSubscriptionUser($channel, $user, $token = null) 36 | { 37 | return $this->sendRequest('GET', 'channels/'.$channel.'/subscriptions/'.$user, $this->getToken($token)); 38 | } 39 | 40 | /** 41 | * Get user object of a single channel subscriber. 42 | * 43 | * @param string $channel Channel name 44 | * @param string $user Username 45 | * @param string $token Twitch token 46 | * 47 | * @return JSON User object 48 | */ 49 | public function userSubscriptionChannel($channel, $user, $token = null) 50 | { 51 | return $this->sendRequest('GET', 'users/'.$user.'/subscriptions/'.$channel, $this->getToken($token)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/API/Teams.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'teams', false, $options, $availableOptions); 22 | } 23 | 24 | /** 25 | * Get a team object. 26 | * 27 | * @param string $team Team name 28 | * 29 | * @return JSON Team object 30 | */ 31 | public function team($team) 32 | { 33 | return $this->sendRequest('GET', 'teams/'.$team); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/API/Users.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'users/'.$user); 20 | } 21 | 22 | /** 23 | * Users object 24 | * 25 | * @param $options List options 26 | * 27 | * @return JSON Users object 28 | */ 29 | public function users($options) 30 | { 31 | $availableOptions = ['login']; 32 | 33 | return $this->sendRequest('GET', 'users', false, $options, $availableOptions); 34 | } 35 | 36 | /** 37 | * Authenticated user object. 38 | * 39 | * @param string $token Twitch token 40 | * 41 | * @return JSON Authenticated user object 42 | */ 43 | public function authenticatedUser($token = null) 44 | { 45 | return $this->sendRequest('GET', 'user', $this->getToken($token)); 46 | } 47 | 48 | /** 49 | * Followed streams who are live. 50 | * 51 | * @param string $token Twitch token 52 | * 53 | * @return JSON List of streams 54 | */ 55 | public function liveChannels($token = null) 56 | { 57 | return $this->sendRequest('GET', 'streams/followed', $this->getToken($token)); 58 | } 59 | 60 | /** 61 | * Videos from channels you follow. 62 | * 63 | * @param string $token Twitch token 64 | * 65 | * @return JSON List of videos 66 | */ 67 | public function followedChannelVideos($token = null) 68 | { 69 | return $this->sendRequest('GET', 'videos/followed', $this->getToken($token)); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/API/Videos.php: -------------------------------------------------------------------------------- 1 | sendRequest('GET', 'videos/'.$id); 20 | } 21 | 22 | /** 23 | * Get top videos by number of views. 24 | * 25 | * @param array $options Video list options 26 | * 27 | * @return JSON List of videos 28 | */ 29 | public function videosTop($options = []) 30 | { 31 | $availableOptions = ['limit', 'offset', 'game', 'period']; 32 | 33 | return $this->sendRequest('GET', 'videos/top', false, $options, $availableOptions); 34 | } 35 | 36 | /** 37 | * Get list of video objects belonging to channel. 38 | * 39 | * @param string $channel Channel name 40 | * @param array $options Video list options 41 | * 42 | * @return JSON List of videos 43 | */ 44 | public function channelVideos($channel, $options = []) 45 | { 46 | $availableOptions = ['limit', 'offset', 'broadcasts', 'hls']; 47 | 48 | return $this->sendRequest('GET', 'channels/'.$channel.'/videos', false, $options, $availableOptions); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Exceptions/RequestRequiresAuthenticationException.php: -------------------------------------------------------------------------------- 1 | message = 'Request requires authentication'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Exceptions/RequestRequiresClientIdException.php: -------------------------------------------------------------------------------- 1 | message = 'Request requires Client-ID'; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Facades/TwitchApiServiceFacade.php: -------------------------------------------------------------------------------- 1 | registerServices(); 13 | } 14 | 15 | // Boot 16 | public function boot() 17 | { 18 | $this->addConfig(); 19 | } 20 | 21 | // Register services 22 | private function registerServices() 23 | { 24 | $this->app->bind('Zarlach\TwitchApi\Services\TwitchApiService', 'Zarlach\TwitchApi\Services\TwitchApiService'); 25 | } 26 | 27 | // Add config file 28 | private function addConfig() 29 | { 30 | $this->publishes([ 31 | __DIR__.'/../../config/twitch-api.php' => config_path('twitch-api.php'), 32 | ]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Services/TwitchApiService.php: -------------------------------------------------------------------------------- 1 | getAuthenticationUrl($state, $forceVerify); 32 | } 33 | 34 | public function getAccessToken($code, $state = null) 35 | { 36 | $authentication = new Authentication(); 37 | 38 | return $authentication->getAccessToken($code, $state); 39 | } 40 | 41 | public function getAccessObject($code, $state = null) 42 | { 43 | $authentication = new Authentication(); 44 | 45 | return $authentication->getAccessObject($code, $state); 46 | } 47 | 48 | /** 49 | * Blocks. 50 | */ 51 | public function ignoreList($user, $token = null) 52 | { 53 | $blocks = new Blocks($this->getToken($token)); 54 | 55 | return $blocks->blocks($user); 56 | } 57 | 58 | public function ignore($user, $target, $token = null) 59 | { 60 | $blocks = new Blocks($this->getToken($token)); 61 | 62 | return $blocks->putBlock($user, $target); 63 | } 64 | 65 | public function unignore($user, $target, $token = null) 66 | { 67 | $blocks = new Blocks($this->getToken($token)); 68 | 69 | return $blocks->deleteBlock($user, $target); 70 | } 71 | 72 | /** 73 | * Channels. 74 | */ 75 | public function channel($channel) 76 | { 77 | $channels = new Channels(); 78 | 79 | return $channels->channel($channel); 80 | } 81 | 82 | public function authChannel($token = null) 83 | { 84 | $channels = new Channels($this->getToken($token)); 85 | 86 | return $channels->authenticatedChannel(); 87 | } 88 | 89 | public function updateChannel($channel, $options, $token = null) 90 | { 91 | $channels = new Channels($this->getToken($token)); 92 | 93 | return $channels->putChannel($channel, $options); 94 | } 95 | 96 | public function resetStreamKey($channel, $token = null) 97 | { 98 | $channels = new Channels($this->getToken($token)); 99 | 100 | return $channels->deleteStreamKey($channel); 101 | } 102 | 103 | public function runCommercial($channel, $length = 30, $token = null) 104 | { 105 | $channels = new Channels($this->getToken($token)); 106 | 107 | return $channels->postCommercial($channel, $length); 108 | } 109 | 110 | /** 111 | * Chat. 112 | */ 113 | public function chat($channel) 114 | { 115 | $chat = new Chat(); 116 | 117 | return $chat->chatChannel($channel); 118 | } 119 | 120 | public function chatBadges($channel) 121 | { 122 | $chat = new Chat(); 123 | 124 | return $chat->chatBadges($channel); 125 | } 126 | 127 | public function chatEmoticons($channel) 128 | { 129 | $chat = new Chat($channel); 130 | 131 | return $chat->chatEmoticons($channel); 132 | } 133 | 134 | /** 135 | * Follow. 136 | */ 137 | public function followers($channel, $options = []) 138 | { 139 | $follow = new Follow(); 140 | 141 | return $follow->channelFollows($channel, $options); 142 | } 143 | 144 | public function followings($user, $options) 145 | { 146 | $follow = new Follow(); 147 | 148 | return $follow->userFollowsChannels($user, $options); 149 | } 150 | 151 | public function userIsFollowing($user, $channel) 152 | { 153 | $follow = new Follow(); 154 | 155 | return $follow->userFollowsChannel($user, $channel); 156 | } 157 | 158 | public function follow($user, $channel, $options = [], $token = null) 159 | { 160 | $follow = new Follow($this->getToken($token)); 161 | 162 | return $follow->authenticatedUserFollowsChannel($user, $channel, $options); 163 | } 164 | 165 | public function unfollow($user, $channel, $token = null) 166 | { 167 | $follow = new Follow($this->getToken($token)); 168 | 169 | return $follow->authenticatedUserUnfollowsChannel($user, $channel); 170 | } 171 | 172 | /** 173 | * Games. 174 | */ 175 | public function topGames($options = []) 176 | { 177 | $games = new Games(); 178 | 179 | return $games->topGames($options); 180 | } 181 | 182 | /** 183 | * Ingests. 184 | */ 185 | public function ingests($options = []) 186 | { 187 | $ingests = new Ingests(); 188 | 189 | return $ingests->ingests($options); 190 | } 191 | 192 | /** 193 | * Root. 194 | */ 195 | public function root() 196 | { 197 | $root = new Root(); 198 | 199 | return $root->root(); 200 | } 201 | 202 | public function authRoot($token = null) 203 | { 204 | $root = new Root($this->getToken($token)); 205 | 206 | return $root->authRoot(); 207 | } 208 | 209 | /** 210 | * Search. 211 | */ 212 | public function searchChannels($options) 213 | { 214 | $search = new Search(); 215 | 216 | return $search->searchChannels($options); 217 | } 218 | 219 | /* Coming Soon, use streams() for now 220 | 221 | public function searchStreams($options) 222 | { 223 | $search = new Search(); 224 | return $search->searchStreams($options); 225 | }*/ 226 | 227 | public function searchGames($options) 228 | { 229 | $search = new Search(); 230 | return $search->searchGames($options); 231 | } 232 | 233 | /** 234 | * Streams. 235 | */ 236 | public function liveChannel($channel) 237 | { 238 | $streams = new Streams(); 239 | 240 | return $streams->streamsChannel($channel); 241 | } 242 | 243 | public function streams($options) 244 | { 245 | $streams = new Streams(); 246 | 247 | return $streams->streams($options); 248 | } 249 | 250 | public function featuredStreams($options = []) 251 | { 252 | $streams = new Streams(); 253 | 254 | return $streams->streamsFeatured($options); 255 | } 256 | 257 | public function streamSummaries($options = []) 258 | { 259 | $streams = new Streams(); 260 | 261 | return $streams->streamSummaries($options); 262 | } 263 | 264 | /** 265 | * Subscriptions. 266 | */ 267 | public function subscribers($channel, $options = [], $token = null) 268 | { 269 | $subscriptions = new Subscriptions(); 270 | 271 | return $subscriptions->channelsSubscriptions($channel, $options, $this->getToken($token)); 272 | } 273 | 274 | public function subscriber($channel, $user, $token = null) 275 | { 276 | $subscriptions = new Subscriptions(); 277 | 278 | return $subscriptions->channelSubscriptionUser($channel, $user, $this->getToken($token)); 279 | } 280 | 281 | public function subscribedToChannel($channel, $user, $token = null) 282 | { 283 | $subscriptions = new Subscriptions(); 284 | 285 | return $subscriptions->userSubscriptionChannel($channel, $user, $this->getToken($token)); 286 | } 287 | 288 | /** 289 | * Teams. 290 | */ 291 | public function teams() 292 | { 293 | $teams = new Teams(); 294 | 295 | return $teams->teams(); 296 | } 297 | 298 | public function team($team) 299 | { 300 | $teams = new Teams(); 301 | 302 | return $teams->team($team); 303 | } 304 | 305 | /** 306 | * Users. 307 | */ 308 | public function user($user) 309 | { 310 | $users = new Users(); 311 | 312 | return $users->user($user); 313 | } 314 | 315 | public function users($options) 316 | { 317 | $users = new Users(); 318 | 319 | return $users->users($options); 320 | } 321 | 322 | public function authUser($token = null) 323 | { 324 | $users = new Users(); 325 | 326 | return $users->authenticatedUser($this->getToken($token)); 327 | } 328 | 329 | public function followedChannelVideos($token = null) 330 | { 331 | $users = new Users(); 332 | 333 | return $users->followedChannelVideos($this->getToken($token)); 334 | } 335 | 336 | /** 337 | * Videos. 338 | */ 339 | public function video($id) 340 | { 341 | $videos = new Videos(); 342 | 343 | return $videos->video($id); 344 | } 345 | 346 | public function topVideos($options = []) 347 | { 348 | $videos = new Videos(); 349 | 350 | return $videos->videosTop($options); 351 | } 352 | 353 | public function channelVideos($channel, $options = []) 354 | { 355 | $videos = new Videos(); 356 | 357 | return $videos->channelVideos($channel, $options); 358 | } 359 | /** 360 | * Clips. 361 | */ 362 | public function clip($slug) 363 | { 364 | $clips = new Clips(); 365 | 366 | return $clips->clip($slug); 367 | } 368 | 369 | public function topClips($options = []) 370 | { 371 | $clips = new Clips(); 372 | 373 | return $clips->clipsTop($options); 374 | } 375 | 376 | 377 | } 378 | --------------------------------------------------------------------------------