Passed
Push — main ( e868ec...9f95cc )
by smiley
12:00
created

Mixcloud   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 1
b 0
f 0
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 3
1
<?php
2
/**
3
 * Class Mixcloud
4
 *
5
 * @created      28.10.2017
6
 * @author       Smiley <[email protected]>
7
 * @copyright    2017 Smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\OAuth\Providers;
12
13
use chillerlan\HTTP\Utils\MessageUtil;
14
use chillerlan\OAuth\Core\OAuth2Provider;
15
use chillerlan\OAuth\Core\ProviderException;
16
use Psr\Http\Message\ResponseInterface;
17
use function sprintf;
18
19
/**
20
 * note: a missing slash at the end of the path will end up in a HTTP/301
21
 *
22
 * @see https://www.mixcloud.com/developers/
23
 */
24
class Mixcloud extends OAuth2Provider{
25
26
	protected string  $authURL        = 'https://www.mixcloud.com/oauth/authorize';
27
	protected string  $accessTokenURL = 'https://www.mixcloud.com/oauth/access_token';
28
	protected string  $apiURL         = 'https://api.mixcloud.com';
29
	protected ?string $userRevokeURL  = 'https://www.mixcloud.com/settings/applications/';
30
	protected ?string $apiDocs        = 'https://www.mixcloud.com/developers/';
31
	protected ?string $applicationURL = 'https://www.mixcloud.com/developers/create/';
32
	protected int     $authMethod     = self::AUTH_METHOD_QUERY;
33
34
	/**
35
	 * @inheritDoc
36
	 */
37
	public function me():ResponseInterface{
38
		$response = $this->request('/me/');
39
		$status   = $response->getStatusCode();
40
41
		if($status === 200){
42
			return $response;
43
		}
44
45
		$json = MessageUtil::decodeJSON($response);
46
47
		if(isset($json->error, $json->error->message)){
48
			throw new ProviderException($json->error->message);
49
		}
50
51
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
52
	}
53
54
}
55