Merge branch 'feature/micropub-json' into develop
This commit is contained in:
commit
0c781987a1
6 changed files with 45 additions and 12 deletions
|
@ -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 = <<<EOD
|
||||
{
|
||||
|
@ -70,7 +69,7 @@ EOD;
|
|||
->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 = <<<EOD
|
||||
{
|
||||
|
|
|
@ -22,15 +22,27 @@ class NoteService
|
|||
*/
|
||||
public function createNote(Request $request, $clientId = null)
|
||||
{
|
||||
if ($request->header('Content-Type') == 'application/json') {
|
||||
$content = $request->input('properties.content')[0];
|
||||
$inReplyTo = $request->input('properties.in-reply-to')[0];
|
||||
$placeSlug = $request->input('properties.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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
10
composer.lock
generated
10
composer.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue