From 50126828ffbc4c257a9e4823fd1af0eb73e5447f Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 11 Jul 2016 13:31:31 +0100 Subject: [PATCH 1/3] Updated composer.lock --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index c506a6aa..e0b2e2cc 100644 --- a/composer.lock +++ b/composer.lock @@ -2437,16 +2437,16 @@ }, { "name": "spatie/laravel-medialibrary", - "version": "4.4.0", + "version": "4.5.0", "source": { "type": "git", "url": "https://github.com/spatie/laravel-medialibrary.git", - "reference": "4b47aaebfa3ee52435a4832e1c551b424a51fdeb" + "reference": "8ba0ded185ee7c3c36d3ebb531a881f17950677d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/4b47aaebfa3ee52435a4832e1c551b424a51fdeb", - "reference": "4b47aaebfa3ee52435a4832e1c551b424a51fdeb", + "url": "https://api.github.com/repos/spatie/laravel-medialibrary/zipball/8ba0ded185ee7c3c36d3ebb531a881f17950677d", + "reference": "8ba0ded185ee7c3c36d3ebb531a881f17950677d", "shasum": "" }, "require": { @@ -2493,7 +2493,7 @@ "media", "spatie" ], - "time": "2016-07-06 12:49:31" + "time": "2016-07-09 13:49:32" }, { "name": "spatie/pdf-to-image", From 72e61032d8d1a349f020ab15de7247c287749041 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 11 Jul 2016 17:09:14 +0100 Subject: [PATCH 2/3] 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 From 7d381eaf812d8fc924fd489af7c1fe0833f5f216 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Mon, 11 Jul 2016 17:32:58 +0100 Subject: [PATCH 3/3] Add a test for JSON request to endpoint --- app/Services/NoteService.php | 2 +- tests/MicropubTest.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index 33c88fe9..38cbe531 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -25,7 +25,7 @@ class NoteService if ($request->header('Content-Type') == 'application/json') { $content = $request->input('properties.content')[0]; $inReplyTo = $request->input('properties.in-reply-to')[0]; - $placeSlug = $request->input('proprties.location'); + $placeSlug = $request->input('properties.location'); if (is_array($placeSlug)) { $placeSlug = $placeSlug[0]; } diff --git a/tests/MicropubTest.php b/tests/MicropubTest.php index 4da3853d..26addf48 100644 --- a/tests/MicropubTest.php +++ b/tests/MicropubTest.php @@ -100,6 +100,25 @@ class MicropubTest extends TestCase $this->seeInDatabase('places', ['slug' => 'the-barton-arms']); } + public function testMicropubJSONRequestCreateNewNote() + { + $faker = \Faker\Factory::create(); + $note = $faker->text; + $this->json( + 'POST', + $this->appurl . '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'content' => [$note], + ], + ], + ['HTTP_Authorization' => 'Bearer ' . $this->getToken()] + )->seeJson([ + 'response' => 'created' + ]); + } + private function getToken() { $signer = new Sha256();