class Chateau::Api
Attributes
configuration[R]
Public Class Methods
new(configuration)
click to toggle source
# File lib/chateau/api.rb, line 7 def initialize(configuration) @configuration = configuration end
Public Instance Methods
all_rooms()
click to toggle source
# File lib/chateau/api.rb, line 11 def all_rooms with_exception_handling([]) do hipchat_api.rooms_list['rooms'] || [] end end
room_exists?(room_name)
click to toggle source
# File lib/chateau/api.rb, line 21 def room_exists?(room_name) rooms_matching(room_name).any? end
room_id_for(room_name)
click to toggle source
# File lib/chateau/api.rb, line 25 def room_id_for(room_name) room_list = rooms_matching(room_name) room_list.first['room_id'] unless room_list.empty? end
rooms_matching(room_name)
click to toggle source
# File lib/chateau/api.rb, line 17 def rooms_matching(room_name) all_rooms.select{ |room_object| room_object['name'].include?(room_name) } end
send_message(room_id, from, text, options = {})
click to toggle source
# File lib/chateau/api.rb, line 30 def send_message(room_id, from, text, options = {}) with_exception_handling(nil) do hipchat_api.rooms_message(room_id, from, text) end end
Private Instance Methods
hipchat_api()
click to toggle source
# File lib/chateau/api.rb, line 49 def hipchat_api @hipchat_api ||= ::HipChat::API.new(configuration.api_key).tap do |h| h.set_timeout(configuration.timeout) end end
with_exception_handling(default_return_value) { || ... }
click to toggle source
# File lib/chateau/api.rb, line 38 def with_exception_handling(default_return_value, &block) begin yield rescue => e $stderr.puts "Unable to access HipChat API" $stderr.puts e.message $stderr.puts e.backtrace.join("\n") default_return_value end end