public function testFromArray() { $str = ' { "InboundSmsMessageList": { "InboundSmsMessage": [ { "MessageId":"msg0", "Message":"Hello", "SenderAddress":"tel:5555551234" } ], "NumberOfMessagesInThisBatch":"1", "ResourceUrl":"http://api.att.com/sms/v3/messaging/inbox/123", "TotalNumberOfPendingMessages":"0" } } '; $arr = json_decode($str, true); $r = GetSMSResponse::fromArray($arr); $this->assertEquals($r->getNumberOfMessages(), 1); $this->assertEquals($r->getResourceUrl(), 'http://api.att.com/sms/v3/messaging/inbox/123'); $this->assertEquals($r->getNumberOfPendingMessages(), 0); $msg = $r->getMessages()[0]; $this->assertEquals($msg->getMessageId(), 'msg0'); $this->assertEquals($msg->getMessage(), 'Hello'); $this->assertEquals($msg->getSenderAddress(), 'tel:5555551234'); }
/** * Sends a request to the API for getting any SMS messages that were sent * to the specified short code. * * @param string $shortCode gets messages sent to this short code * * @return GetSMSResponse API response * @throws ServiceException if API request was not successful */ public function getMessages($shortCode, $raw_response = false) { $endpoint = $this->getFqdn() . '/sms/v3/messaging/inbox/' . urlencode($shortCode); $req = new RESTFulRequest($endpoint); $result = $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/x-www-form-urlencoded')->sendHttpGet(); // 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 GetSMSResponse::fromArray($arr); }
/** * Sends a request to the API for getting any SMS messages that were sent * to the specified short code. * * @param string $shortCode gets messages sent to this short code * * @return GetSMSResponse API response * @throws ServiceException if API request was not successful */ public function getMessages($shortCode) { $endpoint = $this->getFqdn() . '/sms/v3/messaging/inbox/' . urlencode($shortCode); $req = new RESTFulRequest($endpoint); $result = $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/x-www-form-urlencoded')->sendHttpGet(); $arr = Service::parseJson($result); return GetSMSResponse::fromArray($arr); }