Example #1
0
 /**
  * @param array $attributes
  * @return Message
  * @throws \InvalidArgumentException
  */
 public static function fromGitterObject(array $attributes)
 {
     $fields = ['gitter_id', 'text', 'html', 'edited', 'user', 'unread', 'read_by', 'urls', 'mentions', 'issues', 'meta', 'created_at', 'updated_at', 'room_id'];
     $values = (new AttributeMapper($attributes))->rename('readBy', 'read_by')->rename('id', 'gitter_id')->value('editedAt', function ($val) {
         return !!$val;
     }, 'edited')->value('fromUser', function ($user) {
         return User::fromGitterObject($user);
     }, 'user')->value('sent', function ($date) {
         return (new Carbon($date))->setTimezone('Europe/Moscow');
     }, 'created_at')->value('editedAt', function ($date) {
         return (new Carbon($date))->setTimezone('Europe/Moscow');
     }, 'updated_at')->value('mentions', function ($mentions) {
         return static::parseMentions($mentions);
     })->only($fields)->toArray();
     if (!array_key_exists('room_id', $values)) {
         $values['room_id'] = \App::make(Room::class)->id;
     }
     return static::unguarded(function () use($values) {
         return new static($values);
     });
 }
Example #2
0
 /**
  * @param Repository $config
  * @param Container $container
  */
 public function syncUsers(Repository $config, Container $container)
 {
     $this->output->write('Start user sync...');
     $config->set('gitter.output', false);
     $client = Client::make($config->get('gitter.token'), $this->argument('room'));
     $room = $container->make(Room::class);
     $users = $client->request('room.users', ['roomId' => $room->id]);
     $message = "\r<comment>[%s/%s]</comment> %s%80s";
     $count = count($users);
     $current = 1;
     foreach ($users as $user) {
         $user = User::fromGitterObject($user);
         $this->output->write(sprintf($message, $current, $count, $user->login, ''));
         $current++;
     }
     $this->output->write(sprintf($message, $count, $count, 'OK', ''));
 }
Example #3
0
 /**
  * @param null|string $gitterUserId
  * @return $this
  * @throws InvalidArgumentException
  */
 public function authAs($gitterUserId = null)
 {
     $auth = $this->request('user', ['userId' => $gitterUserId])[0];
     $this->user = User::fromGitterObject($auth);
     \Auth::loginUsingId($this->user->id);
     return $this;
 }