generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#310 venue Implemented SendVenue Method and Venue DTO
- Loading branch information
Showing
12 changed files
with
216 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace DefStudio\Telegraph\DTO; | ||
|
||
use Illuminate\Contracts\Support\Arrayable; | ||
|
||
/** | ||
* @implements Arrayable<string, float> | ||
*/ | ||
class Venue implements Arrayable | ||
{ | ||
private Location $location; | ||
private string $title; | ||
private string $address; | ||
private ?string $foursquareId = null; | ||
private ?string $foursquareType = null; | ||
private ?string $googlePlaceId = null; | ||
private ?string $googlePlaceType = null; | ||
|
||
private function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @param array{ | ||
* location: array{longitude: float, latitude: float, horizontal_accuracy?: float}, | ||
* title: string, | ||
* address: string, | ||
* foursquare_id?: string, | ||
* foursquare_type?: string, | ||
* google_place_id?: string, | ||
* google_place_type?: string | ||
* } $data | ||
*/ | ||
public static function fromArray(array $data): Venue | ||
{ | ||
$venue = new self(); | ||
|
||
$venue->location = Location::fromArray($data['location']); | ||
$venue->title = $data['title']; | ||
$venue->address = $data['address']; | ||
$venue->foursquareId = $data['foursquare_id'] ?? null; | ||
$venue->foursquareType = $data['foursquare_type'] ?? null; | ||
$venue->googlePlaceId = $data['google_place_id'] ?? null; | ||
$venue->googlePlaceType = $data['google_place_type'] ?? null; | ||
|
||
return $venue; | ||
} | ||
|
||
public function location(): Location | ||
{ | ||
return $this->location; | ||
} | ||
|
||
public function title(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function address(): string | ||
{ | ||
return $this->address; | ||
} | ||
|
||
public function foursquareId(): ?string | ||
{ | ||
return $this->foursquareId; | ||
} | ||
|
||
public function foursquareType(): ?string | ||
{ | ||
return $this->foursquareType; | ||
} | ||
|
||
public function googlePlaceId(): ?string | ||
{ | ||
return $this->googlePlaceId; | ||
} | ||
|
||
public function googlePlaceType(): ?string | ||
{ | ||
return $this->googlePlaceType; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return array_filter([ | ||
'location' => $this->location, | ||
'title' => $this->title, | ||
'address' => $this->address, | ||
'foursquare_id' => $this->foursquareId, | ||
'foursquare_type' => $this->foursquareType, | ||
'google_place_id' => $this->googlePlaceId, | ||
'google_place_type' => $this->googlePlaceType, | ||
], fn ($value) => $value !== null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/.pest/snapshots/Unit/Concerns/SendsAttachmentsTest/it_can_send_a_venue_message.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"url": "https:\/\/api.telegram.org\/bot3f3814e1-5836-3d77-904e-60f64b15df36\/sendVenue", | ||
"payload": { | ||
"chat_id": "-123456789", | ||
"latitude": 12.345, | ||
"longitude": -54.321, | ||
"title": "title", | ||
"address": "address" | ||
}, | ||
"files": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** @noinspection PhpUnhandledExceptionInspection */ | ||
|
||
use DefStudio\Telegraph\DTO\Venue; | ||
use Illuminate\Support\Str; | ||
|
||
it('export all properties to array', function () { | ||
$dto = Venue::fromArray([ | ||
'location' => [ | ||
'latitude' => 10, | ||
'longitude' => 10, | ||
'horizontal_accuracy' => 10, | ||
], | ||
'title' => 'test title', | ||
'address' => 'test address', | ||
'foursquare_id' => 'test foursquare_id', | ||
'foursquare_type' => 'test foursquare_type', | ||
'google_place_id' => 'test google_place_id', | ||
'google_place_type' => 'test google_place_type', | ||
]); | ||
|
||
$array = $dto->toArray(); | ||
|
||
$reflection = new ReflectionClass($dto); | ||
foreach ($reflection->getProperties() as $property) { | ||
expect($array)->toHaveKey(Str::of($property->name)->snake()); | ||
} | ||
}); |