Class: Tinder::Room

Inherits:
Object
  • Object
show all
Defined in:
lib/tinder/room.rb

Overview

A campfire room

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(campfire, attributes = {}) ⇒ Room

Returns a new instance of Room.



6
7
8
9
10
11
# File 'lib/tinder/room.rb', line 6

def initialize(campfire, attributes = {})
  @campfire = campfire
  @id = attributes['id']
  @name = attributes['name']
  @loaded = false
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/tinder/room.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/tinder/room.rb', line 4

def name
  @name
end

Instance Method Details

#available_transcriptsObject

Get the dates for the available transcripts for this room

Raises:

  • (NotImplementedError)


129
130
131
# File 'lib/tinder/room.rb', line 129

def available_transcripts
  raise NotImplementedError
end

#destroyObject

Raises:

  • (NotImplementedError)


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

def destroy
  raise NotImplementedError
end

#files(count = 5) ⇒ Object

Get the list of latest files for this room



162
163
164
# File 'lib/tinder/room.rb', line 162

def files(count = 5)
  connection.get(room_url_for(:uploads))['uploads'].map { |u| u['full_url'] }
end

#guest_access_enabled?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/tinder/room.rb', line 37

def guest_access_enabled?
  load
  @open_to_guests ? true : false
end

#guest_invite_codeObject

The invite code use for guest



43
44
45
46
# File 'lib/tinder/room.rb', line 43

def guest_invite_code
  load
  @active_token_value
end

#guest_urlObject

Get the url for guest access



29
30
31
32
33
34
35
# File 'lib/tinder/room.rb', line 29

def guest_url
  if guest_access_enabled?
    "http://#{@campfire.subdomain}.campfirenow.com/#{guest_invite_code}"
  else
    nil
  end
end

#join(force = false) ⇒ Object

Join the room. Pass true to join even if you’ve already joined.



14
15
16
# File 'lib/tinder/room.rb', line 14

def join(force = false)
  post 'join'
end

#leaveObject

Leave a room



19
20
21
# File 'lib/tinder/room.rb', line 19

def leave
  post 'leave'
end

#listen(interval = 5) ⇒ Object

Get and array of the messages that have been posted to the room. Each messages is a hash with:

  • :person: the display name of the person that posted the message

  • :message: the body of the message

  • :user_id: Campfire user id

  • :id: Campfire message id

    room.listen #=> [:message=>“I’m getting very sleepy”, :user_id=>“148583”, :id=>“16434003”]

Called without a block, listen will return an array of messages that have been posted since you joined. listen also takes an optional block, which then polls for new messages every 5 seconds and calls the block for each message.

room.listen do |m|
  room.speak "#{m[:person]}, Go away!" if m[:message] =~ /Java/i
end


116
117
118
119
120
121
122
123
124
125
126
# File 'lib/tinder/room.rb', line 116

def listen(interval = 5)
  require 'yajl/http_stream'

  auth = connection.default_options[:basic_auth]
  url = URI.parse("http://#{auth[:username]}:#{auth[:password]}@streaming.#{Campfire::HOST}/room/#{@id}/live.json")
  Yajl::HttpStream.get(url) do |message|
    { :id => message['id'],
      :user_id => message['user_id'],
      :message => message['body'] }
  end
end

#lockObject

Lock the room to prevent new users from entering and to disable logging



66
67
68
# File 'lib/tinder/room.rb', line 66

def lock
  post :lock
end

#paste(message) ⇒ Object



88
89
90
# File 'lib/tinder/room.rb', line 88

def paste(message)
  send_message(message, 'PasteMessage')
end

#ping(force = false) ⇒ Object

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/tinder/room.rb', line 75

def ping(force = false)
  raise NotImplementedError
end

#speak(message, options = {}) ⇒ Object

Post a new message to the chat room



84
85
86
# File 'lib/tinder/room.rb', line 84

def speak(message, options = {})
  send_message(message)
end

#toggle_guest_accessObject

Toggle guest access on or off

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/tinder/room.rb', line 24

def toggle_guest_access
  raise NotImplementedError
end

#topicObject

Get the current topic



60
61
62
63
# File 'lib/tinder/room.rb', line 60

def topic
  load
  @topic
end

#topic=(topic) ⇒ Object

Change the topic



55
56
57
# File 'lib/tinder/room.rb', line 55

def topic=(topic)
  connection.post("/room/#{@id}.json", :body => { :room => { :topic => name } })
end

#transcript(transcript_date) ⇒ Object

Get the transcript for the given date (Returns a hash in the same format as #listen)

room.transcript(room.available_transcripts.first)
#=> [{:message=>"foobar!",
      :user_id=>"99999",
      :person=>"Brandon",
      :id=>"18659245",
      :timestamp=>=>Tue May 05 07:15:00 -0700 2009}]

The timestamp slot will typically have a granularity of five minutes.



144
145
146
147
148
149
150
151
152
# File 'lib/tinder/room.rb', line 144

def transcript(transcript_date)
  url = "/room/#{@id}/transcript/#{transcript_date.to_date.strftime('%Y/%m/%d')}.json"
  connection.get(url)['messages'].map do |room|
    { :id => room['id'],
      :user_id => room['user_id'],
      :message => room['body'],
      :timestamp => Time.parse(room['created_at']) }
  end
end

#unlockObject

Unlock the room



71
72
73
# File 'lib/tinder/room.rb', line 71

def unlock
  post :unlock
end

#upload(filename) ⇒ Object



154
155
156
157
158
159
# File 'lib/tinder/room.rb', line 154

def upload(filename)
  File.open(filename, "rb") do |file|
    params = Multipart::MultipartPost.new('upload' => file)
    connection.post("/room/#{@id}/uploads.json", :body => params.query)
  end
end

#usersObject

Get the list of users currently chatting for this room



93
94
95
96
# File 'lib/tinder/room.rb', line 93

def users
  reload!
  @users
end