Conditions | 3 |
Paths | 1 |
Total Lines | 37 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | public static function build(): array |
||
15 | { |
||
16 | return [ |
||
17 | 'name' => 'addToMailingList', |
||
18 | 'type' => Type::nonNull(Type::boolean()), |
||
19 | 'description' => 'Subscribe e-mail to infomaniak mailing list', |
||
20 | 'args' => [ |
||
21 | 'destination' => Type::nonNull(_types()->get('string')), |
||
22 | 'email' => Type::nonNull(_types()->get('string')), |
||
23 | ], |
||
24 | '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(Client::MAILINGLIST, |
||
40 | [ |
||
41 | 'id' => $destination, |
||
42 | 'action' => Action::IMPORTCONTACT, |
||
43 | 'params' => [ |
||
44 | 'contacts' => [ |
||
45 | ['email' => $email], |
||
46 | ], |
||
47 | ], |
||
48 | ]); |
||
49 | |||
50 | return $response->success(); |
||
51 | }, |
||
55 |