Class: Firering::Room

Inherits:
Struct
  • Object
show all
Extended by:
Instantiator
Defined in:
lib/firering/data/room.rb,
lib/firering/data/room.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Instantiator

instantiate

Instance Attribute Details

#active_token_valueObject

Returns the value of attribute active_token_value

Returns:

  • (Object)

    the current value of active_token_value



2
3
4
# File 'lib/firering/data/room.rb', line 2

def active_token_value
  @active_token_value
end

#connectionObject

Returns the value of attribute connection

Returns:

  • (Object)

    the current value of connection



2
3
4
# File 'lib/firering/data/room.rb', line 2

def connection
  @connection
end

#created_atObject

Returns the value of attribute created_at

Returns:

  • (Object)

    the current value of created_at



2
3
4
# File 'lib/firering/data/room.rb', line 2

def created_at
  @created_at
end

#fullObject Also known as: full?

Returns the value of attribute full

Returns:

  • (Object)

    the current value of full



2
3
4
# File 'lib/firering/data/room.rb', line 2

def full
  @full
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/firering/data/room.rb', line 2

def id
  @id
end

#lockedObject Also known as: locked?

Returns the value of attribute locked

Returns:

  • (Object)

    the current value of locked



2
3
4
# File 'lib/firering/data/room.rb', line 2

def locked
  @locked
end

#membership_limitObject

Returns the value of attribute membership_limit

Returns:

  • (Object)

    the current value of membership_limit



2
3
4
# File 'lib/firering/data/room.rb', line 2

def membership_limit
  @membership_limit
end

#nameObject Also known as: to_s

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/firering/data/room.rb', line 2

def name
  @name
end

#open_to_guestsObject Also known as: open_to_guests?

Returns the value of attribute open_to_guests

Returns:

  • (Object)

    the current value of open_to_guests



2
3
4
# File 'lib/firering/data/room.rb', line 2

def open_to_guests
  @open_to_guests
end

#topicObject

Returns the value of attribute topic

Returns:

  • (Object)

    the current value of topic



2
3
4
# File 'lib/firering/data/room.rb', line 2

def topic
  @topic
end

#updated_atObject

Returns the value of attribute updated_at

Returns:

  • (Object)

    the current value of updated_at



2
3
4
# File 'lib/firering/data/room.rb', line 2

def updated_at
  @updated_at
end

#users(&callback) ⇒ Object

we perform a request each time so 1) we always are are up to date with the users currently on the room (even if some left) 2) we make sure the users are here even if the room was instantiated from a /rooms request



20
21
22
# File 'lib/firering/data/room.rb', line 20

def users
  @users
end

Instance Method Details

#crickets(&callback) ⇒ Object



115
116
117
# File 'lib/firering/data/room.rb', line 115

def crickets(&callback)
  speak({:type => "SoundMessage", :body => "crickets"}, &callback)
end

#join(&callback) ⇒ Object

Join a room.



64
65
66
# File 'lib/firering/data/room.rb', line 64

def join(&callback)
  connection.http(:post, "/room/#{id}/join.json", &callback)
end

#leave(&callback) ⇒ Object

Leave a room.



69
70
71
# File 'lib/firering/data/room.rb', line 69

def leave(&callback)
  connection.http(:post, "/room/#{id}/leave.json", &callback)
end

#lock(&callback) ⇒ Object

Locks a room.



74
75
76
# File 'lib/firering/data/room.rb', line 74

def lock(&callback)
  connection.http(:post, "/room/#{id}/lock.json", &callback)
end

#loggerObject



26
27
28
# File 'lib/firering/data/room.rb', line 26

def logger
  self.connection.logger
end

#paste(paste, &callback) ⇒ Object



107
108
109
# File 'lib/firering/data/room.rb', line 107

def paste(paste, &callback)
  speak({:type => "PasteMessage", :body => paste}, &callback)
end

