| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace OAuth\OAuth1\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use OAuth\Common\Consumer\CredentialsInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use OAuth\Common\Http\Client\ClientInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use OAuth\Common\Http\Exception\TokenResponseException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use OAuth\Common\Http\Uri\Uri; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use OAuth\Common\Http\Uri\UriInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use OAuth\Common\Storage\TokenStorageInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use OAuth\OAuth1\Signature\SignatureInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use OAuth\OAuth1\Token\StdOAuth1Token; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | class ScoopIt extends AbstractService | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |         CredentialsInterface $credentials, | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |         ClientInterface $httpClient, | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         TokenStorageInterface $storage, | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         SignatureInterface $signature, | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         ?UriInterface $baseApiUri = null | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         if (null === $baseApiUri) { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             $this->baseApiUri = new Uri('https://www.scoop.it/api/1/'); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     public function getRequestTokenEndpoint() | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         return new Uri('https://www.scoop.it/oauth/request'); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     public function getAuthorizationEndpoint() | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         return new Uri('https://www.scoop.it/oauth/authorize'); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     public function getAccessTokenEndpoint() | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         return new Uri('https://www.scoop.it/oauth/access'); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     protected function parseRequestTokenResponse($responseBody) | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         parse_str($responseBody, $data); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         if (null === $data || !is_array($data)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             throw new TokenResponseException('Unable to parse response.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |             throw new TokenResponseException('Error in retrieving token.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         return $this->parseAccessTokenResponse($responseBody); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      * {@inheritdoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     protected function parseAccessTokenResponse($responseBody) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         parse_str($responseBody, $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         if (null === $data || !is_array($data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             throw new TokenResponseException('Unable to parse response.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         } elseif (isset($data['error'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $token = new StdOAuth1Token(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $token->setRequestToken($data['oauth_token']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $token->setRequestTokenSecret($data['oauth_token_secret']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $token->setAccessToken($data['oauth_token']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $token->setAccessTokenSecret($data['oauth_token_secret']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         unset($data['oauth_token'], $data['oauth_token_secret']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $token->setExtraParams($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 94 |  |  |         return $token; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 96 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 97 |  |  |  |