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