#recent_messages(limit = nil, &callback) ⇒ Object

Returns a collection of upto 100 recent messages in the room. Accepts an additional optional parameter ‘limit’ to restrict the number of messages returned.



43
44
45
46
47
# File 'lib/firering/data/room.rb', line 43

def recent_messages(limit = nil, &callback)
  connection.http(:get, "/room/#{id}/recent.json", (limit ? { :limit => limit } : nil)) do |data, http|
    callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
  end
end

#rimshot(&callback) ⇒ Object



111
112
113
# File 'lib/firering/data/room.rb', line 111

def rimshot(&callback)
  speak({:type => "SoundMessage", :body => "rimshot"}, &callback)
end

#speak(data, &callback) ⇒ Object

Sends a new message with the currently authenticated user as the sender. The XML for the new message is returned on a successful request.

The valid types are:

  • TextMessage (regular chat message)

  • PasteMessage (pre-formatted message, rendered in a fixed-width font)

  • SoundMessage (plays a sound as determined by the message, which can be either “rimshot”, “crickets”, or “trombone”)

  • TweetMessage (a Twitter status URL to be fetched and inserted into the chat)

If an explicit type is omitted, it will be inferred from the content (e.g., if the message contains new line characters, it will be considered a paste).

:type => “TextMessage”, :body => “Hello”



97
98
99
100
101
# File 'lib/firering/data/room.rb', line 97

def speak(data, &callback)
  connection.http(:post, "/room/#{id}/speak.json", "message" => data) do |data, http| # Response Status: 201 Created
    callback.call(Firering::Message.instantiate(connection, data, "message")) if callback
  end
end

#stream(&callback) ⇒ Object



12
13
14
# File 'lib/firering/data/room.rb', line 12

def stream(&callback)
  join { |data, http| connection.stream(self, &callback) }
end

#text(text, &callback) ⇒ Object



103
104
105
# File 'lib/firering/data/room.rb', line 103

def text(text, &callback)
  speak({:type => "TextMessage", :body => text}, &callback)
end

#today_transcript(&callback) ⇒ Object

Returns all the messages sent today to a room.



50
51
52
53
54
# File 'lib/firering/data/room.rb', line 50

def today_transcript(&callback)
  connection.http(:get, "/room/#{id}/transcript.json") do |data, http|
    callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
  end
end

#transcript(year, month, day, &callback) ⇒ Object

Returns all the messages sent on a specific date to a room.



57
58
59
60
61
# File 'lib/firering/data/room.rb', line 57

def transcript(year, month, day, &callback)
  connection.http(:get, "/room/#{id}/transcript/#{year}/#{month}/#{day}.json") do |data, http|
    callback.call(data[:messages].map { |msg| Firering::Message.instantiate(connection, msg) }) if callback
  end
end

#trombone(&callback) ⇒ Object



119
120
121
# File 'lib/firering/data/room.rb', line 119

def trombone(&callback)
  speak({:type => "SoundMessage", :body => "trombone"}, &callback)
end

#tweet(tweet_url, &callback) ⇒ Object



123
124
125
# File 'lib/firering/data/room.rb', line 123

def tweet(tweet_url, &callback)
  speak({:type => "TweetMessage", :body => tweet_url}, &callback)
end

#unlock(&callback) ⇒ Object

Unlocks a room.



79
80
81
# File 'lib/firering/data/room.rb', line 79

def unlock(&callback)
  connection.http(:post, "/room/#{id}/unlock.json", &callback)
end

#update(data, &callback) ⇒ Object

Updates an existing room. Only admins can rename a room, although any user (except guests) may set the topic. Omitting either key results in that attribute being ignored. To remove a room topic, simply provide an empty topic key.

update “name” => “Name”, “topic” => “Topic”



36
37
38
# File 'lib/firering/data/room.rb', line 36

def update(data, &callback)
  connection.http(:put, "/room/#{id}.json", { :room => data }, &callback)
end