Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Etsy.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.48 KiB


 001  <?php
 002   
 003  namespace OAuth\OAuth1\Service;
 004   
 005  use OAuth\OAuth1\Signature\SignatureInterface;
 006  use OAuth\OAuth1\Token\StdOAuth1Token;
 007  use OAuth\Common\Http\Exception\TokenResponseException;
 008  use OAuth\Common\Http\Uri\Uri;
 009  use OAuth\Common\Consumer\CredentialsInterface;
 010  use OAuth\Common\Http\Uri\UriInterface;
 011  use OAuth\Common\Storage\TokenStorageInterface;
 012  use OAuth\Common\Http\Client\ClientInterface;
 013   
 014  class Etsy extends AbstractService
 015  {
 016   
 017      protected $scopes = array();
 018   
 019      public function __construct(
 020          CredentialsInterface $credentials,
 021          ClientInterface $httpClient,
 022          TokenStorageInterface $storage,
 023          SignatureInterface $signature,
 024          UriInterface $baseApiUri = null
 025      ) {
 026          parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
 027   
 028          if (null === $baseApiUri) {
 029              $this->baseApiUri = new Uri('https://openapi.etsy.com/v2/');
 030          }
 031      }
 032   
 033      /**
 034       * {@inheritdoc}
 035       */
 036      public function getRequestTokenEndpoint()
 037      {
 038          $uri = new Uri($this->baseApiUri . 'oauth/request_token');
 039          $scopes = $this->getScopes();
 040   
 041          if (count($scopes)) {
 042              $uri->setQuery('scope=' . implode('%20', $scopes));
 043          }
 044   
 045          return $uri;
 046      }
 047   
 048      /**
 049       * {@inheritdoc}
 050       */
 051      public function getAuthorizationEndpoint()
 052      {
 053          return new Uri($this->baseApiUri);
 054      }
 055   
 056      /**
 057       * {@inheritdoc}
 058       */
 059      public function getAccessTokenEndpoint()
 060      {
 061          return new Uri($this->baseApiUri . 'oauth/access_token');
 062      }
 063   
 064      /**
 065       * {@inheritdoc}
 066       */
 067      protected function parseRequestTokenResponse($responseBody)
 068      {
 069          parse_str($responseBody, $data);
 070   
 071          if (null === $data || !is_array($data)) {
 072              throw new TokenResponseException('Unable to parse response.');
 073          } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
 074              throw new TokenResponseException('Error in retrieving token.');
 075          }
 076   
 077          return $this->parseAccessTokenResponse($responseBody);
 078      }
 079   
 080      /**
 081       * {@inheritdoc}
 082       */
 083      protected function parseAccessTokenResponse($responseBody)
 084      {
 085          parse_str($responseBody, $data);
 086   
 087          if (null === $data || !is_array($data)) {
 088              throw new TokenResponseException('Unable to parse response.');
 089          } elseif (isset($data['error'])) {
 090              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
 091          }
 092   
 093          $token = new StdOAuth1Token();
 094   
 095          $token->setRequestToken($data['oauth_token']);
 096          $token->setRequestTokenSecret($data['oauth_token_secret']);
 097          $token->setAccessToken($data['oauth_token']);
 098          $token->setAccessTokenSecret($data['oauth_token_secret']);
 099   
 100          $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
 101          unset($data['oauth_token'], $data['oauth_token_secret']);
 102          $token->setExtraParams($data);
 103   
 104          return $token;
 105      }
 106   
 107      /**
 108       * Set the scopes for permissions
 109       * @see https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes
 110       * @param array $scopes
 111       *
 112       * @return $this
 113       */
 114      public function setScopes(array $scopes)
 115      {
 116          if (!is_array($scopes)) {
 117              $scopes = array();
 118          }
 119   
 120          $this->scopes = $scopes;
 121          return $this;
 122      }
 123   
 124      /**
 125       * Return the defined scopes
 126       * @return array
 127       */
 128      public function getScopes()
 129      {
 130          return $this->scopes;
 131      }
 132  }
 133