diff --git a/src/Component.php b/src/Component.php index 716e0c8..4d36ca5 100644 --- a/src/Component.php +++ b/src/Component.php @@ -51,4 +51,9 @@ public static function flowButton(string $token, array $data): Component\FlowBut { return new Component\FlowButton($token, $data); } + + public static function location(string $name, string $address, float $latitude, float $longitude): Component\Location + { + return new Component\Location($name, $address, $latitude, $longitude); + } } diff --git a/src/Component/Location.php b/src/Component/Location.php new file mode 100644 index 0000000..08fb493 --- /dev/null +++ b/src/Component/Location.php @@ -0,0 +1,32 @@ +name = $name; + $this->address = $address; + $this->latitude = $latitude; + $this->longitude = $longitude; + } + + public function toArray(): array + { + return [ + 'type' => 'location', + 'location' => [ + 'latitude' => (string) $this->latitude, + 'longitude' => (string) $this->longitude, + 'name' => $this->name, + 'address' => $this->address, + ], + ]; + } +} diff --git a/tests/Component/LocationTest.php b/tests/Component/LocationTest.php new file mode 100644 index 0000000..846f647 --- /dev/null +++ b/tests/Component/LocationTest.php @@ -0,0 +1,30 @@ + 'location', + 'location' => [ + 'latitude' => (string) $latitude, + 'longitude' => (string) $longitude, + 'name' => $name, + 'address' => $address, + ], + ]; + $this->assertEquals($expectedValue, $currency->toArray()); + } +} diff --git a/tests/ComponentTest.php b/tests/ComponentTest.php index 383f8fc..1f57501 100644 --- a/tests/ComponentTest.php +++ b/tests/ComponentTest.php @@ -55,6 +55,14 @@ public function it_can_return_a_video_component() $this->assertInstanceOf(Component\Video::class, $component); } + /** @test */ + public function it_can_return_a_location_component() + { + $component = Component::location('My Place', 'Liepaja, Latvia', 56.51078, 21.00212); + + $this->assertInstanceOf(Component\Location::class, $component); + } + /** @test */ public function it_can_return_a_url_button_component() {