Completed
Pull Request — master (#472)
by
unknown
02:39
created

Xing::validateTokenResponse()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.2
cc 4
eloc 8
nc 3
nop 1
1
<?php
2
3
namespace OAuth\OAuth1\Service;
4
5
use OAuth\OAuth1\Signature\SignatureInterface;
6
use OAuth\Common\Http\Exception\TokenResponseException;
7
use OAuth\Common\Http\Uri\Uri;
8
use OAuth\Common\Consumer\CredentialsInterface;
9
use OAuth\Common\Http\Uri\UriInterface;
10
use OAuth\Common\Storage\TokenStorageInterface;
11
use OAuth\Common\Http\Client\ClientInterface;
12
13
class Xing extends AbstractService
14
{
15
    public function __construct(
16
        CredentialsInterface $credentials,
17
        ClientInterface $httpClient,
18
        TokenStorageInterface $storage,
19
        SignatureInterface $signature,
20
        UriInterface $baseApiUri = null
21
    ) {
22
        parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
23
24
        if (null === $baseApiUri) {
25
            $this->baseApiUri = new Uri('https://api.xing.com/v1/');
26
        }
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getAuthorizationEndpoint()
33
    {
34
        return new Uri('https://api.xing.com/v1/authorize');
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getAccessTokenEndpoint()
41
    {
42
        return new Uri('https://api.xing.com/v1/access_token');
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getRequestTokenEndpoint()
49
    {
50
        return new Uri('https://api.xing.com/v1/request_token');
51
    }
52
    
53
    /**
54
     * {@inheritdoc}
55
     */
56
    protected function validateTokenResponse($responseBody)
57
    {
58
        parse_str($responseBody, $data);
59
        $errors = json_decode($responseBody);
60
        
61
        if (null === $data || !is_array($data)) {
62
            throw new TokenResponseException('Unable to parse response.');
63
        } elseif ($errors) {
64
            throw new TokenResponseException('Error in retrieving token: "' . $errors->error_name . '"');
65
        }
66
        
67
        return $data;
68
    }
69
    
70
}
71