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

BigCartel   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 16
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 BigCartel
4
 *
5
 * @created      10.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\{CSRFToken, OAuth2Provider, ProviderException};
15
use Psr\Http\Message\ResponseInterface;
16
use function sprintf;
17
18
/**
19
 * BigCartel OAuth
20
 *
21
 * @see https://developers.bigcartel.com/api/v1
22
 * @see https://bigcartel.wufoo.com/confirm/big-cartel-api-application/
23
 */
24
class BigCartel extends OAuth2Provider implements CSRFToken{
25
26
	protected string  $authURL        = 'https://my.bigcartel.com/oauth/authorize';
27
	protected string  $accessTokenURL = 'https://api.bigcartel.com/oauth/token';
28
	protected string  $apiURL         = 'https://api.bigcartel.com/v1';
29
	protected ?string $userRevokeURL  = 'https://my.bigcartel.com/account';
30
	protected ?string $revokeURL      = 'https://api.bigcartel.com/oauth/deauthorize/{ACCOUNT_ID}'; // @todo
31
	protected ?string $apiDocs        = 'https://developers.bigcartel.com/api/v1';
32
	protected ?string $applicationURL = 'https://bigcartel.wufoo.com/forms/big-cartel-api-application/';
33
	protected array   $apiHeaders     = ['Accept' => 'application/vnd.api+json'];
34
35
	/**
36
	 * @inheritDoc
37
	 */
38
	public function me():ResponseInterface{
39
		$response = $this->request('/accounts');
40
		$status   = $response->getStatusCode();
41
42
		if($status === 200){
43
			return $response;
44
		}
45
46
		$json = MessageUtil::decodeJSON($response);
47
48
		if(isset($json->error)){
49
			throw new ProviderException($json->error);
50
		}
51
52
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
53
	}
54
55
}
56