/** * Sends a user a private message * More info: https://www.hipchat.com/docs/apiv2/method/private_message_user * * @param string $user The id, email address, or mention name (beginning with an '@') * of the user to send a message to * @param mixed $message The message to send as plain text * * @return void */ public function privateMessageUser($user, $message) { if (is_string($message)) { $content = array('message' => $message); } else { // Assuming its a Message $content = $message->toJson(); } $this->client->post(sprintf('/v2/user/%s/message', $user), $content); }
/** * Creates a new webhook * More info: https://www.hipchat.com/docs/apiv2/method/create_webhook * * @param string $roomId The id or name of the room * @param Webhook $webhook The webhook to create * * @return int Just created webhook id */ public function createWebhook($roomId, Webhook $webhook) { $response = $this->client->post(sprintf('/v2/room/%s/webhook', $roomId), $webhook->toJson()); return $response['id']; }
function it_creates_webhook(Client $client, Webhook $webhook) { $request = array('url' => 'http://example.com/webhook', 'pattern' => '/phpspec/', 'event' => 'room_message', 'name' => '112233'); $webhook->toJson()->shouldBeCalled()->willReturn($request); $client->post('/v2/room/123456/webhook', $request)->shouldBeCalled(); $this->createWebhook('123456', $webhook); }
function it_sends_private_message_user(Client $client) { $client->post('/v2/user/123456/message', array('message' => 'Im testing!!'))->shouldBeCalled(); $this->privateMessageUser('123456', 'Im testing!!'); }