/** * 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; } }
/** * Test: Get/Set priority * * @covers \Pushy\Message::getPriority * @covers \Pushy\Message::setPriority */ public function testGetSetPriority() { $this->message->setPriority($this->mockPriority); $this->assertEquals($this->mockPriority, $this->message->getPriority()); }