diff --git a/app/Services/NoteService.php b/app/Services/NoteService.php index b29f5d3c..eb3e25a0 100644 --- a/app/Services/NoteService.php +++ b/app/Services/NoteService.php @@ -142,10 +142,11 @@ class NoteService */ private function getCheckin(array $request): ?Place { - if (array_get($request, 'properties.location.0.type.0') === 'h-card') { + $location = array_get($request, 'properties.location.0'); + if (array_get($location, 'type.0') === 'h-card') { try { $place = resolve(PlaceService::class)->createPlaceFromCheckin( - array_get($request, 'properties.location.0') + $location ); } catch (\InvalidArgumentException $e) { return null; @@ -153,12 +154,12 @@ class NoteService return $place; } - if (starts_with(array_get($request, 'properties.location.0'), config('app.url'))) { + if (is_string($location) && starts_with($location, config('app.url'))) { return Place::where( 'slug', basename( parse_url( - array_get($request, 'properties.location.0'), + $location, PHP_URL_PATH ) ) diff --git a/changelog.md b/changelog.md index 6acc263c..a5d9f48d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Version 0.16.1 (2018-02-17) + - Fix issue where OwnYourSwarm requests inlude h-adr block for location + ## Version 0.16 (2018-02-16) - Update Laravel to 5.6 - Fix issue with creating alternative Facebook content when no contacts diff --git a/tests/Feature/SwarmTest.php b/tests/Feature/SwarmTest.php index 7e8f133b..8f92c4f3 100644 --- a/tests/Feature/SwarmTest.php +++ b/tests/Feature/SwarmTest.php @@ -187,4 +187,45 @@ class SwarmTest extends TestCase 'name' => 'Awesome Venue', ]); } + + public function test_ownyourswarm_request_with_hadr_location() + { + $response = $this->json( + 'POST', + 'api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'published' => [\Carbon\Carbon::now()->toDateTimeString()], + 'syndication' => ['https://www.swarmapp.com/checkin/abc'], + 'content' => [[ + 'value' => 'My first #checkin using Example Product', + 'html' => 'My first #checkin using Example Product', + ]], + '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()] + ); + $response + ->assertStatus(201) + ->assertJson(['response' => 'created']); + $this->assertDatabaseMissing('places', [ + 'name' => 'Awesome Venue', + ]); + } }