Completed
Pull Request — master (#498)
by Dragonqos
02:30
created

Yammer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A Yammer::getAuthorizationEndpoint() 0 4 1
1
<?php
2
3
namespace OAuth\OAuth2\Service;
4
5
use OAuth\OAuth2\Token\StdOAuth2Token;
6
use OAuth\Common\Http\Exception\TokenResponseException;
7
use OAuth\Common\Http\Uri\Uri;
8
9
class Yammer extends AbstractService
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    protected function init()
15
    {
16
        if( $this->baseApiUri === null ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
17
            $this->baseApiUri = new Uri('https://www.yammer.com/api/v1/');
18
        }
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function getAuthorizationEndpoint()
25
    {
26
        return new Uri('https://www.yammer.com/dialog/oauth');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getAccessTokenEndpoint()
33
    {
34
        return new Uri('https://www.yammer.com/oauth2/access_token.json');
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getAuthorizationMethod()
41
    {
42
        return static::AUTHORIZATION_METHOD_HEADER_BEARER;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function parseAccessTokenResponse($responseBody)
49
    {
50
        $data = json_decode($responseBody, true);
51
52
        if (null === $data || !is_array($data)) {
53
            throw new TokenResponseException('Unable to parse response.');
54
        } elseif (isset($data['error'])) {
55
            throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
56
        }
57
58
        $token = new StdOAuth2Token();
59
        $token->setAccessToken($data['access_token']['token']);
60
        $token->setLifetime($data['access_token']['expires_at']);
61
62
        if (isset($data['refresh_token'])) {
63
            $token->setRefreshToken($data['refresh_token']);
64
            unset($data['refresh_token']);
65
        }
66
67
        unset($data['access_token']);
68
        unset($data['expires_in']);
69
70
        $token->setExtraParams($data);
71
72
        return $token;
73
    }
74
}
75