-
Notifications
You must be signed in to change notification settings - Fork 3
/
campfire.rb
41 lines (36 loc) · 999 Bytes
/
campfire.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Campfire
KEYS = ["campfire_subdomain", "campfire_token", "campfire_room"]
def self.notify_mocks_created(mocks, url)
if use?
room = find_room
mock = mocks.first
mocks_text = mocks.size == 1 ? "a new mock" : "#{mocks.size} new mocks"
room.speak "#{mock.author.name} posted #{mocks_text}:"
room.speak mock.image.url
room.speak url
end
# Handle invalid token and invalid subdomain errors respectively.
rescue Tinder::AuthenticationFailed, NoMethodError
# Do nothing.
end
def self.find_room
campfire = Tinder::Campfire.new settings["campfire_subdomain"], self.options
campfire.find_room_by_name(settings["campfire_room"])
end
def self.options
{
:ssl => true,
:token => settings["campfire_token"]
}
end
def self.settings
settings = {}
KEYS.each do |key|
settings[key] = Setting[key]
end
settings
end
def self.use?
!self.settings["campfire_subdomain"].blank?
end
end