1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\OAuth1\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth1\Signature\SignatureInterface; |
6
|
|
|
use OAuth\Common\Http\Uri\Uri; |
7
|
|
|
use OAuth\Common\Consumer\CredentialsInterface; |
8
|
|
|
use OAuth\Common\Http\Uri\UriInterface; |
9
|
|
|
use OAuth\Common\Storage\TokenStorageInterface; |
10
|
|
|
use OAuth\Common\Http\Client\ClientInterface; |
11
|
|
|
|
12
|
|
|
class Etsy extends AbstractService |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
protected $scopes = array(); |
16
|
|
|
|
17
|
|
|
public function __construct( |
18
|
|
|
CredentialsInterface $credentials, |
19
|
|
|
ClientInterface $httpClient, |
20
|
|
|
TokenStorageInterface $storage, |
21
|
|
|
SignatureInterface $signature, |
22
|
|
|
UriInterface $baseApiUri = null |
23
|
|
|
) { |
24
|
|
|
parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri); |
25
|
|
|
|
26
|
|
|
if (null === $baseApiUri) { |
27
|
|
|
$this->baseApiUri = new Uri('https://openapi.etsy.com/v2/'); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function getRequestTokenEndpoint() |
35
|
|
|
{ |
36
|
|
|
$uri = new Uri($this->baseApiUri . 'oauth/request_token'); |
37
|
|
|
$scopes = $this->getScopes(); |
38
|
|
|
|
39
|
|
|
if (count($scopes)) { |
40
|
|
|
$uri->setQuery('scope=' . implode('%20', $scopes)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return $uri; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function getAuthorizationEndpoint() |
50
|
|
|
{ |
51
|
|
|
return new Uri($this->baseApiUri); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function getAccessTokenEndpoint() |
58
|
|
|
{ |
59
|
|
|
return new Uri($this->baseApiUri . 'oauth/access_token'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Set the scopes for permissions |
64
|
|
|
* @see https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes |
65
|
|
|
* @param array $scopes |
66
|
|
|
* |
67
|
|
|
* @return $this |
68
|
|
|
*/ |
69
|
|
|
public function setScopes(array $scopes) |
70
|
|
|
{ |
71
|
|
|
if (!is_array($scopes)) { |
72
|
|
|
$scopes = array(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->scopes = $scopes; |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Return the defined scopes |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
|
|
public function getScopes() |
84
|
|
|
{ |
85
|
|
|
return $this->scopes; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
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.