Passed
Push — staging ( 488738...b212ab )
by Woeler
113:32 queued 100:41
created

CitrixAbstractIntegration::getRefreshTokenKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
/*
4
 * @copyright   2016 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace MauticPlugin\MauticCitrixBundle\Integration;
13
14
use Mautic\PluginBundle\Entity\Integration;
15
use Mautic\PluginBundle\Integration\AbstractIntegration;
16
17
/**
18
 * Class CitrixAbstractIntegration.
19
 */
20
abstract class CitrixAbstractIntegration extends AbstractIntegration
21
{
22
    protected $auth;
23
24
    /**
25
     * @return array
26
     */
27
    public function getSupportedFeatures()
28
    {
29
        return [];
30
    }
31
32
    /**
33
     * @param Integration $settings
34
     */
35
    public function setIntegrationSettings(Integration $settings)
36
    {
37
        //make sure URL does not have ending /
38
        $keys = $this->getDecryptedApiKeys($settings);
39
        if (array_key_exists('url', $keys) && '/' === substr($keys['url'], -1)) {
40
            $keys['url'] = substr($keys['url'], 0, -1);
41
            $this->encryptAndSetApiKeys($keys, $settings);
42
        }
43
44
        parent::setIntegrationSettings($settings);
45
    }
46
47
    /**
48
     * Refresh tokens.
49
     */
50
    public function getRefreshTokenKeys()
51
    {
52
        return [
53
            'refresh_token',
54
            'expires_in',
55
        ];
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     *
61
     * @return string
62
     */
63
    public function getAuthenticationType()
64
    {
65
        return 'oauth2';
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     *
71
     * @return array
72
     */
73
    public function getRequiredKeyFields()
74
    {
75
        return [
76
            'app_name'      => 'mautic.citrix.form.appname',
77
            'client_id'     => 'mautic.citrix.form.clientid',
78
            'client_secret' => 'mautic.citrix.form.clientsecret',
79
        ];
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function sortFieldsAlphabetically()
86
    {
87
        return false;
88
    }
89
90
    /**
91
     * Get the API helper.
92
     *
93
     * @return mixed
94
     */
95
    public function getApiHelper()
96
    {
97
        static $helper;
98
        if (null === $helper) {
99
            $class  = '\\MauticPlugin\\MauticCitrixBundle\\Api\\'.$this->getName().'Api';
100
            $helper = new $class($this);
101
        }
102
103
        return $helper;
104
    }
105
106
    /**
107
     * @return array
108
     */
109
    public function getFormSettings()
110
    {
111
        return [
112
            'requires_callback'      => true,
113
            'requires_authorization' => true,
114
        ];
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getApiUrl()
121
    {
122
        return 'https://api.getgo.com';
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     *
128
     * @return string
129
     */
130
    public function getAccessTokenUrl()
131
    {
132
        return $this->getApiUrl().'/oauth/v2/token';
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     *
138
     * @return string
139
     */
140
    public function getAuthenticationUrl()
141
    {
142
        return $this->getApiUrl().'/oauth/v2/authorize';
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     *
148
     * @return bool
149
     */
150
    public function isAuthorized()
151
    {
152
        $keys = $this->getKeys();
153
154
        return isset($keys[$this->getAuthTokenKey()]);
155
    }
156
157
    /**
158
     * @return string
159
     */
160
    public function getApiKey()
161
    {
162
        $keys = $this->getKeys();
163
164
        return $keys[$this->getAuthTokenKey()];
165
    }
166
167
    /**
168
     * @return string
169
     */
170
    public function getOrganizerKey()
171
    {
172
        $keys = $this->getKeys();
173
174
        return $keys['organizer_key'];
175
    }
176
}
177