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