1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\OAuth1\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth1\Signature\SignatureInterface; |
6
|
|
|
use OAuth\OAuth1\Token\StdOAuth1Token; |
7
|
|
|
use OAuth\Common\Http\Exception\TokenResponseException; |
8
|
|
|
use OAuth\Common\Http\Uri\Uri; |
9
|
|
|
use OAuth\Common\Consumer\CredentialsInterface; |
10
|
|
|
use OAuth\Common\Http\Uri\UriInterface; |
11
|
|
|
use OAuth\Common\Storage\TokenStorageInterface; |
12
|
|
|
use OAuth\Common\Http\Client\ClientInterface; |
13
|
|
|
|
14
|
|
|
class Etsy extends AbstractService |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
protected $scopes = array(); |
18
|
|
|
|
19
|
|
|
public function __construct( |
20
|
|
|
CredentialsInterface $credentials, |
21
|
|
|
ClientInterface $httpClient, |
22
|
|
|
TokenStorageInterface $storage, |
23
|
|
|
SignatureInterface $signature, |
24
|
|
|
UriInterface $baseApiUri = null |
25
|
|
|
) { |
26
|
|
|
parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri); |
27
|
|
|
|
28
|
|
|
if (null === $baseApiUri) { |
29
|
|
|
$this->baseApiUri = new Uri('https://openapi.etsy.com/v2/'); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function getRequestTokenEndpoint() |
37
|
|
|
{ |
38
|
|
|
$uri = new Uri($this->baseApiUri . 'oauth/request_token'); |
39
|
|
|
$scopes = $this->getScopes(); |
40
|
|
|
|
41
|
|
|
if (count($scopes)) { |
42
|
|
|
$uri->setQuery('scope=' . implode('%20', $scopes)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $uri; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getAuthorizationEndpoint() |
52
|
|
|
{ |
53
|
|
|
return new Uri($this->baseApiUri); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getAccessTokenEndpoint() |
60
|
|
|
{ |
61
|
|
|
return new Uri($this->baseApiUri . 'oauth/access_token'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Set the scopes for permissions |
66
|
|
|
* @see https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes |
67
|
|
|
* @param array $scopes |
68
|
|
|
* |
69
|
|
|
* @return $this |
70
|
|
|
*/ |
71
|
|
|
public function setScopes(array $scopes) |
72
|
|
|
{ |
73
|
|
|
if (!is_array($scopes)) { |
74
|
|
|
$scopes = array(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->scopes = $scopes; |
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Return the defined scopes |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
|
public function getScopes() |
86
|
|
|
{ |
87
|
|
|
return $this->scopes; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.