Add SMS send logs

This commit is contained in:
Javier Hernández Gil 2014-04-08 22:10:29 +02:00
parent 946f86d962
commit 50616db723
2 changed files with 15 additions and 4 deletions

View File

@ -3,6 +3,7 @@ namespace Jhg\NexmoBundle\NexmoClient;
use Jhg\NexmoBundle\NexmoClient\Exceptions\QuotaExcededException; use Jhg\NexmoBundle\NexmoClient\Exceptions\QuotaExcededException;
use Jhg\NexmoBundle\NexmoClient\Exceptions\UnroutableSmsMessageException; use Jhg\NexmoBundle\NexmoClient\Exceptions\UnroutableSmsMessageException;
use Psr\Log\LoggerInterface;
class NexmoClient { class NexmoClient {
@ -36,20 +37,27 @@ class NexmoClient {
*/ */
protected $disable_delivery; protected $disable_delivery;
/**
* @var LoggerInterface
*/
protected $logger;
/** /**
* @param $api_key * @param $api_key
* @param $api_secret * @param $api_secret
* @param string $api_method GET|POST configured in Nexmo API preferences * @param string $api_method GET|POST configured in Nexmo API preferences
* @param string $delivery_phone * @param string $delivery_phone
* @param boolean $disable_delivery * @param boolean $disable_delivery
* @param LoggerInterface $logger
*/ */
public function __construct($api_key,$api_secret,$api_method='GET',$delivery_phone,$disable_delivery=false) { public function __construct($api_key,$api_secret,$api_method='GET',$delivery_phone,$disable_delivery=false,LoggerInterface $logger) {
$this->rest_url = 'https://rest.nexmo.com'; $this->rest_url = 'https://rest.nexmo.com';
$this->api_key = $api_key; $this->api_key = $api_key;
$this->api_secret = $api_secret; $this->api_secret = $api_secret;
$this->api_method = $api_method; $this->api_method = $api_method;
$this->delivery_phone = $delivery_phone; $this->delivery_phone = $delivery_phone;
$this->disable_delivery = $disable_delivery; $this->disable_delivery = $disable_delivery;
$this->logger = $logger;
} }
/** /**
@ -107,9 +115,13 @@ class NexmoClient {
* @throws \Exception * @throws \Exception
*/ */
public function sendTextMessage($fromName,$toNumber,$text,$status_report_req=0) { public function sendTextMessage($fromName,$toNumber,$text,$status_report_req=0) {
$this->logger->debug("Nexmo sendTextMessage from $fromName to $toNumber with text '$text'");
// delivery phone for development // delivery phone for development
if($this->delivery_phone) { if($this->delivery_phone) {
$toNumber = $this->delivery_phone; $toNumber = $this->delivery_phone;
$this->logger->debug("Nexmo sendTextMessage delivery to $toNumber");
} }
$params = array( $params = array(
@ -120,6 +132,7 @@ class NexmoClient {
); );
if($this->disable_delivery) { if($this->disable_delivery) {
$this->logger->debug("Nexmo sendTextMessage delivery disabled by config");
return null; return null;
} }

View File

@ -1,9 +1,7 @@
services: services:
jhg_nexmo_client: jhg_nexmo_client:
class: Jhg\NexmoBundle\NexmoClient\NexmoClient 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.disable_delivery%",@logger]
"%jhg_nexmo.api_method%","%jhg_nexmo.delivery_phone%",
"%jhg_nexmo.disable_delivery%"]
jhg_nexmo_account: jhg_nexmo_account:
class: Jhg\NexmoBundle\Managers\AccountManager class: Jhg\NexmoBundle\Managers\AccountManager