Skip to content

Commit

Permalink
Merge pull request #1 from tobiasehlert/master
Browse files Browse the repository at this point in the history
enable html formatting in Pushover message
  • Loading branch information
Leonardo Cesar Teixeira committed Jan 4, 2016
2 parents 0a453b0 + 94e0d99 commit 74b88f8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ use LeonardoTeixeira\Pushover\Exceptions\PushoverException;
$client = new Client('YOUR_USER_CODE_HERE', 'YOUR_TOKEN_HERE');

$message = new Message();
$message->setMessage('Your messsage here.');
$message->setMessage('Your messsage <b>here</b>.');
$message->setTitle('Title here');
$message->setUrl('http://www.example.com/');
$message->setUrlTitle('Click me!');
$message->setPriority(Priority::HIGH);
$message->setSound(Sound::SIREN);
$message->setHtml(true);
$message->setDate(new \DateTime());

try {
Expand Down
3 changes: 2 additions & 1 deletion examples/complete-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
$client = new Client('YOUR_USER_CODE_HERE', 'YOUR_TOKEN_HERE');

$message = new Message();
$message->setMessage('Your messsage here.');
$message->setMessage('Your messsage <b>here</b>.');
$message->setTitle('Title here');
$message->setUrl('http://www.example.com/');
$message->setUrlTitle('Click me!');
$message->setPriority(Priority::HIGH);
$message->setSound(Sound::SIREN);
$message->setHtml(true);
$message->setDate(new \DateTime());

try {
Expand Down
4 changes: 4 additions & 0 deletions src/LeonardoTeixeira/Pushover/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public function push(Message $message, $device = null)
$postData['sound'] = $message->getSound();
}

if ($message->hasHtml()) {
$postData['html'] = $message->getHtml();
}

if ($message->hasDate()) {
$postData['timestamp'] = $message->getDate()->getTimestamp();
}
Expand Down
19 changes: 19 additions & 0 deletions src/LeonardoTeixeira/Pushover/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Message
private $urlTitle;
private $priority;
private $sound;
private $html;
private $date;

public function __construct($message = null, $title = null, $priority = Priority::NORMAL)
Expand Down Expand Up @@ -51,6 +52,11 @@ public function getSound()
return $this->sound;
}

public function getHtml()
{
return $this->html;
}

public function getDate()
{
return $this->date;
Expand Down Expand Up @@ -92,6 +98,14 @@ public function setSound($sound)
$this->sound = $sound;
}

public function setHtml($html)
{
if ($html)
$this->html = 1;
else
$this->html = 0;
}

public function setDate(\DateTime $date)
{
$this->date = $date;
Expand All @@ -117,6 +131,11 @@ public function hasSound()
return !is_null($this->sound);
}

public function hasHtml()
{
return !is_null($this->html);
}

public function hasDate()
{
return ($this->date instanceof \DateTime);
Expand Down
11 changes: 9 additions & 2 deletions tests/LeonardoTeixeira/Pushover/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ public function setUp()
$this->messages = [
[
'title' => 'Example Message 1',
'message' => 'Example content message 1.',
'message' => 'Example content message <b>1</b>.',
'url' => 'http://www.google.com/',
'url_title' => 'Google',
'priority' => - 2,
'sound' => 'classical',
'html' => 1,
'date' => '2014-08-14'
],
[
'title' => 'Example Message 2',
'message' => 'Example content message 2.',
'message' => 'Example content message <b>2</b>.',
'url' => 'https://github.com/',
'url_title' => 'Github',
'priority' => 1,
'sound' => 'spacealarm',
'html' => 0,
'date' => '2014-08-10'
]
];
Expand All @@ -51,6 +53,7 @@ public function testGettersAndSetters()
$m->setUrlTitle($message['url_title']);
$m->setPriority($message['priority']);
$m->setSound($message['sound']);
$m->setHtml($message['html']);
$m->setDate(new \DateTime($message['date']));

$this->assertEquals($message['title'], $m->getTitle());
Expand All @@ -59,6 +62,7 @@ public function testGettersAndSetters()
$this->assertEquals($message['url_title'], $m->getUrlTitle());
$this->assertEquals($message['priority'], $m->getPriority());
$this->assertEquals($message['sound'], $m->getSound());
$this->assertEquals($message['html'], $m->getHtml());
$this->assertEquals($message['date'], $m->getDate()
->format('Y-m-d'));
}
Expand All @@ -76,6 +80,7 @@ public function testHasMethods()
$this->assertFalse($m->hasUrl());
$this->assertFalse($m->hasUrlTitle());
$this->assertFalse($m->hasSound());
$this->assertFalse($m->hasHtml());
$this->assertFalse($m->hasDate());
}

Expand All @@ -88,12 +93,14 @@ public function testHasMethods()
$m->setUrlTitle($message['url_title']);
$m->setPriority($message['priority']);
$m->setSound($message['sound']);
$m->setHtml($message['html']);
$m->setDate(new \DateTime($message['date']));

$this->assertTrue($m->hasTitle());
$this->assertTrue($m->hasUrl());
$this->assertTrue($m->hasUrlTitle());
$this->assertTrue($m->hasSound());
$this->assertTrue($m->hasHtml());
$this->assertTrue($m->hasDate());
}
}
Expand Down

0 comments on commit 74b88f8

Please sign in to comment.