lib/god/contacts/campfire.rb in resurrected_god-0.14.0 vs lib/god/contacts/campfire.rb in resurrected_god-1.0.0
- old
+ new
@@ -16,12 +16,13 @@
end
module Marshmallow
class Connection
def initialize(options)
- raise "Required option :subdomain not set." unless options[:subdomain]
- raise "Required option :token not set." unless options[:token]
+ raise 'Required option :subdomain not set.' unless options[:subdomain]
+ raise 'Required option :token not set.' unless options[:token]
+
@options = options
end
def base_url
scheme = @options[:ssl] ? 'https' : 'http'
@@ -38,16 +39,16 @@
req = Net::HTTP::Get.new(url.path)
req.basic_auth(@options[:token], 'X')
res = http.request(req)
case res
- when Net::HTTPSuccess
- rooms = JSON.parse(res.body)
- room = rooms['rooms'].select { |x| x['name'] == room }
- rooms.empty? ? nil : room.first['id']
- else
- raise res.error!
+ when Net::HTTPSuccess
+ rooms = JSON.parse(res.body)
+ room = rooms['rooms'].select { |x| x['name'] == room }
+ rooms.empty? ? nil : room.first['id']
+ else
+ raise res.error!
end
end
def speak(room, message)
room_id = find_room_id_by_name(room)
@@ -63,31 +64,29 @@
req.set_content_type('application/json')
req.body = { 'message' => { 'body' => message } }.to_json
res = http.request(req)
case res
- when Net::HTTPSuccess
- true
- else
- raise res.error!
+ when Net::HTTPSuccess
+ true
+ else
+ raise res.error!
end
end
end
end
module God
module Contacts
-
class Campfire < Contact
class << self
- attr_accessor :subdomain, :token, :room, :ssl
- attr_accessor :format
+ attr_accessor :subdomain, :token, :room, :ssl, :format
end
self.ssl = false
- self.format = lambda do |message, time, priority, category, host|
+ self.format = lambda do |message, time, _priority, _category, host|
"[#{time.strftime('%H:%M:%S')}] #{host} - #{message}"
end
attr_accessor :subdomain, :token, :room, :ssl
@@ -101,21 +100,20 @@
def notify(message, time, priority, category, host)
body = Campfire.format.call(message, time, priority, category, host)
conn = Marshmallow::Connection.new(
- :subdomain => arg(:subdomain),
- :token => arg(:token),
- :ssl => arg(:ssl)
+ subdomain: arg(:subdomain),
+ token: arg(:token),
+ ssl: arg(:ssl)
)
conn.speak(arg(:room), body)
self.info = "notified campfire: #{arg(:subdomain)}"
rescue Object => e
applog(nil, :info, "failed to notify campfire: #{e.message}")
applog(nil, :debug, e.backtrace.join("\n"))
end
end
-
end
end