Class: Gitter::API::Room
- Includes:
- Collectable
- Defined in:
- lib/gitter/api/room.rb
Overview
Model representation of the /room/:room_id/* REST endpoints in the gitter API
Defined Under Namespace
Modules: ClientMethods
Instance Attribute Summary collapse
-
#id ⇒ Object
(also: #room_id)
readonly
Room id.
-
#lurk ⇒ Object
readonly
Indicates if the room is configured with notifications for the user.
-
#mentions ⇒ Object
readonly
Number of unread mentions for this room.
-
#name ⇒ Object
readonly
Room name.
-
#one_on_one ⇒ Object
readonly
Indicates if the room is a one on one chat.
-
#public ⇒ Object
readonly
Indicates if the room is public.
-
#tags ⇒ Object
readonly
Array of tags for the room.
-
#topic ⇒ Object
readonly
Room topic.
-
#unread_items ⇒ Object
readonly
Number of unread messages for this room.
-
#uri ⇒ Object
readonly
Room URI on gitter.
-
#url ⇒ Object
readonly
Room url.
-
#user_count ⇒ Object
readonly
Number of users in the room.
Attributes inherited from Base
Class Method Summary collapse
-
.find(uri) ⇒ Object
Find a room given a URI.
Instance Method Summary collapse
-
#initialize(client, data) ⇒ Room
constructor
INTERNAL METHOD.
-
#join ⇒ Object
Join the current room.
-
#messages(options = {}) ⇒ Object
List recent messages of a room.
-
#send_message(message) ⇒ Object
Send a message to the current room.
-
#unread_messages ⇒ Object
Unread messages in the room for the current user.
-
#users(options = {}) ⇒ Object
List users of a room.
Methods included from Collectable
Methods inherited from Base
Constructor Details
#initialize(client, data) ⇒ Room
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)
-
Room URI on Gitter
- url (String)
-
Path to the room on gitter
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# 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"] = data["tags"] @uri = data["uri"] @url = data["url"] end |
Instance Attribute Details
#id ⇒ Object (readonly) Also known as: room_id
Room id
10 11 12 |
# File 'lib/gitter/api/room.rb', line 10 def id @id end |
#lurk ⇒ Object (readonly)
Indicates if the room is configured with notifications for the user
22 23 24 |
# File 'lib/gitter/api/room.rb', line 22 def lurk @lurk end |
#mentions ⇒ Object (readonly)
Number of unread mentions for this room
28 29 30 |
# File 'lib/gitter/api/room.rb', line 28 def mentions @mentions end |
#name ⇒ Object (readonly)
Room name
13 14 15 |
# File 'lib/gitter/api/room.rb', line 13 def name @name end |
#one_on_one ⇒ Object (readonly)
Indicates if the room is a one on one chat
19 20 21 |
# File 'lib/gitter/api/room.rb', line 19 def one_on_one @one_on_one end |
#public ⇒ Object (readonly)
Indicates if the room is public
25 26 27 |
# File 'lib/gitter/api/room.rb', line 25 def public @public end |
#tags ⇒ Object (readonly)
Array of tags for the room
37 38 39 |
# File 'lib/gitter/api/room.rb', line 37 def end |
#topic ⇒ Object (readonly)
Room topic
16 17 18 |
# File 'lib/gitter/api/room.rb', line 16 def topic @topic end |
#unread_items ⇒ Object (readonly)
Number of unread messages for this room
34 35 36 |
# File 'lib/gitter/api/room.rb', line 34 def unread_items @unread_items end |
#uri ⇒ Object (readonly)
Room URI on gitter
40 41 42 |
# File 'lib/gitter/api/room.rb', line 40 def uri @uri end |
#url ⇒ Object (readonly)
Room url
43 44 45 |
# File 'lib/gitter/api/room.rb', line 43 def url @url end |
#user_count ⇒ Object (readonly)
Number of users in the room
31 32 33 |
# File 'lib/gitter/api/room.rb', line 31 def user_count @user_count end |
Class Method Details
.find(uri) ⇒ Object
Find a room given a URI
See Gitter::API::Room::ClientMethods#find_room
Parameters
- uri (String)
-
Room URI on Gitter
Example
client.find "gitterhq/sandbox"
#=> <#Gitter::API::Room name="gitterhq/sandbox" ...>
:return: Gitter::API::Room
63 64 65 |
# File 'lib/gitter/api/room.rb', line 63 def self.find uri Client.find_room uri end |
Instance Method Details
#join ⇒ Object
Join the current room
:return: Gitter::API::Room
170 171 172 173 174 175 |
# 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 |
#messages(options = {}) ⇒ Object
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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gitter/api/room.rb', line 151 def = {} query = { "skip" => [:skip], "beforeId" => [:before], "afterId" => [:after], "aroundId" => [:around], "limit" => [:limit], "q" => [:search] } data = client.get "/v1/rooms/#{id}/chatMessages", query Message::Collection.new self, data end |
#send_message(message) ⇒ Object
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
188 189 190 191 192 193 |
# File 'lib/gitter/api/room.rb', line 188 def payload = { "text" => }.to_json data = client.post "#{api_prefix}/rooms/#{id}/chatMessages", payload Message.new client, id, data end |
#unread_messages ⇒ Object
Unread messages in the room for the current user
:return: Gitter::API::Message::Collection
199 200 201 202 203 |
# File 'lib/gitter/api/room.rb', line 199 def data = client.get "#{api_prefix}/user/#{client.user.id}/rooms/#{id}/unreadItems" Message::Collection.new self, data end |
#users(options = {}) ⇒ Object
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
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/gitter/api/room.rb', line 123 def users = {} query = { "skip" => [:skip], "limit" => [:limit], "q" => [:search] } data = client.get "/#{api_prefix}/rooms/#{id}/users", query User::Collection.new self, data end |