|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class Discogs |
|
4
|
|
|
* |
|
5
|
|
|
* @created 08.04.2018 |
|
6
|
|
|
* @author Smiley <[email protected]> |
|
7
|
|
|
* @copyright 2018 Smiley |
|
8
|
|
|
* @license MIT |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace chillerlan\OAuth\Providers; |
|
12
|
|
|
|
|
13
|
|
|
use chillerlan\HTTP\Utils\MessageUtil; |
|
14
|
|
|
use chillerlan\OAuth\Core\OAuth1Provider; |
|
15
|
|
|
use chillerlan\OAuth\Core\ProviderException; |
|
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
17
|
|
|
use function sprintf; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @see https://www.discogs.com/developers/ |
|
21
|
|
|
* @see https://www.discogs.com/developers/#page:authentication,header:authentication-oauth-flow |
|
22
|
|
|
*/ |
|
23
|
|
|
class Discogs extends OAuth1Provider{ |
|
24
|
|
|
|
|
25
|
|
|
protected string $requestTokenURL = 'https://api.discogs.com/oauth/request_token'; |
|
26
|
|
|
protected string $authURL = 'https://www.discogs.com/oauth/authorize'; |
|
27
|
|
|
protected string $accessTokenURL = 'https://api.discogs.com/oauth/access_token'; |
|
28
|
|
|
protected string $apiURL = 'https://api.discogs.com'; |
|
29
|
|
|
protected ?string $revokeURL = 'https://www.discogs.com/oauth/revoke'; // ?access_key=<TOKEN> |
|
30
|
|
|
protected ?string $userRevokeURL = 'https://www.discogs.com/settings/applications'; |
|
31
|
|
|
protected ?string $apiDocs = 'https://www.discogs.com/developers/'; |
|
32
|
|
|
protected ?string $applicationURL = 'https://www.discogs.com/settings/developers'; |
|
33
|
|
|
protected array $apiHeaders = ['Accept' => 'application/vnd.discogs.v2.discogs+json']; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritDoc |
|
37
|
|
|
*/ |
|
38
|
|
|
public function me():ResponseInterface{ |
|
39
|
|
|
$response = $this->request('/oauth/identity'); |
|
40
|
|
|
$status = $response->getStatusCode(); |
|
41
|
|
|
|
|
42
|
|
|
if($status === 200){ |
|
43
|
|
|
return $response; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$json = MessageUtil::decodeJSON($response); |
|
47
|
|
|
|
|
48
|
|
|
if(isset($json->message)){ |
|
49
|
|
|
throw new ProviderException($json->message); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
throw new ProviderException(sprintf('user info error error HTTP/%s', $status)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|