Skip to content

Commit

Permalink
Merge pull request #2 from Palleas/message_color
Browse files Browse the repository at this point in the history
Added support for color when sending a message to a room.
  • Loading branch information
powdahound committed Jul 26, 2011
2 parents 8cdd4d1 + 8d814aa commit e8e834b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions HipChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class HipChat {
const STATUS_INTERNAL_SERVER_ERROR = 500;
const STATUS_SERVICE_UNAVAILABLE = 503;

const COLOR_YELLOW = 'yellow';
const COLOR_RED = 'red';
const COLOR_GREEN = 'green';
const COLOR_PURPLE = 'purple';
const COLOR_RANDOM = 'random';

/**
* API versions
*/
Expand Down Expand Up @@ -79,12 +85,19 @@ public function get_rooms() {
*
* @see http://api.hipchat.com/docs/api/method/rooms/message
*/
public function message_room($room_id, $from, $message, $notify = false) {
public function message_room($room_id, $from, $message, $notify = false, $color = self::COLOR_YELLOW) {

if (!in_array($color, array(self::COLOR_YELLOW, self::COLOR_PURPLE, self::COLOR_GREEN, self::COLOR_RED, self::COLOR_RANDOM)))
{
throw new InvalidArgumentException(sprintf('Unkown color "%s"', $color));
}

$args = array(
'room_id' => $room_id,
'from' => $from,
'message' => utf8_encode($message),
'notify' => (int)$notify
'notify' => (int)$notify,
'color' => $color
);
$response = $this->make_request("rooms/message", $args, 'POST');
return ($response->status == 'sent');
Expand Down
8 changes: 8 additions & 0 deletions tests/HipChatPHPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ public function testBadApiMethod() {
$hc->make_request('bad/method');
}

public function testBadColor()
{
$bad_color = 'fancy pink';
$hc = new HipChat('hipchat-php-test-token', $this->target);
$this->setExpectedException('InvalidArgumentException');
$hc->message_room(1337, 'Hipchat', "Hi everybody.", false, $bad_color);
}

}

0 comments on commit e8e834b

Please sign in to comment.