class Gitter::API::Room
Model representation of the /room/:room_id/*
REST endpoints in the gitter API
Attributes
Room
id
Indicates if the room is configured with notifications for the user
Number of unread mentions for this room
Room
name
Indicates if the room is a one on one chat
Indicates if the room is public
Room
id
Room
topic
Number of unread messages for this room
Room
URI on gitter
Room
url
Number of users in the room
Public Class Methods
Find a room given a URI
See Gitter::API::Room::ClientMethods#find_room
Parameters¶ ↑
Example¶ ↑
client.find "gitterhq/sandbox" #=> <#Gitter::API::Room name="gitterhq/sandbox" ...>
:return: Gitter::API::Room
# File lib/gitter/api/room.rb, line 63 def self.find uri Client.find_room uri end
INTERNAL METHOD
Initialize a new Gitter::API::Room
Use Gitter::API::Room::ClientMethods
(found of Gitter::API::Client
) to initialize and make use of the instance methods.
Parameters¶ ↑
- client (
Gitter::API::Client
) -
Configured client object
- data (Hash)
-
Initialization data
Options¶ ↑
(string keys only)
- id (String)
-
Room
id - name (String)
-
Room
name - topic (String)
-
Room
topic - one_on_one (Boolean)
-
Indicates if one on one chat
- lurk (Boolean)
-
Indicates if notifications disabled
- public (Boolean)
-
Indicates if public room
- unread_items (Integer)
-
Number of unread messages
- mentions (Integer)
-
Number of unread mentions
- user_count (Integer)
-
Number of users in the room
- tags (Array<String>)
-
Tags that define the room
- uri (String)
- url (String)
-
Path to the room on gitter
# File lib/gitter/api/room.rb, line 96 def initialize client, data super @id = data["id"] @name = data["name"] @topic = data["topic"] @one_on_one = data["oneOnOne"] @lurk = data["lurk"] @public = data["public"] @mentions = data["mentions"] @user_count = data["userCount"] @unread_items = data["unreadItems"] @tags = data["tags"] @uri = data["uri"] @url = data["url"] end
Public Instance Methods
Join the current room
:return: Gitter::API::Room
# File lib/gitter/api/room.rb, line 170 def join payload = { "id" => id }.to_json data = client.post "#{api_prefix}/user/#{client.user.id}/rooms", payload self end
List recent messages of a room
Options¶ ↑
- :search (String)
-
Filter based on search query
- :before (String)
-
Limit messages to before a date
- :after (String)
-
Limit messages to after a date
- :around (String)
-
Limit messages to around a date
- :limit (Integer)
-
Limit number of records returned
- :skip (Integer)
-
Return users after skiping N records
Returns a collection of most recent messages, with the oldest of that collection being first in the returned list.
:return: Gitter::API::User::Collection
# File lib/gitter/api/room.rb, line 151 def messages options = {} query = { "skip" => options[:skip], "beforeId" => options[:before], "afterId" => options[:after], "aroundId" => options[:around], "limit" => options[:limit], "q" => options[:search] } data = client.get "/v1/rooms/#{id}/chatMessages", query Message::Collection.new self, data end
Send a message to the current room
Parameters¶ ↑
- message (String)
-
Message
to send to the room
Messages should be in plain text/mardown format, and will be converted to html on the server side.
:return: Gitter::API::Message
# File lib/gitter/api/room.rb, line 188 def send_message message payload = { "text" => message }.to_json data = client.post "#{api_prefix}/rooms/#{id}/chatMessages", payload Message.new client, id, data end
Unread messages in the room for the current user
:return: Gitter::API::Message::Collection
# File lib/gitter/api/room.rb, line 199 def unread_messages data = client.get "#{api_prefix}/user/#{client.user.id}/rooms/#{id}/unreadItems" Message::Collection.new self, data end
List users of a room
Options¶ ↑
- :search (String)
-
Filter based on search query
- :limit (Integer)
-
Limit number of records returned
- :skip (Integer)
-
Return users after skiping N records
:return: Gitter::API::User::Collection
# File lib/gitter/api/room.rb, line 123 def users options = {} query = { "skip" => options[:skip], "limit" => options[:limit], "q" => options[:search] } data = client.get "/#{api_prefix}/rooms/#{id}/users", query User::Collection.new self, data end