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
 /**
  * Send command
  *
  * @param Client $client Pushy client
  *
  * @return null|string null if no receipt, string if there is
  */
 public function send(Client $client)
 {
     // Create request message
     $requestMessage = (new RequestMessage())->setMethod('POST')->setPath("receipts/{$this->receipt}/cancel.json")->setQueryParam('token', $client->getApiToken());
     // Send request
     $response = $client->getTransport()->sendRequest($requestMessage);
     return (bool) $response->status;
 }
Exemplo n.º 3
0
 /**
  * Send command
  *
  * @param Client $client Pushy client
  *
  * @return bool true if valid, false if not
  */
 public function send(Client $client)
 {
     // Create request message
     $requestMessage = (new RequestMessage())->setMethod('POST')->setPath('users/validate.json')->setQueryParam('token', $client->getApiToken())->setQueryParam('user', $this->user->getId());
     // Set device name if one is available on the user
     if ($device = $this->user->getDeviceName()) {
         $requestMessage->setQueryParam('device', $device);
     }
     // Send request, and if no exception, user is valid
     $client->getTransport()->sendRequest($requestMessage);
     return true;
 }
Exemplo n.º 4
0
 /**
  * Test: Get default transport.
  *
  * @covers \Pushy\Client::getTransport
  */
 public function testGetDefaultTransport()
 {
     $client = new Client('KzGDORePK8gMaC0QOYAMyEEuzJnyUi');
     $this->assertInstanceOf('\\Pushy\\Transport\\TransportInterface', $client->getTransport());
 }