Skip to content

Commit

Permalink
Merge pull request #3 from pgodel/command
Browse files Browse the repository at this point in the history
Commands for sending a message to a room and setting the room topic has been added.
  • Loading branch information
ManneW committed Aug 6, 2013
2 parents a57d629 + 2b5ef59 commit f3dcc83
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Command/SendMessageCommand.php
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);
}
}
44 changes: 44 additions & 0 deletions Command/SetRoomTopicCommand.php
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);
}
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ $hipChat = $this->container->get('hipchat');

```

The bundle also provides the following commands:

# send messages from the command
$ app/console hipchat:send:message --room='Room name' 'Message content' 'Sender name' --color=red

# set the room topic
$ app/console hipchat:set:room:topic 'Room name' 'new topic' 'Sender name'



# Further reading

Expand Down

0 comments on commit f3dcc83

Please sign in to comment.