Esempio 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;
     }
 }
Esempio 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;
 }
Esempio n. 3
0
 /**
  * Test: Send command
  *
  * @covers \Pushy\Command\CancelEmergency::send
  */
 public function testSend()
 {
     // Stub mock client getAPiToken and getTransport
     $this->mockClient->shouldReceive('getApiToken')->andReturn('abc');
     $this->mockClient->shouldReceive('getTransport')->andReturn($this->mockTransport);
     // Stub mock transport sendRequest
     $this->mockTransport->shouldReceive('sendRequest')->andReturn((object) ['status' => 1]);
     // Ensure we get a message status back
     $this->assertTrue($this->cancelEmergencyCommand->send($this->mockClient));
 }
Esempio n. 4
0
 /**
  * Constructor.
  * @param Pushy\Client $pushy A preconfigured Pushy Client instance to use for sending.
  * @param Pushy\User $user A preconfigured Pushy User instance to use for sending.
  */
 public function __construct(Pushy\Client $pushy, Pushy\User $user)
 {
     try {
         $pushy->verifyUser($user);
     } catch (Pushy\Transport\Exception\ApiException $e) {
         throw new InvalidArgumentException('User is not valid', 1);
     }
     $this->pushy = $pushy;
     $this->user = $user;
 }
Esempio n. 5
0
 /**
  * Test: Send command
  *
  * @covers \Pushy\Command\GetMessageStatus::send
  */
 public function testSend()
 {
     // Stub mock client getAPiToken and getTransport
     $this->mockClient->shouldReceive('getApiToken')->andReturn('abc');
     $this->mockClient->shouldReceive('getTransport')->andReturn($this->mockTransport);
     // Stub mock transport sendRequest
     $this->mockTransport->shouldReceive('sendRequest')->andReturn(new \stdClass());
     // Ensure we get a message status back
     $this->assertInstanceOf('\\Pushy\\MessageStatus', $this->getMessageStatusCommand->send($this->mockClient));
 }
Esempio n. 6
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;
 }
Esempio n. 7
0
 /**
  * Test: Send command
  *
  * @covers \Pushy\Command\VerifyUser::send
  */
 public function testSend()
 {
     // Stub mock client getAPiToken and getTransport
     $this->mockClient->shouldReceive('getApiToken')->andReturn('abc');
     $this->mockClient->shouldReceive('getTransport')->andReturn($this->mockTransport);
     // Stub mock transport sendRequest
     $this->mockTransport->shouldReceive('sendRequest')->andReturn(new \stdClass());
     // Stub mock user getId and getDeviceName
     $this->mockUser->shouldReceive('getId')->andReturn('pQiRzpo4DXghDmr9QzzfQu27cmVRsG');
     $this->mockUser->shouldReceive('getDeviceName')->andReturn('droid2');
     // Ensure we get true back
     $this->assertTrue($this->verifyUserCommand->send($this->mockClient));
 }
Esempio n. 8
0
 /**
  * Test: Send command
  *
  * @covers \Pushy\Client::sendCommand
  */
 public function testSendCommand()
 {
     // Command returns a value
     $dummyValue = 'dummy!';
     // Mock command
     $mockCommand = Mockery::mock('\\Pushy\\Command\\CommandInterface')->shouldReceive('send')->times(1)->andReturn($dummyValue)->getMock();
     // Assert return value of command matches dummy
     $this->assertEquals($dummyValue, $this->client->sendCommand($mockCommand));
 }
Esempio n. 9
0
 /**
  * Test: Send command
  *
  * @covers \Pushy\Command\SendMessage::send
  */
 public function testSend()
 {
     // Stub mock client getAPiToken and getTransport
     $this->mockClient->shouldReceive('getApiToken')->andReturn('abc')->getMock()->shouldReceive('getTransport')->andReturn($this->mockTransport);
     // Stub mock transport sendRequest and response object
     $responseObject = (object) ['receipt' => 'receiptid'];
     $this->mockTransport->shouldReceive('sendRequest')->andReturn($responseObject);
     // Stub mock message methods
     $this->mockMessage->shouldReceive('getUser')->andReturn($this->mockUser)->getMock()->shouldReceive('getSound')->andReturn($this->mockSound)->getMock()->shouldReceive('getPriority')->andReturn($this->mockPriority);
     // Stub sound
     $this->mockSound->shouldReceive('__toString')->andReturn('soundname');
     // Stub mock priority getApiParameters
     $this->mockPriority->shouldReceive('getApiParameters')->andReturn([]);
     // Ensure we get a receipt back
     $this->assertEquals($responseObject->receipt, $this->sendMessageCommand->send($this->mockClient));
 }