rcrowe\Hippy\Transport\Guzzle::send PHP Method

send() public method

public send ( rcrowe\Hippy\Message\MessageInterface $message )
$message rcrowe\Hippy\Message\MessageInterface
    public function send(MessageInterface $message)
    {
        // Validate we have everything we need
        foreach (array('token', 'room', 'from') as $variable) {
            if (empty($this->{$variable})) {
                throw new InvalidArgumentException("Invalid `{$variable}`");
            }
        }
        // Build up the data we are sending to Hipchat
        $data = array('room_id' => $this->getRoom(), 'from' => $this->getFrom(), 'message' => $message->getMessage(), 'message_format' => $message->getMessageFormat(), 'notify' => $message->getNotification(), 'color' => $message->getBackgroundColor(), 'format' => 'json');
        $data = http_build_query($data, '', '&');
        return $this->http->post($this->getUri(), $this->getHeaders(), $data)->send();
    }

Usage Example

コード例 #1
0
ファイル: GuzzleSendTest.php プロジェクト: rcrowe/hippy
 public function testPost()
 {
     $guzzle = new Guzzle('123', 'cog', 'vivalacrowe');
     $message = new Message(true, 'green');
     $entity = m::mock('Guzzle\\Http\\Message\\EntityEnclosingRequest');
     $entity->shouldReceive('send')->once();
     // Build up the data we are sending to Hipchat
     $data = array('room_id' => $guzzle->getRoom(), 'from' => $guzzle->getFrom(), 'message' => $message->getMessage(), 'message_format' => $message->getMessageFormat(), 'notify' => $message->getNotification(), 'color' => $message->getBackgroundColor(), 'format' => 'json');
     $http = m::mock('Guzzle\\Http\\Client');
     $http->shouldReceive('post')->with('rooms/message?format=json&auth_token=123', array('Content-type' => 'application/x-www-form-urlencoded'), http_build_query($data))->andReturn($entity)->once();
     $guzzle->setHttp($http);
     $guzzle->send($message);
 }