1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
3 | namespace BristolSU\Service\Typeform\Connectors; |
||
4 | |||
5 | use BristolSU\Support\Connection\Contracts\Connector; |
||
6 | use FormSchema\Generator\Field; |
||
7 | use FormSchema\Schema\Form; |
||
8 | use GuzzleHttp\Exception\GuzzleException; |
||
9 | |||
10 | class ApiKey extends Connector |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | |||
13 | /** |
||
0 ignored issues
–
show
|
|||
14 | * @inheritDoc |
||
15 | */ |
||
0 ignored issues
–
show
|
|||
16 | 4 | public function request($method, $uri, array $options = []) |
|
17 | { |
||
18 | 4 | $options['base_uri'] = config('typeform_service.base_uri'); |
|
19 | 4 | $headers = ((isset($options['headers']) && is_array($options['headers']))?$options['headers']:[]); |
|
20 | 4 | $headers['Authorization'] = 'Bearer ' . $this->getSetting('api_key'); |
|
21 | 4 | $options['headers'] = $headers; |
|
22 | 4 | return $this->client->request($method, $uri, $options); |
|
23 | } |
||
24 | |||
25 | /** |
||
0 ignored issues
–
show
|
|||
26 | * @inheritDoc |
||
27 | */ |
||
0 ignored issues
–
show
|
|||
28 | 2 | public function test(): bool |
|
29 | { |
||
30 | try { |
||
31 | 2 | $this->request('get', '/me'); |
|
32 | 1 | return true; |
|
33 | 1 | } catch (GuzzleException $e) { |
|
34 | 1 | return false; |
|
35 | } |
||
36 | } |
||
37 | |||
38 | /** |
||
0 ignored issues
–
show
|
|||
39 | * @inheritDoc |
||
40 | */ |
||
0 ignored issues
–
show
|
|||
41 | 1 | static public function settingsSchema(): Form |
|
42 | { |
||
43 | 1 | return \FormSchema\Generator\Form::make()->withField( |
|
44 | 1 | Field::input('api_key')->inputType('text')->label('API Key') |
|
45 | 1 | ->description('You should be able to find this on Typeform')->required(true) |
|
46 | 1 | )->getSchema(); |
|
47 | } |
||
48 | } |