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

Instagram   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 3
1
<?php
2
/**
3
 * Class Instagram
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
 * @see https://developers.facebook.com/docs/instagram
20
 * @see https://developers.facebook.com/docs/instagram-basic-display-api/reference/oauth-authorize
21
 */
22
class Instagram extends OAuth2Provider implements CSRFToken{
23
24
	public const SCOPE_BASIC          = 'basic';
25
	public const SCOPE_COMMENTS       = 'comments';
26
	public const SCOPE_RELATIONSHIPS  = 'relationships';
27
	public const SCOPE_LIKES          = 'likes';
28
	public const SCOPE_PUBLIC_CONTENT = 'public_content';
29
	public const SCOPE_FOLLOWER_LIST  = 'follower_list';
30
31
	protected string  $authURL        = 'https://api.instagram.com/oauth/authorize';
32
	protected string  $accessTokenURL = 'https://api.instagram.com/oauth/access_token';
33
	protected string  $apiURL         = 'https://api.instagram.com';
34
	protected ?string $userRevokeURL  = 'https://www.instagram.com/accounts/manage_access/';
35
	protected ?string $apiDocs        = 'https://www.instagram.com/developer/';
36
	protected ?string $applicationURL = 'https://www.instagram.com/developer/clients/manage/';
37
#	protected int     $authMethod     = self::AUTH_METHOD_QUERY;
38
39
	protected array $defaultScopes    = [
40
		self::SCOPE_BASIC,
41
		self::SCOPE_PUBLIC_CONTENT,
42
	];
43
44
	/**
45
	 * @inheritDoc
46
	 */
47
	public function me():ResponseInterface{
48
		$response = $this->request('/me/');
49
		$status   = $response->getStatusCode();
50
51
		if($status === 200){
52
			return $response;
53
		}
54
55
		$json = MessageUtil::decodeJSON($response);
56
57
		if(isset($json->error, $json->error_description)){
58
			throw new ProviderException($json->error_description);
59
		}
60
61
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
62
	}
63
}
64