class Moneypenny::Connections::Campfire

Public Class Methods

new(subdomain, room_name, api_token) click to toggle source
# File lib/moneypenny/connections/campfire.rb, line 6
def initialize(subdomain, room_name, api_token)
  @subdomain = subdomain
  @room_name = room_name
  @api_token = api_token
end

Public Instance Methods

listen(&block) click to toggle source
# File lib/moneypenny/connections/campfire.rb, line 35
def listen(&block)
  begin
    room.listen do |message|
      begin
        block.call(message['body']) if message['user']['id'] != @id
      rescue Exception => exception
        puts exception.to_s
      end
    end
  rescue Tinder::ListenFailed
    reconnect
    retry
  end
end
reconnect() click to toggle source
# File lib/moneypenny/connections/campfire.rb, line 22
def reconnect
  @room = nil
  room
end
room() click to toggle source
# File lib/moneypenny/connections/campfire.rb, line 12
def room
  unless @room
    campfire = Tinder::Campfire.new @subdomain, :token => @api_token
    @id      = campfire.me['id']
    @room    = campfire.find_room_by_name @room_name
    raise 'Unknown Room' unless @room
  end
  @room
end
say(message) click to toggle source
# File lib/moneypenny/connections/campfire.rb, line 27
def say(message)
  if message.include?("\n")
    room.paste message
  else
    room.speak message
  end
end