2015-03-17 02:30:56 +01:00
|
|
|
<?php namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Utils;
|
2015-04-28 22:13:52 +02:00
|
|
|
use Response;
|
|
|
|
use Auth;
|
|
|
|
use Input;
|
|
|
|
use App\Models\Subscription;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
class IntegrationController extends Controller
|
|
|
|
{
|
|
|
|
public function subscribe()
|
|
|
|
{
|
|
|
|
$eventId = Utils::lookupEventId(trim(Input::get('event')));
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-10-02 10:32:13 +02:00
|
|
|
$subscription = Subscription::where('account_id', '=', Auth::user()->account_id)
|
|
|
|
->where('event_id', '=', $eventId)->first();
|
2015-03-16 22:45:25 +01:00
|
|
|
|
|
|
|
if (!$subscription) {
|
|
|
|
$subscription = new Subscription();
|
|
|
|
$subscription->account_id = Auth::user()->account_id;
|
|
|
|
$subscription->event_id = $eventId;
|
|
|
|
}
|
|
|
|
|
|
|
|
$subscription->target_url = trim(Input::get('target_url'));
|
|
|
|
$subscription->save();
|
|
|
|
|
2015-10-02 10:32:13 +02:00
|
|
|
if (!$subscription->id) {
|
|
|
|
return Response::json('Failed to create subscription', 500);
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
return Response::json('{"id":'.$subscription->id.'}', 201);
|
|
|
|
}
|
|
|
|
}
|