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

OpenStreetmap   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 1
b 0
f 0
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 4
1
<?php
2
/**
3
 * Class OpenStreetmap
4
 *
5
 * @created      12.05.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
use function strip_tags;
19
20
/**
21
 * @see https://wiki.openstreetmap.org/wiki/API
22
 * @see https://wiki.openstreetmap.org/wiki/OAuth
23
 */
24
class OpenStreetmap extends OAuth1Provider{
25
26
	protected string  $requestTokenURL = 'https://www.openstreetmap.org/oauth/request_token';
27
	protected string  $authURL         = 'https://www.openstreetmap.org/oauth/authorize';
28
	protected string  $accessTokenURL  = 'https://www.openstreetmap.org/oauth/access_token';
29
	protected string  $apiURL          = 'https://api.openstreetmap.org';
30
	protected ?string $apiDocs         = 'https://wiki.openstreetmap.org/wiki/API';
31
	protected ?string $applicationURL  = 'https://www.openstreetmap.org/user/{USERNAME}/oauth_clients';
32
33
	/**
34
	 * @inheritDoc
35
	 */
36
	public function me(bool $json = true):ResponseInterface{
37
		$response = $this->request('/api/0.6/user/details'.($json ? '.json' : ''));
38
		$status   = $response->getStatusCode();
39
40
		if($status === 200){
41
			return $response;
42
		}
43
44
		$body = MessageUtil::getContents($response);
45
46
		if(!empty($body)){
47
			throw new ProviderException(strip_tags($body));
48
		}
49
50
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
51
	}
52
53
}
54