1 | <?php |
||
12 | class ExpoController extends Controller |
||
13 | { |
||
14 | /** |
||
15 | * @var ExpoChannel |
||
16 | */ |
||
17 | private $expoChannel; |
||
18 | |||
19 | /** |
||
20 | * ExpoController constructor. |
||
21 | * |
||
22 | * @param ExpoChannel $expoChannel |
||
23 | */ |
||
24 | 5 | public function __construct(ExpoChannel $expoChannel) |
|
28 | |||
29 | /** |
||
30 | * Handles subscription endpoint for an expo token. |
||
31 | * |
||
32 | * @param Request $request |
||
33 | * |
||
34 | * @return \Illuminate\Http\JsonResponse |
||
35 | */ |
||
36 | 3 | public function subscribe(Request $request) |
|
37 | { |
||
38 | 3 | $validator = Validator::make($request->all(), [ |
|
39 | 3 | 'expo_token' => 'required|string', |
|
40 | ]); |
||
41 | |||
42 | 3 | if ($validator->fails()) { |
|
43 | 1 | return JsonResponse::create([ |
|
44 | 1 | 'status' => 'failed', |
|
45 | 'error' => [ |
||
46 | 'message' => 'Expo Token is required', |
||
47 | ], |
||
48 | 1 | ], 422); |
|
49 | } |
||
50 | |||
51 | 2 | $token = $request->get('expo_token'); |
|
52 | |||
53 | 2 | $interest = $this->expoChannel->interestName(Auth::user()); |
|
54 | |||
55 | try { |
||
56 | 2 | $this->expoChannel->expo->subscribe($interest, $token); |
|
57 | 1 | } catch (\Exception $e) { |
|
58 | 1 | return JsonResponse::create([ |
|
59 | 1 | 'status' => 'failed', |
|
60 | 'error' => [ |
||
61 | 1 | 'message' => $e->getMessage(), |
|
62 | ], |
||
63 | 1 | ], 500); |
|
64 | } |
||
65 | |||
66 | 1 | return JsonResponse::create([ |
|
67 | 1 | 'status' => 'succeeded', |
|
68 | 1 | 'expo_token' => $token, |
|
69 | 1 | ], 200); |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Handles removing subscription endpoint for the authenticated interest. |
||
74 | * |
||
75 | * @return \Illuminate\Http\JsonResponse |
||
76 | */ |
||
77 | 2 | public function unsubscribe() |
|
94 | } |
||
95 |