Conditions | 3 |
Paths | 1 |
Total Lines | 39 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 5.667 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | 1 | public static function build(): array |
|
15 | { |
||
16 | return [ |
||
17 | 1 | 'name' => 'addToMailingList', |
|
18 | 1 | 'type' => Type::nonNull(Type::boolean()), |
|
19 | 'description' => 'Subscribe e-mail to infomaniak mailing list', |
||
20 | 'args' => [ |
||
21 | 1 | 'destination' => Type::nonNull(_types()->get('string')), |
|
22 | 1 | 'email' => Type::nonNull(_types()->get('string')), |
|
23 | ], |
||
24 | 1 | 'resolve' => function ($root, array $args): bool { |
|
25 | global $container; |
||
26 | $config = $container->get('config'); |
||
27 | $key = $config['infomaniak-api'] ?? null; |
||
28 | $secret = $config['infomaniak-secret'] ?? null; |
||
29 | |||
30 | if (!$key || !$secret) { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | $destination = $args['destination']; |
||
35 | $email = $args['email']; |
||
36 | |||
37 | $client = new Client($key, $secret); |
||
38 | |||
39 | $response = $client->post( |
||
40 | Client::MAILINGLIST, |
||
41 | [ |
||
42 | 'id' => $destination, |
||
43 | 'action' => Action::IMPORTCONTACT, |
||
44 | 'params' => [ |
||
45 | 'contacts' => [ |
||
46 | ['email' => $email], |
||
47 | ], |
||
48 | ], |
||
49 | ] |
||
50 | ); |
||
51 | |||
52 | return $response->success(); |
||
53 | }, |
||
57 |