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

Netatmo.php

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


001  <?php
002  /**
003   * Netatmo service.
004   *
005   * @author  Pedro Amorim <contact@pamorim.fr>
006   * @license http://www.opensource.org/licenses/mit-license.html MIT License
007   * @link    https://dev.netatmo.com/doc/
008   */
009   
010  namespace OAuth\OAuth2\Service;
011   
012  use OAuth\OAuth2\Token\StdOAuth2Token;
013  use OAuth\Common\Http\Exception\TokenResponseException;
014  use OAuth\Common\Http\Uri\Uri;
015  use OAuth\Common\Consumer\CredentialsInterface;
016  use OAuth\Common\Http\Client\ClientInterface;
017  use OAuth\Common\Storage\TokenStorageInterface;
018  use OAuth\Common\Http\Uri\UriInterface;
019   
020  /**
021   * Netatmo service.
022   *
023   * @author  Pedro Amorim <contact@pamorim.fr>
024   * @license http://www.opensource.org/licenses/mit-license.html MIT License
025   * @link    https://dev.netatmo.com/doc/
026   */
027  class Netatmo extends AbstractService
028  {
029   
030      // SCOPES
031      // @link https://dev.netatmo.com/doc/authentication/scopes
032   
033      // Used to read weather station's data (devicelist, getmeasure)
034      const SCOPE_STATION_READ        = 'read_station';
035      // Used to read thermostat's data (devicelist, getmeasure, getthermstate)
036      const SCOPE_THERMOSTAT_READ     = 'read_thermostat';
037      // Used to configure the thermostat (syncschedule, setthermpoint)
038      const SCOPE_THERMOSTAT_WRITE    = 'write_thermostat';
039   
040      public function __construct(
041          CredentialsInterface $credentials,
042          ClientInterface $httpClient,
043          TokenStorageInterface $storage,
044          $scopes = array(),
045          UriInterface $baseApiUri = null
046      ) {
047          parent::__construct(
048              $credentials,
049              $httpClient,
050              $storage,
051              $scopes,
052              $baseApiUri,
053              true // use parameter state
054          );
055   
056          if (null === $baseApiUri) {
057              $this->baseApiUri = new Uri('https://api.netatmo.net/');
058          }
059      }
060   
061      /**
062       * {@inheritdoc}
063       */
064      public function getAuthorizationEndpoint()
065      {
066          return new Uri($this->baseApiUri.'oauth2/authorize');
067   
068      }
069   
070      /**
071       * {@inheritdoc}
072       */
073      public function getAccessTokenEndpoint()
074      {
075          return new Uri($this->baseApiUri.'oauth2/token');
076      }
077   
078      /**
079       * {@inheritdoc}
080       */
081      protected function getAuthorizationMethod()
082      {
083          return static::AUTHORIZATION_METHOD_QUERY_STRING;
084      }
085   
086      /**
087       * {@inheritdoc}
088       */
089      protected function parseAccessTokenResponse($responseBody)
090      {
091          $data = json_decode($responseBody, true);
092   
093          if (null === $data || !is_array($data)) {
094              throw new TokenResponseException('Unable to parse response.');
095          } elseif (isset($data['error'])) {
096              throw new TokenResponseException(
097                  'Error in retrieving token: "' . $data['error'] . '"'
098              );
099          }
100   
101          $token = new StdOAuth2Token();
102          $token->setAccessToken($data['access_token']);
103          $token->setLifetime($data['expires_in']);
104   
105          if (isset($data['refresh_token'])) {
106              $token->setRefreshToken($data['refresh_token']);
107              unset($data['refresh_token']);
108          }
109   
110          unset($data['access_token']);
111          unset($data['expires_in']);
112   
113          $token->setExtraParams($data);
114   
115          return $token;
116      }
117  }
118