-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP]Refactor to Traits and add some little more Parameters #58
Merged
Merged
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
715521e
Refactor to Traits and add some little more Parameters
LKaemmerling 3c7ae6a
Add Grouping Helpers
LKaemmerling 7d42ea1
Add Button Helpers
LKaemmerling e00b7cc
Removed all unused protected variables
LKaemmerling 95fe263
Make the setData Method call setParameter directly & allow the dot no…
LKaemmerling b926b13
Apply fixes from StyleCI (#59)
7101895
Working on Code with suggestions from timacdonald
LKaemmerling 5095faf
Working on Code with suggestions from timacdonald #2
LKaemmerling 3be802c
Add Deprecated DocTypes & remove Trait the contains only other Traits
LKaemmerling ad05ee0
Add Deprecated Trait that contains all deprecated methods
LKaemmerling d14ac9a
i really love travis :D
LKaemmerling 52bfc9e
Add support for silent messages (#67)
kjostling b1e9d1b
Add method to set the template_id of the message (#77)
dyegonery a14695b
Fix Style CI
LKaemmerling 860ce55
Fix Style CI Issues
LKaemmerling 64bb529
Fix Style CI Issues
LKaemmerling 32521dd
implemented sending of notifications based on segments (included/excl…
rylxes 83c1c00
ability of user to send notification , filtering for multiple tags (#73)
rylxes 7d7edcb
Pass Notification Object to Route
LKaemmerling 785705b
Merge remote-tracking branch 'origin/refactor-to-traits' into refacto…
LKaemmerling 5431c23
Fix Style CI Issue
LKaemmerling d5a94ab
Fix Style CI Issue
LKaemmerling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,32 +3,20 @@ | |
namespace NotificationChannels\OneSignal; | ||
|
||
use Illuminate\Support\Arr; | ||
use NotificationChannels\OneSignal\Traits\Categories\AppearanceHelpers; | ||
use NotificationChannels\OneSignal\Traits\Categories\AttachmentHelpers; | ||
use NotificationChannels\OneSignal\Traits\Categories\ButtonHelpers; | ||
use NotificationChannels\OneSignal\Traits\Categories\DeliveryHelpers; | ||
use NotificationChannels\OneSignal\Traits\Categories\GroupingHelpers; | ||
|
||
|
||
class OneSignalMessage | ||
{ | ||
/** @var string */ | ||
protected $body; | ||
|
||
/** @var string */ | ||
protected $subject; | ||
|
||
/** @var string */ | ||
protected $url; | ||
|
||
/** @var string */ | ||
protected $icon; | ||
|
||
/** @var array */ | ||
protected $data = []; | ||
|
||
/** @var array */ | ||
protected $buttons = []; | ||
use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers; | ||
|
||
/** @var array */ | ||
protected $webButtons = []; | ||
|
||
/** @var array */ | ||
protected $extraParameters = []; | ||
protected $payload = []; | ||
|
||
/** | ||
* @param string $body | ||
|
@@ -45,212 +33,131 @@ public static function create($body = '') | |
*/ | ||
public function __construct($body = '') | ||
{ | ||
$this->body = $body; | ||
$this->setBody($body); | ||
} | ||
|
||
/** | ||
* Set the message body. | ||
* | ||
* @param string $value | ||
* @param mixed $value | ||
* | ||
* @deprecated use setBody instead | ||
* | ||
* @return $this | ||
*/ | ||
public function body($value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it would be good to move these deprecated methods to |
||
{ | ||
$this->body = $value; | ||
|
||
return $this; | ||
return $this->setBody($value); | ||
} | ||
|
||
/** | ||
* Set the message icon. | ||
* Set the message body. | ||
* | ||
* @param string $value | ||
* @param mixed $value | ||
* | ||
* @return $this | ||
*/ | ||
public function icon($value) | ||
public function setBody($value) | ||
{ | ||
$this->icon = $value; | ||
|
||
return $this; | ||
return $this->setParameter('contents', $this->parseValueToArray($value)); | ||
} | ||
|
||
/** | ||
* Set the message subject. | ||
* | ||
* @param string $value | ||
* @param mixed $value | ||
* | ||
* @deprecated Use setSubject instead | ||
* | ||
* @return $this | ||
*/ | ||
public function subject($value) | ||
{ | ||
$this->subject = $value; | ||
|
||
return $this; | ||
return $this->setParameter('headings', $this->parseValueToArray($value)); | ||
} | ||
|
||
/** | ||
* Set the message url. | ||
* Set the message subject. | ||
* | ||
* @param string $value | ||
* @param mixed $value | ||
* | ||
* @return $this | ||
*/ | ||
public function url($value) | ||
public function setSubject($value) | ||
{ | ||
$this->url = $value; | ||
|
||
return $this; | ||
return $this->setSubject($value); | ||
} | ||
|
||
/** | ||
* Set the iOS badge increment count. | ||
* @param mixed $value | ||
* | ||
* @param int $count | ||
* | ||
* @return $this | ||
* @return array | ||
*/ | ||
public function incrementIosBadgeCount($count = 1) | ||
protected function parseValueToArray($value) | ||
{ | ||
return $this->setParameter('ios_badgeType', 'Increase') | ||
->setParameter('ios_badgeCount', $count); | ||
return (is_array($value)) ? $value : ['en' => $value]; | ||
} | ||
|
||
/** | ||
* Set the iOS badge decrement count. | ||
* | ||
* @param int $count | ||
* Set the message url. | ||
* | ||
* @return $this | ||
*/ | ||
public function decrementIosBadgeCount($count = 1) | ||
{ | ||
return $this->setParameter('ios_badgeType', 'Increase') | ||
->setParameter('ios_badgeCount', -1 * $count); | ||
} | ||
|
||
/** | ||
* Set the iOS badge count. | ||
* @param string $value | ||
* | ||
* @param int $count | ||
* @deprecated use setUrl Instead | ||
* | ||
* @return $this | ||
*/ | ||
public function setIosBadgeCount($count) | ||
public function url($value) | ||
{ | ||
return $this->setParameter('ios_badgeType', 'SetTo') | ||
->setParameter('ios_badgeCount', $count); | ||
return $this->setUrl($value); | ||
} | ||
|
||
/** | ||
* Set additional data. | ||
* | ||
* @param string $key | ||
* @param string $value | ||
* @param mixed $value | ||
* | ||
* @return $this | ||
*/ | ||
public function setData($key, $value) | ||
public function setData(string $key, $value) | ||
{ | ||
$this->data[$key] = $value; | ||
|
||
return $this; | ||
return $this->setParameter("data.{$key}", $value); | ||
} | ||
|
||
/** | ||
* Set additional parameters. | ||
* Set parameters. | ||
* | ||
* @param string $key | ||
* @param string $value | ||
* | ||
* @return $this | ||
*/ | ||
public function setParameter($key, $value) | ||
{ | ||
$this->extraParameters[$key] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add a web button to the message. | ||
* | ||
* @param OneSignalWebButton $button | ||
* @param mixed $value | ||
* | ||
* @return $this | ||
*/ | ||
public function webButton(OneSignalWebButton $button) | ||
public function setParameter(string $key, $value) | ||
{ | ||
$this->webButtons[] = $button->toArray(); | ||
Arr::set($this->payload, $key, $value); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add a native button to the message. | ||
* Get parameters. | ||
* | ||
* @param OneSignalButton $button | ||
* | ||
* @return $this | ||
*/ | ||
public function button(OneSignalButton $button) | ||
{ | ||
$this->buttons[] = $button->toArray(); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set an image to all possible attachment variables. | ||
* @param string $imageUrl | ||
* @param string $key | ||
* @param mixed $default | ||
* | ||
* @return $this | ||
* @return mixed | ||
*/ | ||
public function setImageAttachments($imageUrl) | ||
public function getParameter(string $key, $default = null) | ||
{ | ||
$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 Arr::get($this->payload, $key, $default); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$message = [ | ||
'contents' => ['en' => $this->body], | ||
'headings' => $this->subjectToArray(), | ||
'url' => $this->url, | ||
'buttons' => $this->buttons, | ||
'web_buttons' => $this->webButtons, | ||
'chrome_web_icon' => $this->icon, | ||
'chrome_icon' => $this->icon, | ||
'adm_small_icon' => $this->icon, | ||
'small_icon' => $this->icon, | ||
]; | ||
|
||
foreach ($this->extraParameters as $key => $value) { | ||
Arr::set($message, $key, $value); | ||
} | ||
|
||
foreach ($this->data as $data => $value) { | ||
Arr::set($message, 'data.'.$data, $value); | ||
} | ||
|
||
return $message; | ||
} | ||
|
||
protected function subjectToArray() | ||
{ | ||
if ($this->subject === null) { | ||
return []; | ||
} | ||
|
||
return ['en' => $this->subject]; | ||
return $this->payload; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use relative trait names here - then you could remove all of the top
use
imports.i.e.
But that is just a style thing - and not really needed