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