| Conditions | 4 |
| Paths | 7 |
| Total Lines | 36 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 43 | protected function handleWebhookPayload($json) { |
||
| 44 | /** @var \helper_plugin_struct $struct */ |
||
| 45 | $struct = plugin_load('helper', 'struct'); |
||
|
1 ignored issue
–
show
|
|||
| 46 | if (!$struct) { |
||
| 47 | http_status(422, 'struct plugin not active at this server'); |
||
|
1 ignored issue
–
show
|
|||
| 48 | exit(); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** @var \helper_plugin_swarmzapierstructwebhook $helper */ |
||
| 52 | $helper = plugin_load('helper', 'swarmzapierstructwebhook'); |
||
| 53 | |||
| 54 | $data = json_decode($json, true); |
||
| 55 | $timestamp = $data['createdAt']; |
||
| 56 | $checkinID = $data['id']; |
||
| 57 | $date = date('Y-m-d', $timestamp); // FIXME: use timezone offset? |
||
| 58 | $locationName = $data['venue']['name']; |
||
| 59 | |||
| 60 | $lookupData = [ |
||
| 61 | 'date' => $date, |
||
| 62 | 'time' => date_iso8601($timestamp), |
||
|
1 ignored issue
–
show
|
|||
| 63 | 'checkinid' => $checkinID, |
||
| 64 | 'locname' => $locationName, |
||
| 65 | 'json' => $json, |
||
| 66 | ]; |
||
| 67 | if (!empty($data['shout'])) { |
||
| 68 | $lookupData['shout'] = $data['shout']; |
||
| 69 | } |
||
| 70 | |||
| 71 | try { |
||
| 72 | $helper->deleteCheckinFromLookup($checkinID); |
||
| 73 | $helper->saveDataToLookup($lookupData); |
||
| 74 | } catch (\Exception $e) { |
||
| 75 | $errorMessage = $e->getMessage(); |
||
| 76 | dbglog($errorMessage); |
||
|
1 ignored issue
–
show
|
|||
| 77 | http_status(500, $errorMessage); |
||
| 78 | exit(); |
||
| 79 | } |
||
| 82 |