public function testGetMessages() { $this->prepareConfig(); if ($this->apiKey) { ChatworkSDK::setApiKey($this->apiKey); $room = new ChatworkRoom($this->roomId); $messages = $room->getMessages(); $this->assertInternalType('array', $messages); $checkClass = true; $lastMessage = null; foreach ($messages as $message) { if (!$message instanceof wataridori\ChatworkSDK\ChatworkMessage) { $checkClass = false; } $lastMessage = $message; } $this->assertTrue($checkClass); if ($lastMessage) { $room->resetMessage(); $room->appendReplyInRoom($lastMessage); $room->appendQuote($lastMessage); $room->appendInfo('Test Quote, Reply, Info text', 'Test from Chatwork-SDK'); $room->sendMessage(); } } $this->assertTrue(true); }
public function testGetRooms() { $this->prepareConfig(); if ($this->apiKey) { ChatworkSDK::setApiKey($this->apiKey); $api = new ChatworkApi(); $api->getRooms(); } $this->assertTrue(true); }
/** * Send Request to Chatwork. * * @throws RequestFailException * * @return array */ public function send() { $curl = curl_init(); $url = $this->buildUrl(); curl_setopt($curl, CURLOPT_HTTPHEADER, [$this->getHeader()]); switch ($this->method) { case self::REQUEST_METHOD_GET: curl_setopt($curl, CURLOPT_HTTPGET, 1); if ($this->params) { $url .= '?' . http_build_query($this->params, '', '&'); } break; case self::REQUEST_METHOD_POST: curl_setopt($curl, CURLOPT_POST, 1); if ($this->params) { curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->params, '', '&')); } break; case self::REQUEST_METHOD_PUT: curl_setopt($curl, CURLOPT_PUT, 1); if ($this->params) { curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->params, '', '&')); } break; case self::REQUEST_METHOD_DELETE: curl_setopt($curl, CURLOPT_CUSTOMREQUEST, self::REQUEST_METHOD_DELETE); if ($this->params) { $url .= '?' . http_build_query($this->params, '', '&'); } break; } curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if (!ChatworkSDK::getSslVerificationMode()) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); } $response = json_decode(curl_exec($curl), 1); $info = curl_getinfo($curl); curl_close($curl); if ($info['http_code'] >= 400) { $error = $response['errors']; throw new RequestFailException(); } return ['http_code' => $info['http_code'], 'response' => $response]; }
/** * @param string|null $roomId */ public function __construct($roomId = null) { $this->setApiKey(ChatworkSDK::getApiKey()); $this->setRoomId($roomId); $this->chatworkApi = new ChatworkApi(); }