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

Tumblr   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
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 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 3
1
<?php
2
/**
3
 * Class Tumblr
4
 *
5
 * @created      22.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\OAuth1Provider;
15
use chillerlan\OAuth\Core\ProviderException;
16
use Psr\Http\Message\ResponseInterface;
17
use function sprintf;
18
19
/**
20
 * @see https://www.tumblr.com/docs/en/api/v2
21
 */
22
class Tumblr extends OAuth1Provider{
23
24
	protected string  $requestTokenURL = 'https://www.tumblr.com/oauth/request_token';
25
	protected string  $authURL         = 'https://www.tumblr.com/oauth/authorize';
26
	protected string  $accessTokenURL  = 'https://www.tumblr.com/oauth/access_token';
27
	protected string  $apiURL          = 'https://api.tumblr.com/v2';
28
	protected ?string $userRevokeURL   = 'https://www.tumblr.com/settings/apps';
29
	protected ?string $apiDocs         = 'https://www.tumblr.com/docs/en/api/v2';
30
	protected ?string $applicationURL  = 'https://www.tumblr.com/oauth/apps';
31
32
33
	/**
34
	 * @inheritDoc
35
	 */
36
	public function me():ResponseInterface{
37
		$response = $this->request('/user/info');
38
		$status   = $response->getStatusCode();
39
40
		if($status === 200){
41
			return $response;
42
		}
43
44
		$json = MessageUtil::decodeJSON($response);
45
46
		if(isset($json->meta, $json->meta->msg)){
47
			throw new ProviderException($json->meta->msg);
48
		}
49
50
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
51
	}
52
53
}
54