Exemplo n.º 1
0
 /**
  * STREAM
  */
 public function testStreamAdapter()
 {
     $client = $this->client();
     $message = (string) memory_get_usage(true);
     $routeStream = Route::get('rooms/{roomId}/chatMessages')->with('roomId', $this->debugRoomId())->toStream();
     $routeAnswer = Route::post('rooms/{roomId}/chatMessages')->with('roomId', $this->debugRoomId());
     // Connect to client
     $client->adapters->through(StreamBuzzAdapter::class)->request($routeStream)->subscribe(function ($answer) use($client, $message) {
         $this->assertInternalType('array', $answer);
         $this->assertArrayHasKey('text', $answer);
         if ($message === $answer['text']) {
             $client->disconnect();
         }
     });
     // Send message after 1 second
     $client->loop->addTimer(1, function () use($message, $routeAnswer) {
         $this->client()->adapters->through(SyncBuzzAdapter::class)->request($routeAnswer->withBody('text', $message));
     });
     // Throws exception after 10 seconds timeout
     $client->loop->addTimer(10, function () use($client) {
         $client->disconnect();
         $this->throwException(new \RuntimeException('Client timeout'));
     });
     $client->connect();
 }
Exemplo n.º 2
0
 /**
  * @param string $message
  * @return Route
  */
 private function buildRoute(string $message) : Route
 {
     $icon = $this->level === static::HOOK_LEVEL_ERROR ? 'error' : $this->level;
     $route = Route::post($this->hookId)->toWebhook()->withBody('message', $message)->withBody('errorLevel', $this->level);
     if ($this->icon !== null) {
         $route->withBody('icon', $icon);
     }
     return $route;
 }
Exemplo n.º 3
0
 /**
  * To join a room you'll need to provide a URI for it.
  *
  * Said URI can represent a GitHub Org, a GitHub Repo or a Gitter Channel.
  *  - If the room exists and the user has enough permission to access it, it'll be added to the room.
  *  - If the room doesn't exist but the supplied URI represents a GitHub Org or GitHub Repo the user
  *
  * is an admin of, the room will be created automatically and the user added.
  *
  * @param string $name Required URI of the room you would like to join
  * @return mixed
  */
 public function joinByName(string $name)
 {
     return $this->fetch(Route::post('rooms')->withBody('uri', $name));
 }
Exemplo n.º 4
0
 /**
  * Send a message to a room.
  *
  * @param string $roomId Room id
  * @param string $content Message body
  * @return mixed
  */
 public function create(string $roomId, string $content)
 {
     return $this->fetch(Route::post('rooms/{roomId}/chatMessages')->with('roomId', $roomId)->withBody('text', $content));
 }
Exemplo n.º 5
0
 /**
  * There is an additional endpoint nested under rooms that you can use to mark chat messages as read
  *
  * @param string $roomId
  * @param array $messageIds
  * @param string|null $userId
  * @return mixed
  * @throws \InvalidArgumentException
  */
 public function markAsRead(string $roomId, array $messageIds, string $userId = null)
 {
     return $this->fetch(Route::post('user/{userId}/rooms/{roomId}/unreadItems')->withMany(['userId' => $userId ?? $this->currentUserId(), 'roomId' => $roomId])->withBody('chat', $messageIds));
 }