|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace jofner\SDK\TwitchTV\Methods; |
|
4
|
|
|
|
|
5
|
|
|
use jofner\SDK\TwitchTV\TwitchSDKException; |
|
6
|
|
|
use jofner\SDK\TwitchTV\TwitchRequest; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Channels method class for TwitchTV API SDK for PHP |
|
10
|
|
|
* |
|
11
|
|
|
* @author Josef Ohnheiser <[email protected]> |
|
12
|
|
|
* @license https://github.com/jofner/Twitch-SDK/blob/master/LICENSE.md MIT |
|
13
|
|
|
* @homepage https://github.com/jofner/Twitch-SDK |
|
14
|
|
|
*/ |
|
15
|
|
|
class Channel |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var TwitchRequest */ |
|
18
|
|
|
protected $request; |
|
19
|
|
|
|
|
20
|
|
|
const URI_CHANNEL_AUTH = 'channel'; |
|
21
|
|
|
const URI_CHANNELS = 'channels/'; |
|
22
|
|
|
const URI_CHANNEL_KEY = 'channels/%s/stream_key'; |
|
23
|
|
|
const URI_CHANNEL_EDITORS_AUTH = 'channels/%s/editors'; |
|
24
|
|
|
const URI_CHANNEL_TEAMS = 'channels/%s/teams'; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct(TwitchRequest $request) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->request = $request; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Update channel's status or game |
|
33
|
|
|
* - requires scope 'channel_editor' |
|
34
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md#put-channelschannel |
|
35
|
|
|
* @param string $channel |
|
36
|
|
|
* @param string $queryString |
|
37
|
|
|
* @param string $data |
|
38
|
|
|
* @return \stdClass |
|
39
|
|
|
* @throws TwitchSDKException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function setChannel($channel, $queryString, $data) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->request->request(self::URI_CHANNELS . $channel . $queryString, 'PUT', $data); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get the authenticated channel |
|
48
|
|
|
* - requires scope 'channel_read' |
|
49
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md#get-channel |
|
50
|
|
|
* @param string $queryString |
|
51
|
|
|
* @return \stdClass |
|
52
|
|
|
* @throws TwitchSDKException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getChannel($queryString) |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->request->request(self::URI_CHANNEL_AUTH . $queryString); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Resets channel's stream key |
|
61
|
|
|
* - requires scope 'channel_stream' |
|
62
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md#delete-channelschannelstream_key |
|
63
|
|
|
* @param string $channel |
|
64
|
|
|
* @param string $queryString |
|
65
|
|
|
* @return \stdClass |
|
66
|
|
|
* @throws TwitchSDKException |
|
67
|
|
|
*/ |
|
68
|
|
|
public function resetStreamKey($channel, $queryString) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->request->request(sprintf(self::URI_CHANNEL_KEY, $channel) . $queryString, 'DELETE'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get the specified channel |
|
75
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md#get-channelschannel |
|
76
|
|
|
* @param string $channel |
|
77
|
|
|
* @return \stdClass |
|
78
|
|
|
* @throws TwitchSDKException |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getChannels($channel) |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->request->request(self::URI_CHANNELS . $channel); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns an array of users who are editors of specified channel |
|
87
|
|
|
* - requires scope 'channel_read' |
|
88
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md#get-channelschanneleditors |
|
89
|
|
|
* @param string $channel |
|
90
|
|
|
* @param string $queryString |
|
91
|
|
|
* @return \stdClass |
|
92
|
|
|
* @throws TwitchSDKException |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getEditors($channel, $queryString) |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->request->request(sprintf(self::URI_CHANNEL_EDITORS_AUTH, $channel) . $queryString); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Return team list for specified channel |
|
101
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/channels.md#get-channelschannelteams |
|
102
|
|
|
* @param string $channel |
|
103
|
|
|
* @return \stdClass |
|
104
|
|
|
* @throws TwitchSDKException |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getTeams($channel) |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->request->request(sprintf(self::URI_CHANNEL_TEAMS, $channel)); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|