Exemplo n.º 1
0
 /**
  * Send command
  *
  * @param Client $client Pushy client
  *
  * @return null|string null if no receipt, string if there is
  */
 public function send(Client $client)
 {
     // Init api params
     $apiParams = array_merge(['token' => $client->getApiToken(), 'user' => $this->message->getUser()->getId(), 'device' => $this->message->getUser()->getDeviceName(), 'message' => $this->message->getMessage(), 'title' => $this->message->getTitle(), 'url' => $this->message->getUrl(), 'url_title' => $this->message->getUrlTitle(), 'timestamp' => $this->message->getTimestamp()], $this->message->getPriority()->getApiParameters());
     // Set optional sound
     if ($sound = $this->message->getSound()) {
         $apiParams['sound'] = (string) $sound;
     }
     // Create request message
     $requestMessage = (new RequestMessage())->setMethod('POST')->setPath('messages.json');
     // Set API params
     foreach ($apiParams as $param => $value) {
         // Skip param if null
         if ($value === null) {
             continue;
         }
         $requestMessage->setPostBodyField($param, $value);
     }
     // Send request
     $response = $client->getTransport()->sendRequest($requestMessage);
     // Return receipt if there is one
     if (isset($response->receipt)) {
         return $response->receipt;
     }
 }
Exemplo n.º 2
0
 /**
  * Test: Get/Set user
  *
  * @covers \Pushy\Message::getUser
  * @covers \Pushy\Message::setUser
  */
 public function testGetSetUser()
 {
     $this->message->setUser($this->mockUser);
     $this->assertEquals($this->mockUser, $this->message->getUser());
 }