Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
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 |
Etsy.php
01 <?php
02 namespace OAuth\OAuth1\Service;
03
04 use OAuth\OAuth1\Signature\SignatureInterface;
05 use OAuth\OAuth1\Token\StdOAuth1Token;
06 use OAuth\Common\Http\Exception\TokenResponseException;
07 use OAuth\Common\Http\Uri\Uri;
08 use OAuth\Common\Consumer\Credentials;
09 use OAuth\Common\Http\Uri\UriInterface;
10 use OAuth\Common\Storage\TokenStorageInterface;
11 use OAuth\Common\Http\Client\ClientInterface;
12
13 class Etsy extends AbstractService
14 {
15 public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, SignatureInterface $signature, UriInterface $baseApiUri = null)
16 {
17 parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
18 if( null === $baseApiUri ) {
19 $this->baseApiUri = new Uri('http://openapi.etsy.com/v2/');
20 }
21 }
22
23 /**
24 * @return \OAuth\Common\Http\Uri\UriInterface
25 */
26 public function getRequestTokenEndpoint()
27 {
28 return new Uri($this->baseApiUri . 'oauth/request_token');
29 }
30
31 /**
32 * Not required method!
33 * @return \OAuth\Common\Http\Uri\UriInterface
34 */
35 public function getAuthorizationEndpoint()
36 {
37 return new Uri($this->baseApiUri);
38 }
39
40 /**
41 * @return \OAuth\Common\Http\Uri\UriInterface
42 */
43 public function getAccessTokenEndpoint()
44 {
45 return new Uri($this->baseApiUri . 'oauth/access_token');
46 }
47
48 /**
49 * We need a separate request token parser only to verify the `oauth_callback_confirmed` parameter. For the actual
50 * parsing we can just use the default access token parser.
51 *
52 * @param string $responseBody
53 * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth1\Token\StdOAuth1Token
54 * @throws \OAuth\Common\Http\Exception\TokenResponseException
55 */
56 protected function parseRequestTokenResponse($responseBody)
57 {
58 parse_str($responseBody, $data);
59
60 if( null === $data || !is_array($data) ) {
61 throw new TokenResponseException('Unable to parse response.');
62 } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] != 'true') {
63 throw new TokenResponseException('Error in retrieving token.');
64 }
65
66 return $this->parseAccessTokenResponse($responseBody);
67 }
68
69 /**
70 * @param string $responseBody
71 * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth1\Token\StdOAuth1Token
72 * @throws \OAuth\Common\Http\Exception\TokenResponseException
73 */
74 protected function parseAccessTokenResponse($responseBody)
75 {
76 parse_str($responseBody, $data);
77
78 if( null === $data || !is_array($data) ) {
79 throw new TokenResponseException('Unable to parse response.');
80 } elseif( isset($data['error'] ) ) {
81 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
82 }
83
84 $token = new StdOAuth1Token();
85
86 $token->setRequestToken( $data['oauth_token'] );
87 $token->setRequestTokenSecret( $data['oauth_token_secret'] );
88 $token->setAccessToken( $data['oauth_token'] );
89 $token->setAccessTokenSecret( $data['oauth_token_secret'] );
90
91 $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
92 unset( $data['oauth_token'], $data['oauth_token_secret'] );
93 $token->setExtraParams( $data );
94
95 return $token;
96 }
97 }
98