Module: Gitter::API::Room::ClientMethods

Included in:
Client
Defined in:
lib/gitter/api/room.rb

Overview

Gitter::API::Room based methods that are available on any Gitter::API::Client instance

Instance Method Summary collapse

Instance Method Details

#find_room(uri) ⇒ Object

Find a room based off of uri

Parameters

uri (String)

Room URI on Gitter

Example

client.join_room "gitterhq/sandbox"
#=> <#Gitter::API::Room name="gitterhq/sandbox" ...>

:return: Gitter::API::Room



236
237
238
239
240
241
# File 'lib/gitter/api/room.rb', line 236

def find_room uri
  payload =  { "uri" => uri }.to_json
  data    = self.post "#{api_prefix}/rooms", payload

  Room.new(self, data)
end

#join_room(uri) ⇒ Object

Join a room from the top level client using the api user

Parameters

uri (String)

Room URI on Gitter

Example

client.join_room "gitterhq/sandbox"
#=> <#Gitter::API::Room name="gitterhq/sandbox" ...>

:return: Gitter::API::Room



256
257
258
259
260
261
262
263
# File 'lib/gitter/api/room.rb', line 256

def join_room uri
  has_room = rooms.detect { |room| room.uri == uri }

  return has_room if has_room

  @rooms = nil # clear rooms cache
  self.class.find_room(uri).join
end

#rooms(refresh = false) ⇒ Object

Memoized version of User#rooms for the api client user

Parameters

refresh (Boolean)

set to true refresh memoization

:return: Gitter::API::Room::Collection



217
218
219
220
221
# File 'lib/gitter/api/room.rb', line 217

def rooms refresh = false
  return @rooms unless @rooms.nil? || refresh

  @rooms = user.rooms
end