1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ritero\SDK\TwitchTV\Methods; |
4
|
|
|
|
5
|
|
|
use ritero\SDK\TwitchTV\TwitchRequest; |
6
|
|
|
use ritero\SDK\TwitchTV\TwitchException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* TwitchTV API SDK for PHP |
10
|
|
|
* |
11
|
|
|
* Streams 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
|
|
View Code Duplication |
class Stream |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** @var TwitchRequest */ |
20
|
|
|
protected $request; |
21
|
|
|
|
22
|
|
|
const URI_STREAM = 'streams/'; |
23
|
|
|
const URI_STREAMS = 'streams'; |
24
|
|
|
const URI_STREAMS_FEATURED = 'streams/featured'; |
25
|
|
|
const URI_STREAM_SUMMARY = 'streams/summary'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Stream constructor |
29
|
|
|
* @param TwitchRequest $request |
30
|
|
|
*/ |
31
|
|
|
public function __construct(TwitchRequest $request) |
32
|
|
|
{ |
33
|
|
|
$this->request = $request; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the specified channel's stream |
38
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamschannel |
39
|
|
|
* @param $channel |
40
|
|
|
* @return \stdClass |
41
|
|
|
* @throws TwitchException |
42
|
|
|
*/ |
43
|
|
|
public function getStream($channel) |
44
|
|
|
{ |
45
|
|
|
$this->request->setApiVersion(3); |
46
|
|
|
|
47
|
|
|
return $this->request->request(self::URI_STREAM . $channel); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns a list of streams |
52
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streams |
53
|
|
|
* @param $queryString |
54
|
|
|
* @return \stdClass |
55
|
|
|
* @throws TwitchException |
56
|
|
|
*/ |
57
|
|
|
public function getStreams($queryString) |
58
|
|
|
{ |
59
|
|
|
$this->request->setApiVersion(3); |
60
|
|
|
|
61
|
|
|
return $this->request->request(self::URI_STREAMS . $queryString); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns a list of featured (promoted) stream |
66
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamsfeatured |
67
|
|
|
* @param $queryString |
68
|
|
|
* @return \stdClass |
69
|
|
|
* @throws TwitchException |
70
|
|
|
*/ |
71
|
|
|
public function getFeatured($queryString) |
72
|
|
|
{ |
73
|
|
|
$this->request->setApiVersion(3); |
74
|
|
|
|
75
|
|
|
return $this->request->request(self::URI_STREAMS_FEATURED . $queryString); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns a summary of current streams |
80
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamssummary |
81
|
|
|
* @param $queryString |
82
|
|
|
* @return \stdClass |
83
|
|
|
* @throws TwitchException |
84
|
|
|
*/ |
85
|
|
|
public function getSummary($queryString) |
86
|
|
|
{ |
87
|
|
|
$this->request->setApiVersion(3); |
88
|
|
|
|
89
|
|
|
return $this->request->request(self::URI_STREAM_SUMMARY . $queryString); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.