Class: Moneypenny::Connections::Campfire

Inherits:
Object
  • Object
show all
Defined in:
lib/moneypenny/connections/campfire.rb

Instance Method Summary collapse

Constructor Details

#initialize(subdomain, room_name, api_token) ⇒ Campfire

Returns a new instance of Campfire.



6
7
8
9
10
# 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

Instance Method Details

#listen(&block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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

#reconnectObject



22
23
24
25
# File 'lib/moneypenny/connections/campfire.rb', line 22

def reconnect
  @room = nil
  room
end

#roomObject



12
13
14
15
16
17
18
19
20
# 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) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/moneypenny/connections/campfire.rb', line 27

def say(message)
  if message.include?("\n")
    room.paste message
  else
    room.speak message
  end
end