예제 #1
0
 public function testSetMessageWithBadArgumentFails()
 {
     $recipient = '49123456789';
     $sender = 'easySMS';
     $message = 'Hi, this is me';
     $instance = new Message($recipient, $sender, $message);
     $this->setExpectedException('\\InvalidArgumentException');
     $instance->setMessageText(null);
 }
예제 #2
0
 /**
  * Sends a message through the gateway.
  *
  * @param Message $message Message
  * @param bool    $debug   If debug mode should be enabled
  *
  * @return \AndreasWeber\SMS\Core\Response
  * @throws \RuntimeException
  */
 public function send(Message $message, $debug = false)
 {
     // gather arguments
     $params = array('key' => $this->apiKey, 'to' => $message->getTo(), 'message' => $message->getMessageText(), 'route' => $this->route, 'from' => $message->getFrom(), 'debug' => $debug ? 1 : 0);
     // build request
     $query = http_build_query($params, null, '&');
     // send request via curl
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, self::URI);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
     curl_setopt($ch, CURLOPT_USERAGENT, 'easySMS-php');
     $responseCode = intval(curl_exec($ch));
     curl_close($ch);
     // prepare response
     $response = new Response(time(), 100 === $responseCode ? true : false, $responseCode, $this->getResponseMessageToResponseCode($responseCode));
     // return response
     return $response;
 }
예제 #3
0
 /**
  * Sets options to params instance.
  *
  * @param \stdClass $params
  * @param Message   $message
  *
  * @return Message
  */
 private function setOptions(\stdClass $params, Message $message)
 {
     foreach ($message->getOptions() as $property => $value) {
         $params->{$property} = $value;
     }
     return $message;
 }