Class: Raibo::CampfireConnection
- Inherits:
-
Object
- Object
- Raibo::CampfireConnection
- Defined in:
- lib/raibo/campfire_connection.rb
Instance Attribute Summary collapse
-
#opened ⇒ Object
Returns the value of attribute opened.
-
#room_name ⇒ Object
Returns the value of attribute room_name.
-
#subdomain ⇒ Object
Returns the value of attribute subdomain.
-
#token ⇒ Object
Returns the value of attribute token.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #close ⇒ Object
- #construct_message(msg) ⇒ Object
- #handle_lines ⇒ Object
-
#initialize(subdomain, opts = {}) ⇒ CampfireConnection
constructor
A new instance of CampfireConnection.
- #open ⇒ Object
- #say(*msgs) ⇒ Object
Constructor Details
#initialize(subdomain, opts = {}) ⇒ CampfireConnection
Returns a new instance of CampfireConnection.
7 8 9 10 11 12 13 |
# File 'lib/raibo/campfire_connection.rb', line 7 def initialize(subdomain, opts={}) @subdomain = subdomain @token = opts[:token] @room_name = opts[:room] || 'Raibo' @verbose = !!opts[:verbose] @opened = false end |
Instance Attribute Details
#opened ⇒ Object
Returns the value of attribute opened.
5 6 7 |
# File 'lib/raibo/campfire_connection.rb', line 5 def opened @opened end |
#room_name ⇒ Object
Returns the value of attribute room_name.
5 6 7 |
# File 'lib/raibo/campfire_connection.rb', line 5 def room_name @room_name end |
#subdomain ⇒ Object
Returns the value of attribute subdomain.
5 6 7 |
# File 'lib/raibo/campfire_connection.rb', line 5 def subdomain @subdomain end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/raibo/campfire_connection.rb', line 5 def token @token end |
#verbose ⇒ Object
Returns the value of attribute verbose.
5 6 7 |
# File 'lib/raibo/campfire_connection.rb', line 5 def verbose @verbose end |
Instance Method Details
#close ⇒ Object
28 29 30 31 |
# File 'lib/raibo/campfire_connection.rb', line 28 def close @room.leave if @room rescue end |
#construct_message(msg) ⇒ Object
69 70 71 |
# File 'lib/raibo/campfire_connection.rb', line 69 def (msg) Raibo::Message.new(:message, msg[:user][:name], @room_name, msg[:body]) end |
#handle_lines ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/raibo/campfire_connection.rb', line 33 def handle_lines @room.listen do |m| # Message Format: # :body: the body of the message # :user: Campfire user, which is itself a hash, of: # :id: User id # :name: User name # :email_address: Email address # :admin: Boolean admin flag # :created_at: User creation timestamp # :type: User type (e.g. Member) # :id: Campfire message id # :type: Campfire message type # :room_id: Campfire room id # :created_at: Message creation timestamp puts "--> #{m}" if @verbose if m[:type] == 'TextMessage' and m[:user][:name] != @name yield m end end rescue => e puts "Error:\n #{e.backtrace.join(' ')}" if @verbose retry end |
#open ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/raibo/campfire_connection.rb', line 15 def open if @token.nil? or @token == '' raise "token is a required field for Campfire" end @campfire = Tinder::Campfire.new @subdomain, :token => @token @room = @campfire.find_room_by_name @room_name @name = @campfire.me['name'] puts "Connected to room #{@room_name}" if @verbose @opened = true end |
#say(*msgs) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/raibo/campfire_connection.rb', line 59 def say(*msgs) m = msgs.join("\n") if msgs.size == 1 @room.speak m else @room.paste m end puts "<-- #{m}" if @verbose end |