1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace jofner\SDK\TwitchTV\Methods; |
4
|
|
|
|
5
|
|
|
use jofner\SDK\TwitchTV\TwitchRequest; |
6
|
|
|
use jofner\SDK\TwitchTV\TwitchSDKException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Follow 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 Follow |
16
|
|
|
{ |
17
|
|
|
/** @var TwitchRequest */ |
18
|
|
|
protected $request; |
19
|
|
|
|
20
|
|
|
const URI_CHANNEL_FOLLOWS = 'channels/%s/follows'; |
21
|
|
|
const URI_USER_FOLLOWS_CHANNEL = 'users/%s/follows/channels'; |
22
|
|
|
const URI_USER_FOLLOW_RELATION = 'users/%s/follows/channels/%s'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Follow constructor |
26
|
|
|
* @param TwitchRequest $request |
27
|
|
|
*/ |
28
|
|
|
public function __construct(TwitchRequest $request) |
29
|
|
|
{ |
30
|
|
|
$this->request = $request; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns a list of follow objects |
35
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/follows.md#get-channelschannelfollows |
36
|
|
|
* @param string $channel |
37
|
|
|
* @param string $queryString |
38
|
|
|
* @return \stdClass |
39
|
|
|
* @throws TwitchSDKException |
40
|
|
|
*/ |
41
|
|
|
public function getChannelFollows($channel, $queryString) |
42
|
|
|
{ |
43
|
|
|
return $this->request->request(sprintf(self::URI_CHANNEL_FOLLOWS, $channel) . $queryString); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get a user's list of followed channels |
48
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/follows.md#get-usersuserfollowschannels |
49
|
|
|
* @param $user |
50
|
|
|
* @param $queryString |
51
|
|
|
* @return \stdClass |
52
|
|
|
* @throws TwitchSDKException |
53
|
|
|
*/ |
54
|
|
|
public function userFollowChannels($user, $queryString) |
55
|
|
|
{ |
56
|
|
|
return $this->request->request(sprintf(self::URI_USER_FOLLOWS_CHANNEL, $user) . $queryString); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns 404 Not Found if :user is not following :target. Returns a follow object otherwise |
61
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/follows.md#get-usersuserfollowschannelstarget |
62
|
|
|
* @param string $user |
63
|
|
|
* @param string $channel |
64
|
|
|
* @return \stdClass |
65
|
|
|
* @throws TwitchSDKException |
66
|
|
|
*/ |
67
|
|
|
public function userIsFollowingChannel($user, $channel) |
68
|
|
|
{ |
69
|
|
|
return $this->request->request(sprintf(self::URI_USER_FOLLOW_RELATION, $user, $channel)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Set user to follow given channel |
74
|
|
|
* - requires scope 'user_follows_edit' |
75
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/follows.md#put-usersuserfollowschannelstarget |
76
|
|
|
* @param string $user |
77
|
|
|
* @param string $channel |
78
|
|
|
* @param string $queryString |
79
|
|
|
* @return \stdClass |
80
|
|
|
* @throws TwitchSDKException |
81
|
|
|
*/ |
82
|
|
|
public function followChannel($user, $channel, $queryString) |
83
|
|
|
{ |
84
|
|
|
return $this->request->request(sprintf(self::URI_USER_FOLLOW_RELATION, $user, $channel) . $queryString, 'PUT'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Set user to unfollow given channel |
89
|
|
|
* - requires scope 'user_follows_edit' |
90
|
|
|
* @see https://github.com/justintv/Twitch-API/blob/master/v3_resources/follows.md#delete-usersuserfollowschannelstarget |
91
|
|
|
* @param string $user |
92
|
|
|
* @param string $channel |
93
|
|
|
* @param string $queryString |
94
|
|
|
* @return \stdClass |
95
|
|
|
* @throws TwitchSDKException |
96
|
|
|
*/ |
97
|
|
|
public function unfollowChannel($user, $channel, $queryString) |
98
|
|
|
{ |
99
|
|
|
return $this->request->request(sprintf(self::URI_USER_FOLLOW_RELATION, $user, $channel) . $queryString, 'DELETE'); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|