2017-01-30 21:40:43 +02:00
|
|
|
<?php
|
2015-03-17 11:30:56 +10:00
|
|
|
|
2017-01-30 21:40:43 +02:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Subscription;
|
2015-04-28 23:13:52 +03:00
|
|
|
use Auth;
|
2017-01-30 21:40:43 +02:00
|
|
|
use Response;
|
|
|
|
|
use Utils;
|
2015-03-17 07:45:25 +10:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 21:40:43 +02:00
|
|
|
* Class IntegrationController.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2018-05-06 22:45:47 +03:00
|
|
|
class IntegrationController extends BaseAPIController
|
2015-03-17 07:45:25 +10:00
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
|
*/
|
2015-03-17 07:45:25 +10:00
|
|
|
public function subscribe()
|
|
|
|
|
{
|
2021-09-25 20:13:01 -04:00
|
|
|
$eventId = Utils::lookupEventId(trim(\Request::input('event')));
|
2015-03-17 07:45:25 +10:00
|
|
|
|
2017-01-30 21:40:43 +02:00
|
|
|
if (! $eventId) {
|
2015-10-02 11:32:13 +03:00
|
|
|
return Response::json('Event is invalid', 500);
|
2015-03-17 07:45:25 +10:00
|
|
|
}
|
|
|
|
|
|
2017-11-29 13:12:20 +02:00
|
|
|
$subscription = Subscription::createNew();
|
|
|
|
|
$subscription->event_id = $eventId;
|
2021-09-25 20:13:01 -04:00
|
|
|
$subscription->target_url = trim(\Request::input('target_url'));
|
2015-03-17 07:45:25 +10:00
|
|
|
$subscription->save();
|
|
|
|
|
|
2017-01-30 21:40:43 +02:00
|
|
|
if (! $subscription->id) {
|
2015-10-02 11:32:13 +03:00
|
|
|
return Response::json('Failed to create subscription', 500);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-06 22:45:47 +03:00
|
|
|
return Response::json(['id' => $subscription->public_id], 201);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function unsubscribe($publicId)
|
|
|
|
|
{
|
|
|
|
|
$subscription = Subscription::scope($publicId)->firstOrFail();
|
|
|
|
|
$subscription->delete();
|
|
|
|
|
|
|
|
|
|
return $this->response(RESULT_SUCCESS);
|
2015-03-17 07:45:25 +10:00
|
|
|
}
|
|
|
|
|
}
|