Phue\Command\CreateSchedule::send PHP Method

send() public method

Send command
public send ( Client $client ) : integer
$client Phue\Client Phue Client
return integer Schedule Id
    public function send(Client $client)
    {
        // Set command attribute if passed
        if ($this->command) {
            $params = $this->command->getActionableParams($client);
            $params['address'] = "/api/{$client->getUsername()}" . $params['address'];
            $this->attributes['command'] = $params;
        }
        // Set time attribute if passed
        if ($this->time) {
            $this->attributes['time'] = (string) $this->time;
        }
        // Create schedule
        $scheduleId = $client->getTransport()->sendRequest("/api/{$client->getUsername()}/schedules", TransportInterface::METHOD_POST, (object) $this->attributes);
        return $scheduleId;
    }

Usage Example

Example #1
0
 /**
  * Test: Send command
  *
  * @covers \Phue\Command\CreateSchedule::__construct
  * @covers \Phue\Command\CreateSchedule::send
  */
 public function testSend()
 {
     $command = new CreateSchedule('Dummy!', '2012-12-30T10:11:12', $this->mockCommand);
     $command->description('Description!');
     // Stub transport's sendRequest usage
     $this->mockTransport->expects($this->once())->method('sendRequest')->with($this->equalTo("{$this->mockClient->getUsername()}/schedules"), $this->equalTo(TransportInterface::METHOD_POST), $this->equalTo((object) ['name' => 'Dummy!', 'description' => 'Description!', 'time' => '2012-12-30T10:11:12', 'command' => ['method' => TransportInterface::METHOD_POST, 'address' => "/api/endpoint", 'body' => "Dummy"]]))->will($this->returnValue(4));
     // Send command and get response
     $scheduleId = $command->send($this->mockClient);
     // Ensure we have a schedule id
     $this->assertEquals($scheduleId, 4);
 }