From 72e61032d8d1a349f020ab15de7247c287749041 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 11 Jul 2016 17:09:14 +0100 Subject: [PATCH] Allow JSON requests to the micropub endpoint --- app/Http/Controllers/MicropubController.php | 5 ++--- app/Services/NoteService.php | 18 +++++++++++++++--- app/Services/PlaceService.php | 2 +- changelog.md | 3 +++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/MicropubController.php b/app/Http/Controllers/MicropubController.php index ad1b3314..0ff28497 100644 --- a/app/Http/Controllers/MicropubController.php +++ b/app/Http/Controllers/MicropubController.php @@ -56,8 +56,7 @@ class MicropubController extends Controller $scopes = explode(' ', $tokenData->getClaim('scope')); if (array_search('post', $scopes) !== false) { $clientId = $tokenData->getClaim('client_id'); - $type = $request->input('h'); - if ($type == 'entry') { + if (($request->input('h') == 'entry') || ($request->input('type')[0] == 'h-entry')) { $note = $this->noteService->createNote($request, $clientId); $content = <<header('Location', $note->longurl) ->header('Content-Type', 'application/json'); } - if ($type == 'card') { + if ($request->input('h') == 'card' || $request->input('type')[0] == 'h-card') { $place = $this->placeService->createPlace($request); $content = <<header('Content-Type') == 'application/json') { + $content = $request->input('properties.content')[0]; + $inReplyTo = $request->input('properties.in-reply-to')[0]; + $placeSlug = $request->input('proprties.location'); + if (is_array($placeSlug)) { + $placeSlug = $placeSlug[0]; + } + } else { + $content = $request->input('content'); + $inReplyTo = $request->input('in-reply-to'); + $placeSlug = $request->input('location'); + } + $note = Note::create( [ - 'note' => $request->input('content'), - 'in_reply_to' => $request->input('in-reply-to'), + 'note' => $content, + 'in_reply_to' => $inReplyTo, 'client_id' => $clientId, ] ); - $placeSlug = $request->input('location'); if ($placeSlug !== null && $placeSlug !== 'no-location') { $place = Place::where('slug', '=', $placeSlug)->first(); $note->place()->associate($place); diff --git a/app/Services/PlaceService.php b/app/Services/PlaceService.php index b4f737af..c5e49b18 100644 --- a/app/Services/PlaceService.php +++ b/app/Services/PlaceService.php @@ -14,7 +14,7 @@ class PlaceService * @param \Illuminate\Http\Request $request * @return \App\Place */ - public function createplace(Request $request) + public function createPlace(Request $request) { //we’ll either have latitude and longitude sent together in a //geo-url (micropub), or seperatley (/admin) diff --git a/changelog.md b/changelog.md index a7b4d042..9b1baa14 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version {next} + - Allow new notes to be made by a JSON request from a micropub client + ## Version 0.0.7.1 (2016-07-04) - Minor style fixes