module Takosan
Constants
- VERSION
Public Instance Methods
logger()
click to toggle source
# File lib/takosan.rb, line 37 def logger @@_logger ||= if defined?(Rails.logger) Rails.logger else Logger.new($stderr) end end
privmsg(message, **options)
click to toggle source
# File lib/takosan.rb, line 11 def privmsg(message, **options) request('/privmsg', options.merge({ 'channel' => @@channel, 'message' => message, 'name' => @@name, 'icon' => @@icon })) end
request(path, params)
click to toggle source
# File lib/takosan.rb, line 21 def request(path, params) begin uri = uri_for(path) http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = http.read_timeout = 10 req = Net::HTTP::Post.new(uri.path) req.form_data = params http.request(req) rescue StandardError, TimeoutError => e logger.warn("#{e.class} #{e.message}") end end
uri_for(path = nil)
click to toggle source
# File lib/takosan.rb, line 15 def uri_for(path = nil) uri = URI.parse("#{@@url}/#{path}") uri.path = Pathname.new(uri.path).cleanpath.to_s uri end