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
|
|
|
* Subscription 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 Subscription |
18
|
|
|
{ |
19
|
|
|
/** @var TwitchRequest */ |
20
|
|
|
protected $request; |
21
|
|
|
|
22
|
|
|
const URI_CHANNEL_SUBSCRIPTIONS = 'channels/%s/subscriptions'; |
23
|
|
|
const URI_CHANNEL_SUBSCRIPTIONS_USER = 'channels/%s/subscriptions/%s'; |
24
|
|
|
const URI_USER_SUBSCRIPTIONS_CHANNEL = 'users/%s/subscriptions/%s'; |
25
|
|
|
|
26
|
|
|
public function __construct(TwitchRequest $request) |
27
|
|
|
{ |
28
|
|
|
$this->request = $request; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @description Returns an array of subscriptions who are subscribed to specified channel |
33
|
|
|
* - requires scope 'channel_subscriptions' |
34
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-channelschannelsubscriptions |
35
|
|
|
* @param string $channel |
36
|
|
|
* @param string $queryString |
37
|
|
|
* @return \stdClass |
38
|
|
|
* @throws TwitchException |
39
|
|
|
*/ |
40
|
|
|
public function getSubscriptions($channel, $queryString) |
41
|
|
|
{ |
42
|
|
|
return $this->request->request(sprintf(self::URI_CHANNEL_SUBSCRIPTIONS, $channel) . $queryString); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns user object if that user is subscribed |
47
|
|
|
* - requires scope 'channel_check_subscription' for channel |
48
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/subscriptions.md#get-channelschannelsubscriptionsuser |
49
|
|
|
* @param string $channel |
50
|
|
|
* @param string $user |
51
|
|
|
* @param string $queryString |
52
|
|
|
* @return \stdClass |
53
|
|
|
* @throws TwitchException |
54
|
|
|
*/ |
55
|
|
|
public function getSubscribedUser($channel, $user, $queryString) |
56
|
|
|
{ |
57
|
|
|
return $this->request->request(sprintf(self::URI_CHANNEL_SUBSCRIPTIONS_USER, $channel, $user) . $queryString); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns a channel object that user subscribes to |
62
|
|
|
* - requires scope 'user_subscriptions' for user |
63
|
|
|
* @param string $user |
64
|
|
|
* @param string $channel |
65
|
|
|
* @param string $queryString |
66
|
|
|
* @return \stdClass |
67
|
|
|
* @throws TwitchException |
68
|
|
|
*/ |
69
|
|
|
public function getSubscribedToChannel($user, $channel, $queryString) |
70
|
|
|
{ |
71
|
|
|
return $this->request->request(sprintf(self::URI_USER_SUBSCRIPTIONS_CHANNEL, $user, $channel) . $queryString); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|