OpenCaching   A
last analyzed

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 OpenCaching
4
 *
5
 * @created      04.03.2019
6
 * @author       smiley <[email protected]>
7
 * @copyright    2019 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.opencaching.de/okapi/
21
 */
22
class OpenCaching extends OAuth1Provider{
23
24
	protected string  $requestTokenURL = 'https://www.opencaching.de/okapi/services/oauth/request_token';
25
	protected string  $authURL         = 'https://www.opencaching.de/okapi/services/oauth/authorize';
26
	protected string  $accessTokenURL  = 'https://www.opencaching.de/okapi/services/oauth/access_token';
27
	protected string  $apiURL          = 'https://www.opencaching.de/okapi/services';
28
	protected ?string $userRevokeURL   = 'https://www.opencaching.de/okapi/apps/';
29
	protected ?string $apiDocs         = 'https://www.opencaching.de/okapi/';
30
	protected ?string $applicationURL  = 'https://www.opencaching.de/okapi/signup.html';
31
32
	/**
33
	 * @inheritDoc
34
	 */
35
	public function me():ResponseInterface{
36
		$response = $this->request('/users/user', ['fields' => 'uuid|username|profile_url|internal_id|date_registered|caches_found|caches_notfound|caches_hidden|rcmds_given|rcmds_left|rcmd_founds_needed|home_location']);
37
		$status   = $response->getStatusCode();
38
39
		if($status === 200){
40
			return $response;
41
		}
42
43
		$json = MessageUtil::decodeJSON($response);
44
45
		if(isset($json->error, $json->error_description)){
46
			throw new ProviderException($json->error_description);
47
		}
48
49
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
50
	}
51
52
}
53