Exemplo n.º 1
1
 public function encode(\Esendex\Model\DispatchMessage $message)
 {
     if (strlen($message->originator()) < 1) {
         throw new ArgumentException("Originator is invalid");
     }
     if (strlen($message->recipient()) < 1) {
         throw new ArgumentException("Recipient is invalid");
     }
     if ($message->validityPeriod() > 72) {
         throw new ArgumentException("Validity too long, must be less or equal to than 72");
     }
     $doc = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><messages />", 0, false, Api::NS);
     $doc->accountreference = $this->reference;
     $child = $doc->addChild("message");
     $child->from = $message->originator();
     $child->to = $message->recipient();
     $child->body = $message->body();
     $child->type = $message->type();
     if ($message->validityPeriod() > 0) {
         $child->validity = $message->validityPeriod();
     }
     if ($message->language() != null) {
         $child->lang = $message->language();
     }
     return $doc->asXML();
 }
 /**
  * @test
  */
 function encodeVoiceMessage()
 {
     $reference = "EX123456";
     $message = new DispatchMessage("4412345678", "4487654321", "Something to say", Message::VoiceType, 36, "fr-FR");
     $parser = new DispatchXmlParser($reference);
     $doc = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><messages />", 0, false, Api::NS);
     $doc->addChild("accountreference", $reference);
     $child = $doc->addChild("message");
     $child->addChild("from", $message->originator());
     $child->addChild("to", $message->recipient());
     $child->addChild("body", $message->body());
     $child->addChild("type", Message::VoiceType);
     $child->addChild("validity", $message->validityPeriod());
     $child->addChild("lang", $message->language());
     $expected = $doc->asXML();
     $result = $parser->encode($message);
     $this->assertEquals($expected, $result);
 }
Exemplo n.º 3
0
 /**
  * Returns true if message was actually sent
  *
  * @param DispatchMessage $message
  * @return bool
  */
 public function doSend(DispatchMessage $message)
 {
     $this->logger->debug(sprintf('Sending Message: "%s", To: "%s", From: "%s"', $message->body(), $message->recipient(), $message->originator()));
     if (!$this->performSend) {
         $this->logger->debug('Not performing send as specified in configuration');
         return false;
     }
     try {
         $this->dispatchService->send($message);
         $this->logger->debug('Message was successfully sent');
     } catch (EsendexException $e) {
         //message failed to send
         //or error parsing the result
         $this->logger->critical($e->__toString());
         return false;
     }
     return true;
 }
 /**
  * @test
  * @dataProvider characterSets
  */
 function encodeCharacterSetMessage($charset)
 {
     $reference = "EX123456";
     $message = new DispatchMessage("4412345678", "4487654321", "Something to say", Message::SmsType, null, null, $charset);
     $parser = new DispatchXmlParser($reference);
     $doc = new \SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><messages />", 0, false, Api::NS);
     $doc->addAttribute("xmlns", Api::NS);
     $doc->addChild("accountreference", $reference);
     $doc->addChild("characterset", $charset);
     $child = $doc->addChild("message");
     $child->addChild("from", $message->originator());
     $child->addChild("to", $message->recipient());
     $child->addChild("body", $message->body());
     $child->addChild("type", Message::SmsType);
     $expected = $doc->asXML();
     $result = $parser->encode($message);
     $this->assertEquals($expected, $result);
 }