From 70348610334fd2e38abf95e7caf7ecaac4f79893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Fri, 5 Jan 2018 13:08:48 +0100 Subject: [PATCH 1/4] Add all for setImageAttachments --- README.md | 2 +- src/OneSignalMessage.php | 15 +++++++++++++++ tests/MessageTest.php | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f94b5fb..e6c1d1d 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ public function routeNotificationForOneSignal() - `button(OneSignalButton $button)`: Allows you to add buttons to the notification (Supported by iOS 8.0 and Android 4.1+ devices. Icon only works for Android). - `setData($key, $value)`: Allows you to set additional data for the message payload. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). - `setParameter($key, $value)`: Allows you to set additional parameters for the message payload that are available for the REST API. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). - +- `setImageAttachments($imageUrl)`: Allows you to set one Image to all possible Attachments [OneSignal Attachment documentation](https://documentation.onesignal.com/reference#section-attachments). ### Button usage ```php diff --git a/src/OneSignalMessage.php b/src/OneSignalMessage.php index c3569e7..2bd7d63 100644 --- a/src/OneSignalMessage.php +++ b/src/OneSignalMessage.php @@ -162,6 +162,21 @@ public function button(OneSignalButton $button) return $this; } + /** + * Set an image to all possible attachment variables. + * @param string $imageUrl + * + * @return $this + */ + public function setImageAttachments($imageUrl){ + $this->extraParameters['ios_attachments']['id1'] = $imageUrl; + $this->extraParameters['big_picture'] = $imageUrl; + $this->extraParameters['adm_big_picture'] = $imageUrl; + $this->extraParameters['chrome_big_picture'] = $imageUrl; + + return $this; + } + /** * @return array */ diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 7631f9f..730347f 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -108,4 +108,14 @@ public function it_can_set_a_button() $this->assertEquals('buttonText', Arr::get($this->message->toArray(), 'buttons.0.text')); $this->assertEquals('buttonIcon', Arr::get($this->message->toArray(), 'buttons.0.icon')); } + + /** @test */ + public function it_can_set_a_image(){ + $this->message->setImageAttachments('https://url.com/to/image.jpg'); + + $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'ios_attachments.id1')); + $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'big_picture')); + $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'adm_big_picture')); + $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'chrome_big_picture')); + } } From fd475d64ff35c8ae13b0651197772ddc03dcc447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Fri, 5 Jan 2018 13:09:37 +0100 Subject: [PATCH 2/4] A new line after the List is needed --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e6c1d1d..7db196b 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ public function routeNotificationForOneSignal() - `setData($key, $value)`: Allows you to set additional data for the message payload. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). - `setParameter($key, $value)`: Allows you to set additional parameters for the message payload that are available for the REST API. For more information check the [OneSignal documentation](https://documentation.onesignal.com/reference). - `setImageAttachments($imageUrl)`: Allows you to set one Image to all possible Attachments [OneSignal Attachment documentation](https://documentation.onesignal.com/reference#section-attachments). + ### Button usage ```php From 8c8b16150271c4452c96a317c050eb91d9bbeb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Fri, 5 Jan 2018 13:10:23 +0100 Subject: [PATCH 3/4] StyleCI issue --- src/OneSignalMessage.php | 3 ++- tests/MessageTest.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OneSignalMessage.php b/src/OneSignalMessage.php index 2bd7d63..3ba14de 100644 --- a/src/OneSignalMessage.php +++ b/src/OneSignalMessage.php @@ -168,7 +168,8 @@ public function button(OneSignalButton $button) * * @return $this */ - public function setImageAttachments($imageUrl){ + public function setImageAttachments($imageUrl) + { $this->extraParameters['ios_attachments']['id1'] = $imageUrl; $this->extraParameters['big_picture'] = $imageUrl; $this->extraParameters['adm_big_picture'] = $imageUrl; diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 730347f..d0a9fd7 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -110,7 +110,8 @@ public function it_can_set_a_button() } /** @test */ - public function it_can_set_a_image(){ + public function it_can_set_a_image() + { $this->message->setImageAttachments('https://url.com/to/image.jpg'); $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'ios_attachments.id1')); From d972fb262f7521b2a138b2cbed8e364b90717605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Fri, 5 Jan 2018 13:11:04 +0100 Subject: [PATCH 4/4] StyleCI issue --- tests/MessageTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/MessageTest.php b/tests/MessageTest.php index d0a9fd7..732fcd5 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -114,9 +114,9 @@ public function it_can_set_a_image() { $this->message->setImageAttachments('https://url.com/to/image.jpg'); - $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'ios_attachments.id1')); - $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'big_picture')); - $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'adm_big_picture')); - $this->assertEquals('https://url.com/to/image.jpg',Arr::get($this->message->toArray(), 'chrome_big_picture')); + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'ios_attachments.id1')); + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'big_picture')); + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'adm_big_picture')); + $this->assertEquals('https://url.com/to/image.jpg', Arr::get($this->message->toArray(), 'chrome_big_picture')); } }