diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 369eb3b..531b417 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -30,6 +30,11 @@ class Configuration implements ConfigurationInterface ->isRequired() ->end() + ->enumNode('api_method') + ->defaultValue('GET') + ->values(array('GET','POST')) + ->end() + ->scalarNode('from_name') ->validate() ->ifTrue(function ($s) { @@ -39,12 +44,16 @@ class Configuration implements ConfigurationInterface ->end() ->end() + ->scalarNode('delivery_phone') + ->defaultNull() + ->end() + ->booleanNode('disable_delivery') ->defaultFalse() ->end() ->end() ; - + return $treeBuilder; } } diff --git a/DependencyInjection/JhgNexmoExtension.php b/DependencyInjection/JhgNexmoExtension.php index 893447c..afd2b4a 100644 --- a/DependencyInjection/JhgNexmoExtension.php +++ b/DependencyInjection/JhgNexmoExtension.php @@ -23,7 +23,9 @@ class JhgNexmoExtension extends Extension $container->setParameter('jhg_nexmo.api_key', $config['api_key']); $container->setParameter('jhg_nexmo.api_secret', $config['api_secret']); + $container->setParameter('jhg_nexmo.api_method', $config['api_method']); $container->setParameter('jhg_nexmo.disable_delivery', $config['disable_delivery']); + $container->setParameter('jhg_nexmo.delivery_phone', $config['delivery_phone']); $container->setParameter('jhg_nexmo.from_name', $config['from_name']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); diff --git a/NexmoClient/NexmoClient.php b/NexmoClient/NexmoClient.php index a2cd103..8abe503 100644 --- a/NexmoClient/NexmoClient.php +++ b/NexmoClient/NexmoClient.php @@ -26,16 +26,23 @@ class NexmoClient { */ protected $api_method; + /** + * @var string + */ + protected $delivery_phone; + /** * @param $api_key * @param $api_secret * @param string $api_method GET|POST configured in Nexmo API preferences + * @param $delivery_phone */ - public function __construct($api_key,$api_secret,$api_method='GET') { + public function __construct($api_key,$api_secret,$api_method='GET',$delivery_phone) { $this->rest_url = 'https://rest.nexmo.com'; $this->api_key = $api_key; $this->api_secret = $api_secret; $this->api_method = $api_method; + $this->delivery_phone = $delivery_phone; } /** @@ -93,6 +100,11 @@ class NexmoClient { * @throws \Exception */ public function sendTextMessage($fromName,$toNumber,$text,$status_report_req=0) { + // delivery phone for development + if($this->delivery_phone) { + $toNumber = $this->delivery_phone; + } + $params = array( 'from'=>$fromName, 'to'=>$toNumber, diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 6d013a6..408a075 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,7 +1,7 @@ services: jhg_nexmo_client: class: Jhg\NexmoBundle\NexmoClient\NexmoClient - arguments: ["%jhg_nexmo.api_key%","%jhg_nexmo.api_secret%"] + arguments: ["%jhg_nexmo.api_key%","%jhg_nexmo.api_secret%","%jhg_nexmo.api_method%","%jhg_nexmo.delivery_phone%"] jhg_nexmo_account: class: Jhg\NexmoBundle\Managers\AccountManager