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

Vimeo   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 3
1
<?php
2
/**
3
 * Class Vimeo
4
 *
5
 * @created      09.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\{ClientCredentials, CSRFToken, OAuth2Provider, ProviderException};
15
use Psr\Http\Message\ResponseInterface;
16
use function sprintf;
17
18
/**
19
 * @see https://developer.vimeo.com/
20
 * @see https://developer.vimeo.com/api/authentication
21
 */
22
class Vimeo extends OAuth2Provider implements ClientCredentials, CSRFToken{
23
24
	/**
25
	 * @see https://developer.vimeo.com/api/authentication#understanding-the-auth-process
26
	 */
27
	public const SCOPE_PUBLIC                    = 'public';
28
	public const SCOPE_PRIVATE                   = 'private';
29
	public const SCOPE_PURCHASED                 = 'purchased';
30
	public const SCOPE_CREATE                    = 'create';
31
	public const SCOPE_EDIT                      = 'edit';
32
	public const SCOPE_DELETE                    = 'delete';
33
	public const SCOPE_INTERACT                  = 'interact';
34
	public const SCOPE_UPLOAD                    = 'upload';
35
	public const SCOPE_PROMO_CODES               = 'promo_codes';
36
	public const SCOPE_VIDEO_FILES               = 'video_files';
37
38
	protected const API_VERSION                  = '3.4';
39
40
	protected string  $authURL                   = 'https://api.vimeo.com/oauth/authorize';
41
	protected string  $accessTokenURL            = 'https://api.vimeo.com/oauth/access_token';
42
	protected string  $apiURL                    = 'https://api.vimeo.com';
43
	protected ?string $userRevokeURL             = 'https://vimeo.com/settings/apps';
44
	protected ?string $clientCredentialsTokenURL = 'https://api.vimeo.com/oauth/authorize/client';
45
	protected ?string $apiDocs                   = 'https://developer.vimeo.com';
46
	protected ?string $applicationURL            = 'https://developer.vimeo.com/apps';
47
	protected array   $authHeaders               = ['Accept' => 'application/vnd.vimeo.*+json;version='.self::API_VERSION];
48
	protected array   $apiHeaders                = ['Accept' => 'application/vnd.vimeo.*+json;version='.self::API_VERSION];
49
50
	protected array $defaultScopes               =  [
51
		self::SCOPE_PUBLIC,
52
		self::SCOPE_PRIVATE,
53
		self::SCOPE_INTERACT,
54
	];
55
56
	/**
57
	 * @inheritDoc
58
	 */
59
	public function me():ResponseInterface{
60
		$response = $this->request('/me');
61
		$status   = $response->getStatusCode();
62
63
		if($status === 200){
64
			return $response;
65
		}
66
67
		$json = MessageUtil::decodeJSON($response);
68
69
		if(isset($json->error, $json->developer_message)){
70
			throw new ProviderException($json->developer_message);
71
		}
72
73
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
74
	}
75
76
}
77