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.
Merge pull request #678 from defstudio/implement-InlineQueryResultVenue
Implement InlineQueryResultVenue
- Loading branch information
Showing
10 changed files
with
201 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
/** @noinspection PhpUnused */ | ||
|
||
namespace DefStudio\Telegraph\DTO; | ||
|
||
use DefStudio\Telegraph\Telegraph; | ||
|
||
class InlineQueryResultVenue extends InlineQueryResult | ||
{ | ||
protected string $type = 'venue'; | ||
protected string $id; | ||
protected string $title; | ||
protected float $latitude; | ||
protected float $longitude; | ||
protected string $address; | ||
protected string|null $foursquareId = null; | ||
protected string|null $foursquareType = null; | ||
protected string|null $googlePlaceId = null; | ||
protected string|null $googlePlaceType = null; | ||
protected string|null $message = null; | ||
protected string|null $thumbUrl = null; | ||
protected int|null $thumbWidth = null; | ||
protected int|null $thumbHeight = null; | ||
|
||
public static function make(string $id, string $title, float $latitude, float $longitude, string $address, string $message = null): InlineQueryResultVenue | ||
{ | ||
$result = new InlineQueryResultVenue(); | ||
$result->id = $id; | ||
$result->title = $title; | ||
$result->latitude = $latitude; | ||
$result->longitude = $longitude; | ||
$result->address = $address; | ||
$result->message = $message; | ||
|
||
return $result; | ||
} | ||
|
||
public function thumbUrl(string|null $thumbUrl): static | ||
{ | ||
$this->thumbUrl = $thumbUrl; | ||
|
||
return $this; | ||
} | ||
|
||
public function thumbWidth(int|null $thumbWidth): static | ||
{ | ||
$this->thumbWidth = $thumbWidth; | ||
|
||
return $this; | ||
} | ||
|
||
public function thumbHeight(int|null $thumbHeight): static | ||
{ | ||
$this->thumbHeight = $thumbHeight; | ||
|
||
return $this; | ||
} | ||
|
||
public function foursquareId(string|null $foursquareId): static | ||
{ | ||
$this->foursquareId = $foursquareId; | ||
|
||
return $this; | ||
} | ||
|
||
public function foursquareType(string|null $foursquareType): static | ||
{ | ||
$this->foursquareType = $foursquareType; | ||
|
||
return $this; | ||
} | ||
|
||
public function googlePlaceId(string|null $googlePlaceId): static | ||
{ | ||
$this->googlePlaceId = $googlePlaceId; | ||
|
||
return $this; | ||
} | ||
|
||
public function googlePlaceType(string|null $googlePlaceType): static | ||
{ | ||
$this->googlePlaceType = $googlePlaceType; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function data(): array | ||
{ | ||
$data = [ | ||
'title' => $this->title, | ||
'latitude' => $this->latitude, | ||
'longitude' => $this->longitude, | ||
'address' => $this->address, | ||
'foursquare_id' => $this->foursquareId, | ||
'foursquare_type' => $this->foursquareType, | ||
'google_place_id' => $this->googlePlaceId, | ||
'google_place_type' => $this->googlePlaceType, | ||
'thumb_url' => $this->thumbUrl, | ||
'thumb_width' => $this->thumbWidth, | ||
'thumb_height' => $this->thumbHeight, | ||
]; | ||
|
||
if ($this->message !== null) { | ||
$data['input_message_content'] = [ | ||
'message_text' => $this->message, | ||
'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML), | ||
]; | ||
} | ||
|
||
return array_filter($data, 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
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,32 @@ | ||
<?php | ||
|
||
use DefStudio\Telegraph\DTO\InlineQueryResultVenue; | ||
|
||
it('can export to array', function () { | ||
expect( | ||
InlineQueryResultVenue::make('a45', 'testTitle', 10.5, 10.5, 'testAddress') | ||
->thumbUrl('testThumbUrl') | ||
->thumbWidth(200) | ||
->thumbHeight(100) | ||
->foursquareId('testId') | ||
->foursquareType('testType') | ||
->googlePlaceId('testPlaceId') | ||
->googlePlaceType('testPlaceType') | ||
->toArray() | ||
)-> | ||
toBe([ | ||
'title' => 'testTitle', | ||
'latitude' => 10.5, | ||
'longitude' => 10.5, | ||
'address' => 'testAddress', | ||
'foursquare_id' => 'testId', | ||
'foursquare_type' => 'testType', | ||
'google_place_id' => 'testPlaceId', | ||
'google_place_type' => 'testPlaceType', | ||
'thumb_url' => 'testThumbUrl', | ||
'thumb_width' => 200, | ||
'thumb_height' => 100, | ||
'id' => "a45", | ||
'type' => "venue", | ||
]); | ||
}); |