Uploading inital module
This commit is contained in:
parent
f1dc2680a3
commit
0aed3e8196
51
FDShim_Controller.php
Normal file
51
FDShim_Controller.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\FreshdeskShim\Controller;
|
||||||
|
|
||||||
|
use Drupal\Core\Controller\ControllerBase;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class FDShim_Controller extends ControllerBase {
|
||||||
|
public function fd_route(Request $request) {
|
||||||
|
if ($request->isMethod('POST')) {
|
||||||
|
$postData = $request->request->all();
|
||||||
|
|
||||||
|
// Initial variables
|
||||||
|
$apiUrl = 'https://jvmanufacturing-help.freshdesk.com/api/v2/tickets';
|
||||||
|
$apiKey = 'OTBuVjM4cVA0dDdHaXVJeUhoWDpY';
|
||||||
|
$fd = curl_init($apiUrl);
|
||||||
|
$headers = [
|
||||||
|
'Content-Type: multipart/form-data',
|
||||||
|
'Authorization: ' . $apiKey
|
||||||
|
];
|
||||||
|
|
||||||
|
// cURL Options
|
||||||
|
curl_setopt($fd, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($fd, CURLOPT_POST, true);
|
||||||
|
curl_setopt($fd, CURLOPT_POSTFIELDS, http_build_query($postData));
|
||||||
|
curl_setopt($fd, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
|
||||||
|
$response = curl_exec($fd);
|
||||||
|
|
||||||
|
// HTTP Response Codes:
|
||||||
|
// 200 - Request OK
|
||||||
|
// 405 - Method Not Allowed
|
||||||
|
// 500 - Internal Error
|
||||||
|
|
||||||
|
if (curl_errno($fd)) {
|
||||||
|
// cURL error handling
|
||||||
|
$error = curl_error($fd);
|
||||||
|
curl_close($fd);
|
||||||
|
return new JsonResponse(['error' => $error], 500);
|
||||||
|
} else {
|
||||||
|
// return cURL response if successful
|
||||||
|
curl_close($fd);
|
||||||
|
return new JsonResponse(json_decode($response, true), 200);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// reject all methods that aren't POST requests
|
||||||
|
return new JsonResponse(['error'=> 'Method Not Allowed'], 405);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
FreshdeskShim.info.yml
Normal file
6
FreshdeskShim.info.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
name: Freshdesk Shim API
|
||||||
|
description: This module takes a POST request from a webform and passess the info back to the Freshdesk API to open a ticket.
|
||||||
|
package: Custom
|
||||||
|
type: module
|
||||||
|
version: 1.0
|
||||||
|
core_version_requirement: 10.*
|
||||||
7
FreshdeskShim.routing.yml
Normal file
7
FreshdeskShim.routing.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
FresdeskShim.content:
|
||||||
|
path: '/FreshdeskShim'
|
||||||
|
defaults:
|
||||||
|
_controller: '\Drupal\FreshdeskShim\Controller\FDShim_Controller::fd_route'
|
||||||
|
_title: 'Freshdesk Shim'
|
||||||
|
requirements:
|
||||||
|
_permission: 'access content'
|
||||||
Loading…
x
Reference in New Issue
Block a user