class Gitter::API::Room

Model representation of the /room/:room_id/* REST endpoints in the gitter API

Attributes

id[R]

Room id

lurk[R]

Indicates if the room is configured with notifications for the user

mentions[R]

Number of unread mentions for this room

name[R]

Room name

one_on_one[R]

Indicates if the room is a one on one chat

public[R]

Indicates if the room is public

room_id[R]

Room id

tags[R]

Array of tags for the room

topic[R]

Room topic

unread_items[R]

Number of unread messages for this room

uri[R]

Room URI on gitter

url[R]

Room url

user_count[R]

Number of users in the room

Public Class Methods

find(uri) click to toggle source

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

# File lib/gitter/api/room.rb, line 63
def self.find uri
  Client.find_room uri
end
new(client, data) click to toggle source

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

Calls superclass method
# 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() click to toggle source

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
messages(options = {}) click to toggle source

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_message(message) click to toggle source

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() click to toggle source

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
users(options = {}) click to toggle source

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