[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/carlos-mg89/oauth/src/OAuth/OAuth1/Service/ -> Flickr.php (source)

   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 Flickr extends AbstractService
  15  {
  16      protected $format;
  17  
  18      public function __construct(
  19          CredentialsInterface $credentials,
  20          ClientInterface $httpClient,
  21          TokenStorageInterface $storage,
  22          SignatureInterface $signature,
  23          ?UriInterface $baseApiUri = null
  24      ) {
  25          parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
  26          if ($baseApiUri === null) {
  27              $this->baseApiUri = new Uri('https://api.flickr.com/services/rest/');
  28          }
  29      }
  30  
  31      public function getRequestTokenEndpoint()
  32      {
  33          return new Uri('https://www.flickr.com/services/oauth/request_token');
  34      }
  35  
  36      public function getAuthorizationEndpoint()
  37      {
  38          return new Uri('https://www.flickr.com/services/oauth/authorize');
  39      }
  40  
  41      public function getAccessTokenEndpoint()
  42      {
  43          return new Uri('https://www.flickr.com/services/oauth/access_token');
  44      }
  45  
  46      protected function parseRequestTokenResponse($responseBody)
  47      {
  48          parse_str($responseBody, $data);
  49          if (null === $data || !is_array($data)) {
  50              throw new TokenResponseException('Unable to parse response.');
  51          } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] != 'true') {
  52              throw new TokenResponseException('Error in retrieving token.');
  53          }
  54  
  55          return $this->parseAccessTokenResponse($responseBody);
  56      }
  57  
  58      protected function parseAccessTokenResponse($responseBody)
  59      {
  60          parse_str($responseBody, $data);
  61          if ($data === null || !is_array($data)) {
  62              throw new TokenResponseException('Unable to parse response.');
  63          } elseif (isset($data['error'])) {
  64              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
  65          }
  66  
  67          $token = new StdOAuth1Token();
  68          $token->setRequestToken($data['oauth_token']);
  69          $token->setRequestTokenSecret($data['oauth_token_secret']);
  70          $token->setAccessToken($data['oauth_token']);
  71          $token->setAccessTokenSecret($data['oauth_token_secret']);
  72          $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
  73          unset($data['oauth_token'], $data['oauth_token_secret']);
  74          $token->setExtraParams($data);
  75  
  76          return $token;
  77      }
  78  
  79      public function request($path, $method = 'GET', $body = null, array $extraHeaders = [])
  80      {
  81          $uri = $this->determineRequestUriFromPath('/', $this->baseApiUri);
  82          $uri->addToQuery('method', $path);
  83  
  84          if (!empty($this->format)) {
  85              $uri->addToQuery('format', $this->format);
  86  
  87              if ($this->format === 'json') {
  88                  $uri->addToQuery('nojsoncallback', 1);
  89              }
  90          }
  91  
  92          $token = $this->storage->retrieveAccessToken($this->service());
  93          $extraHeaders = array_merge($this->getExtraApiHeaders(), $extraHeaders);
  94          $authorizationHeader = [
  95              'Authorization' => $this->buildAuthorizationHeaderForAPIRequest($method, $uri, $token, $body),
  96          ];
  97          $headers = array_merge($authorizationHeader, $extraHeaders);
  98  
  99          return $this->httpClient->retrieveResponse($uri, $body, $headers, $method);
 100      }
 101  
 102      public function requestRest($path, $method = 'GET', $body = null, array $extraHeaders = [])
 103      {
 104          return $this->request($path, $method, $body, $extraHeaders);
 105      }
 106  
 107      public function requestXmlrpc($path, $method = 'GET', $body = null, array $extraHeaders = [])
 108      {
 109          $this->format = 'xmlrpc';
 110  
 111          return $this->request($path, $method, $body, $extraHeaders);
 112      }
 113  
 114      public function requestSoap($path, $method = 'GET', $body = null, array $extraHeaders = [])
 115      {
 116          $this->format = 'soap';
 117  
 118          return $this->request($path, $method, $body, $extraHeaders);
 119      }
 120  
 121      public function requestJson($path, $method = 'GET', $body = null, array $extraHeaders = [])
 122      {
 123          $this->format = 'json';
 124  
 125          return $this->request($path, $method, $body, $extraHeaders);
 126      }
 127  
 128      public function requestPhp($path, $method = 'GET', $body = null, array $extraHeaders = [])
 129      {
 130          $this->format = 'php_serial';
 131  
 132          return $this->request($path, $method, $body, $extraHeaders);
 133      }
 134  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1