This repository was archived by the owner on Mar 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMixcloud.php
53 lines (43 loc) · 1.51 KB
/
Mixcloud.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Class Mixcloud
*
* @created 28.10.2017
* @author Smiley <smiley@chillerlan.net>
* @copyright 2017 Smiley
* @license MIT
*/
namespace chillerlan\OAuth\Providers;
use chillerlan\HTTP\Utils\MessageUtil;
use chillerlan\OAuth\Core\{OAuth2Provider, ProviderException};
use Psr\Http\Message\ResponseInterface;
use function sprintf;
/**
* note: a missing slash at the end of the path will end up in an HTTP/301
*
* @see https://www.mixcloud.com/developers/
*/
class Mixcloud extends OAuth2Provider{
protected string $authURL = 'https://www.mixcloud.com/oauth/authorize';
protected string $accessTokenURL = 'https://www.mixcloud.com/oauth/access_token';
protected string $apiURL = 'https://api.mixcloud.com';
protected string|null $userRevokeURL = 'https://www.mixcloud.com/settings/applications/';
protected string|null $apiDocs = 'https://www.mixcloud.com/developers/';
protected string|null $applicationURL = 'https://www.mixcloud.com/developers/create/';
protected int $authMethod = self::AUTH_METHOD_QUERY;
/**
* @inheritDoc
*/
public function me():ResponseInterface{
$response = $this->request('/me/');
$status = $response->getStatusCode();
if($status === 200){
return $response;
}
$json = MessageUtil::decodeJSON($response);
if(isset($json->error, $json->error->message)){
throw new ProviderException($json->error->message);
}
throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
}
}