Completed
Pull Request — master (#467)
by
unknown
04:10
created

Todoist::getScopesDelimiter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of Boozt Platform
5
 * and belongs to Boozt Fashion AB.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
13
namespace OAuth\OAuth2\Service;
14
15
use OAuth\OAuth2\Token\StdOAuth2Token;
16
use OAuth\Common\Http\Exception\TokenResponseException;
17
use OAuth\Common\Http\Uri\Uri;
18
use OAuth\Common\Consumer\CredentialsInterface;
19
use OAuth\Common\Http\Client\ClientInterface;
20
use OAuth\Common\Storage\TokenStorageInterface;
21
use OAuth\Common\Http\Uri\UriInterface;
22
23
class Todoist extends AbstractService
24
{
25
    /**
26
     * Defined scopes, see https://developer.todoist.com/#oauth for definitions.
27
     */
28
29
    /**
30
     * Grants permission to add tasks to the Inbox project (The application cannot read tasks data).
31
     */
32
    const SCOPE_TASK_ADD = 'task:add';
33
34
    /**
35
     * Grants read-only access to application data, including tasks, projects, labels, and filters.
36
     */
37
    const SCOPE_DATA_READ = 'data:read';
38
39
    /**
40
     * Grants read and write access to application data, including tasks, projects, labels, and filters.
41
     *
42
     * This scope includes task:add and data:read scopes.
43
     */
44
    const SCOPE_DATA_READ_WRITE = 'data:read_write';
45
46
    /**
47
     * Grants permission to delete application data, including tasks, labels, and filters.
48
     */
49
    const SCOPE_DATA_DELETE = 'data:delete';
50
51
    /**
52
     * Grants permission to delete projects.
53
     */
54
    const SCOPE_PROJECT_DELETE = 'project:delete';
55
56
57
    public function __construct(
58
        CredentialsInterface $credentials,
59
        ClientInterface $httpClient,
60
        TokenStorageInterface $storage,
61
        $scopes = array(),
62
        UriInterface $baseApiUri = null
63
    )
64
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
65
        parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
66
67
        if (null === $baseApiUri) {
68
            $this->baseApiUri = new Uri('https://todoist.com/API/v6/');
69
        }
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getAuthorizationEndpoint()
76
    {
77
        return new Uri('https://todoist.com/oauth/authorize');
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function getAccessTokenEndpoint()
84
    {
85
        return new Uri('https://todoist.com/oauth/access_token');
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    protected function getAuthorizationMethod()
92
    {
93
        return static::AUTHORIZATION_METHOD_QUERY_STRING_V5;
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99
    protected function parseAccessTokenResponse($responseBody)
100
    {
101
        $data = json_decode($responseBody, true);
102
103
        if (null === $data || !is_array($data)) {
104
            throw new TokenResponseException('Unable to parse response.');
105
        } elseif (isset($data['error'])) {
106
            throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
107
        }
108
109
        $token = new StdOAuth2Token();
110
        $token->setAccessToken($data['access_token']);
111
        // Github tokens evidently never expire...
112
        $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
113
        unset($data['access_token']);
114
115
        $token->setExtraParams($data);
116
117
        return $token;
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123
    protected function getScopesDelimiter()
124
    {
125
        return ',';
126
    }
127
}
128