/** * Sends a request to the API for sending a SMS to the specified address. * * @param string $addr address to which SMS should be sent. * @param string $msg SMS message body to send. * @param boolean $notifyDeliveryStatus whether the API should sent a * notification after delivery. * * @return SendSMSResponse API response. * @throws ServiceException if API request was not successful. */ public function sendSMS($addr, $msg, $notifyDeliveryStatus = true) { $vals = array('address' => $addr, 'message' => $msg, 'notifyDeliveryStatus' => $notifyDeliveryStatus); $jsobj = array('outboundSMSRequest' => $vals); $jvals = json_encode($jsobj); $endpoint = $this->getFqdn() . '/sms/v3/messaging/outbox'; $req = new RESTFulRequest($endpoint); $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/json'); $httpPost = new HttpPost(); $httpPost->setBody($jvals); $result = $req->sendHttpPost($httpPost); $arr = Service::parseJson($result); return SendSMSResponse::fromArray($arr); }
public function testFromArray() { $str = ' { "outboundSMSResponse": { "messageId":"msg0", "resourceReference": { "resourceURL":"https://api.att.com/sms/v3/messaging/outbox/123" } } } '; $arr = json_decode($str, true); $r = SendSMSResponse::fromArray($arr); $this->assertEquals($r->getMessageId(), 'msg0'); $this->assertEquals($r->getResourceUrl(), 'https://api.att.com/sms/v3/messaging/outbox/123'); }
/** * Sends a request to the API for sending a SMS to the specified address. * * @param string $addr address to which SMS should be sent. * @param string $msg SMS message body to send. * @param boolean $notifyDeliveryStatus whether the API should sent a * notification after delivery. * * @return SendSMSResponse API response. * @throws ServiceException if API request was not successful. */ public function sendSMS($addr, $msg, $notifyDeliveryStatus = false, $raw_response = false) { $vals = array('address' => $addr, 'message' => $msg, 'notifyDeliveryStatus' => $notifyDeliveryStatus); $jsobj = array('outboundSMSRequest' => $vals); $jvals = json_encode($jsobj); $endpoint = $this->getFqdn() . '/sms/v3/messaging/outbox'; $req = new RESTFulRequest($endpoint); $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/json'); $httpPost = new HttpPost(); $httpPost->setBody($jvals); $result = $req->sendHttpPost($httpPost); // Handle the flag to return json. if ($raw_response) { $body = Service::parseApiResposeBody($result); // Note: This could throw ServiceExeption return $body; } $arr = Service::parseJson($result); return SendSMSResponse::fromArray($arr); }