Completed
Push — develop ( 6f2df9...3563b6 )
by Josef
01:50
created

Follow::getChannelFollows()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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