Fix ownyourswarm checkins (closes issue #93)
Squashed commit of the following: commit b9716fc406664a58ce506aa419f978853d698eff Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Sat Jan 26 15:30:43 2019 +0000 Location and checkin aren’t part of the properties anymore
This commit is contained in:
parent
11a26e80e0
commit
acbb04f5a9
3 changed files with 130 additions and 80 deletions
|
@ -139,18 +139,7 @@ class NoteService
|
|||
*/
|
||||
private function getCheckin(array $request): ?Place
|
||||
{
|
||||
$location = array_get($request, 'properties.location.0');
|
||||
if (array_get($location, 'type.0') === 'h-card') {
|
||||
try {
|
||||
$place = resolve(PlaceService::class)->createPlaceFromCheckin(
|
||||
$location
|
||||
);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $place;
|
||||
}
|
||||
$location = array_get($request, 'location');
|
||||
if (is_string($location) && starts_with($location, config('app.url'))) {
|
||||
return Place::where(
|
||||
'slug',
|
||||
|
@ -162,10 +151,21 @@ class NoteService
|
|||
)
|
||||
)->first();
|
||||
}
|
||||
if (array_get($request, 'properties.checkin')) {
|
||||
if (array_get($request, 'checkin')) {
|
||||
try {
|
||||
$place = resolve(PlaceService::class)->createPlaceFromCheckin(
|
||||
array_get($request, 'properties.checkin.0')
|
||||
array_get($request, 'checkin')
|
||||
);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $place;
|
||||
}
|
||||
if (array_get($location, 'type.0') === 'h-card') {
|
||||
try {
|
||||
$place = resolve(PlaceService::class)->createPlaceFromCheckin(
|
||||
$location
|
||||
);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
|
|
|
@ -353,14 +353,14 @@ class MicropubControllerTest extends TestCase
|
|||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'content' => [$note],
|
||||
'location' => [[
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
'location' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
|
|
@ -26,15 +26,15 @@ class SwarmTest extends TestCase
|
|||
'value' => 'My first #checkin using Example Product',
|
||||
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
|
||||
]],
|
||||
'checkin' => [[
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://foursquare.com/v/123456'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
'checkin' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://foursquare.com/v/123456'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -64,15 +64,15 @@ class SwarmTest extends TestCase
|
|||
'value' => 'My first #checkin using Example Product',
|
||||
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
|
||||
]],
|
||||
'checkin' => [[
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://www.openstreetmap.org/way/123456'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
'checkin' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://www.openstreetmap.org/way/123456'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -99,15 +99,15 @@ class SwarmTest extends TestCase
|
|||
'value' => 'My first #checkin using Example Product',
|
||||
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
|
||||
]],
|
||||
'checkin' => [[
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://www.example.org/way/123456'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
'checkin' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://www.example.org/way/123456'],
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -130,15 +130,15 @@ class SwarmTest extends TestCase
|
|||
'properties' => [
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()],
|
||||
'syndication' => ['https://www.swarmapp.com/checkin/def'],
|
||||
'checkin' => [[
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesomer Venue'],
|
||||
'url' => ['https://foursquare.com/v/654321'],
|
||||
'latitude' => ['3.21'],
|
||||
'longitude' => ['6.54'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
'checkin' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesomer Venue'],
|
||||
'url' => ['https://foursquare.com/v/654321'],
|
||||
'latitude' => ['3.21'],
|
||||
'longitude' => ['6.54'],
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -169,13 +169,13 @@ class SwarmTest extends TestCase
|
|||
'value' => 'My first #checkin using Example Product',
|
||||
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
|
||||
]],
|
||||
'checkin' => [[
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://foursquare.com/v/123456'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
'checkin' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://foursquare.com/v/123456'],
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -202,21 +202,21 @@ class SwarmTest extends TestCase
|
|||
'value' => 'My first #checkin using Example Product',
|
||||
'html' => 'My first #checkin using <a href="http://example.org">Example Product</a>',
|
||||
]],
|
||||
'location' => [[
|
||||
'type' => ['h-adr'],
|
||||
'properties' => [
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
'street-address' => ['Awesome Street'],
|
||||
],
|
||||
]],
|
||||
'checkin' => [[
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://foursquare.com/v/123456'],
|
||||
],
|
||||
]],
|
||||
],
|
||||
'location' => [
|
||||
'type' => ['h-adr'],
|
||||
'properties' => [
|
||||
'latitude' => ['1.23'],
|
||||
'longitude' => ['4.56'],
|
||||
'street-address' => ['Awesome Street'],
|
||||
],
|
||||
],
|
||||
'checkin' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Awesome Venue'],
|
||||
'url' => ['https://foursquare.com/v/123456'],
|
||||
],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -228,4 +228,54 @@ class SwarmTest extends TestCase
|
|||
'name' => 'Awesome Venue',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function a_real_ownyourswarm_checkin()
|
||||
{
|
||||
$response = $this->json(
|
||||
'POST',
|
||||
'api/post',
|
||||
[
|
||||
'type' => ['h-entry'],
|
||||
'properties' =>[
|
||||
'published' => [\Carbon\Carbon::now()->toDateTimeString()]
|
||||
],
|
||||
'syndication' => [
|
||||
'https://www.swarmapp.com/user/199841/checkin/5c4b1ac56dcf04002c0a4f58'
|
||||
],
|
||||
'checkin' => [
|
||||
'type' => ['h-card'],
|
||||
'properties' => [
|
||||
'name' => ['Forbidden Planet'],
|
||||
'url' => ['https://foursquare.com/v/4ade0e46f964a520bf6f21e3'],
|
||||
'latitude' => [53.483153021713],
|
||||
'longitude' => [-2.2350297792539],
|
||||
'street-address' => ['65 Oldham St.'],
|
||||
'locality' => ['Manchester'],
|
||||
'country-name' => ['United Kingdom'],
|
||||
'postal-code' => ['M1 1JR']
|
||||
],
|
||||
'value' => 'https://foursquare.com/v/4ade0e46f964a520bf6f21e3'
|
||||
],
|
||||
'location' => [
|
||||
'type' => ['h-adr'],
|
||||
'properties' => [
|
||||
'latitude' => [53.483153021713],
|
||||
'longitude' => [-2.2350297792539],
|
||||
'street-address' => ['65 Oldham St.'],
|
||||
'locality' => ['Manchester'],
|
||||
'country-name' => ['United Kingdom'],
|
||||
'postal-code' => ['M1 1JR']
|
||||
]
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$this->assertDatabaseHas('places', [
|
||||
'name' => 'Forbidden Planet',
|
||||
]);
|
||||
$response
|
||||
->assertStatus(201)
|
||||
->assertJson(['response' => 'created']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue