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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Mailchimp.php
001 <?php
002
003 namespace OAuth\OAuth2\Service;
004
005 use OAuth\OAuth2\Token\StdOAuth2Token;
006 use OAuth\Common\Http\Exception\TokenResponseException;
007 use OAuth\Common\Http\Uri\Uri;
008 use OAuth\Common\Consumer\CredentialsInterface;
009 use OAuth\Common\Http\Client\ClientInterface;
010 use OAuth\Common\Storage\TokenStorageInterface;
011 use OAuth\Common\Http\Uri\UriInterface;
012
013 class Mailchimp extends AbstractService
014 {
015 public function __construct(
016 CredentialsInterface $credentials,
017 ClientInterface $httpClient,
018 TokenStorageInterface $storage,
019 $scopes = array(),
020 UriInterface $baseApiUri = null
021 ) {
022 parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
023
024 if (is_null($this->baseApiUri) && $storage->hasAccessToken($this->service())) {
025 $this->setBaseApiUri($storage->retrieveAccessToken($this->service()));
026 }
027 }
028
029 /**
030 * {@inheritdoc}
031 */
032 protected function getAuthorizationMethod()
033 {
034 return static::AUTHORIZATION_METHOD_QUERY_STRING_V3;
035 }
036
037 /**
038 * {@inheritdoc}
039 */
040 public function getAuthorizationEndpoint()
041 {
042 return new Uri('https://login.mailchimp.com/oauth2/authorize');
043 }
044
045 /**
046 * {@inheritdoc}
047 */
048 public function getAccessTokenEndpoint()
049 {
050 return new Uri('https://login.mailchimp.com/oauth2/token');
051 }
052
053 /**
054 * {@inheritdoc}
055 */
056 protected function parseAccessTokenResponse($responseBody)
057 {
058 // Parse JSON
059 $data = json_decode($responseBody, true);
060
061 // Do validation.
062 if (null === $data || !is_array($data)) {
063 throw new TokenResponseException('Unable to parse response.');
064 } elseif (isset($data['error'])) {
065 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
066 }
067
068 // Create token object.
069 $token = new StdOAuth2Token($data['access_token']);
070
071 // Set the right API endpoint.
072 $this->setBaseApiUri($token);
073
074 // Mailchimp tokens evidently never expire...
075 $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
076
077 return $token;
078 }
079
080 /**
081 * {@inheritdoc}
082 */
083 public function request($path, $method = 'GET', $body = null, array $extraHeaders = array())
084 {
085 if (is_null($this->baseApiUri)) {
086 $this->setBaseApiUri($this->storage->retrieveAccessToken($this->service()));
087 }
088
089 return parent::request($path, $method, $body, $extraHeaders);
090 }
091
092 /**
093 * Set the right base endpoint.
094 *
095 * @param StdOAuth2Token $token
096 */
097 protected function setBaseApiUri(StdOAuth2Token $token)
098 {
099 // Make request uri.
100 $endpoint = 'https://login.mailchimp.com/oauth2/metadata?oauth_token='. $token->getAccessToken();
101
102 // Grab meta data about the token.
103 $response = $this->httpClient->retrieveResponse(new Uri($endpoint), array(), array(), 'GET');
104
105 // Parse JSON.
106 $meta = json_decode($response, true);
107
108 // Set base api uri.
109 $this->baseApiUri = new Uri('https://'. $meta['dc'] .'.api.mailchimp.com/2.0/');
110
111 // Allow chaining.
112 return $this;
113 }
114 }
115