2014-03-30 22:20:02 +00:00
|
|
|
<?php
|
|
|
|
namespace Jhg\NexmoBundle\Command;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Javi Hernández
|
|
|
|
*/
|
|
|
|
class SmsPricingCommand extends ContainerAwareCommand
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure() {
|
|
|
|
$this
|
|
|
|
->setName('nexmo:sms:pricing')
|
|
|
|
->setDescription('Gets sms price for given country')
|
|
|
|
->setDefinition(array(
|
|
|
|
new InputArgument('country', InputArgument::REQUIRED, 'The country code'),
|
|
|
|
))
|
|
|
|
->setHelp("The <info>nexmo:sms:pricing</info> command gets Nexmo API SMS pricing for a given country");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
|
|
|
$country = $input->getArgument('country');
|
|
|
|
|
2015-02-05 08:14:46 +00:00
|
|
|
$account = $this->getContainer()->get('jhg_nexmo_account');
|
2014-03-30 22:20:02 +00:00
|
|
|
$price = $account->smsPricing($country);
|
|
|
|
|
|
|
|
if($price===false) {
|
|
|
|
throw new \Exception("Country not valid");
|
|
|
|
} else {
|
|
|
|
$output->writeln(sprintf('SMS sending price for "%s": %f',$country,$price));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|