-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from pgodel/command
Commands for sending a message to a room and setting the room topic has been added.
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Mannew\HipchatBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
/** | ||
* Sends a message to a HipChat room | ||
*/ | ||
|
||
class SendMessageCommand extends ContainerAwareCommand | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
parent::configure(); | ||
|
||
$this | ||
->setName('hipchat:send:message') | ||
->setDescription('Sends a message to a HipChat room') | ||
->addArgument('message', InputArgument::REQUIRED, 'The Message') | ||
->addArgument('from', InputArgument::OPTIONAL, 'Sender Name', 'HipchatBundle') | ||
->addOption('room', null, InputOption::VALUE_REQUIRED, 'The HipChat Room') | ||
->addOption('notify', null, InputOption::VALUE_NONE, 'Notify room members') | ||
->addOption('color', null, InputOption::VALUE_OPTIONAL, 'Color', 'yellow') | ||
->addOption('format', null, InputOption::VALUE_OPTIONAL, 'Message format', 'html'); | ||
|
||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->input = $input; | ||
$this->output = $output; | ||
|
||
$message = $input->getArgument('message'); | ||
$from = $input->getArgument('from'); | ||
|
||
$room = $input->getOption('room'); | ||
$notify = $input->getOption('notify'); | ||
$color = $input->getOption('color'); | ||
$format = $input->getOption('format'); | ||
|
||
$hipChat = $this->getContainer()->get('hipchat'); | ||
|
||
if (empty($room)) { | ||
throw new \InvalidArgumentException("Please provide a valid room"); | ||
} | ||
|
||
$hipChat->message_room($room, $from, $message, $notify, $color, $format); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Mannew\HipchatBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
/** | ||
* Sets the topic for a HipChat room | ||
*/ | ||
|
||
class SetRoomTopicCommand extends ContainerAwareCommand | ||
{ | ||
|
||
protected function configure() | ||
{ | ||
parent::configure(); | ||
|
||
$this | ||
->setName('hipchat:set:room:topic') | ||
->setDescription('Sets the topic for a HipChat room') | ||
->addArgument('room', InputArgument::REQUIRED, 'The HipChat Room') | ||
->addArgument('topic', InputArgument::REQUIRED, 'The Topic') | ||
->addArgument('from', InputArgument::OPTIONAL, 'User name', 'HipchatBundle'); | ||
|
||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->input = $input; | ||
$this->output = $output; | ||
|
||
$room = $input->getArgument('room'); | ||
$topic = $input->getArgument('topic'); | ||
$from = $input->getArgument('from'); | ||
|
||
$hipChat = $this->getContainer()->get('hipchat'); | ||
|
||
$hipChat->set_room_topic($room, $topic, $from); | ||
} | ||
} |
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