class RakeNotifier::Ikachan::Client

Public Class Methods

new(url, channel) click to toggle source
# File lib/rake_notifier/ikachan.rb, line 39
def initialize(url, channel)
  @url     = url
  @channel = channel
end

Public Instance Methods

join() click to toggle source
# File lib/rake_notifier/ikachan.rb, line 44
def join
  request('/join', {channel: @channel})
end
notice(message) click to toggle source
# File lib/rake_notifier/ikachan.rb, line 48
def notice(message)
  join
  request('/notice', {channel: @channel, message: message})
end
request(path, params) click to toggle source
# File lib/rake_notifier/ikachan.rb, line 59
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
    $stderr.puts "#{e.class} #{e.message}"
  end
end
uri_for(path = nil) click to toggle source
# File lib/rake_notifier/ikachan.rb, line 53
def uri_for(path = nil)
  uri = URI.parse("#{@url}/#{path}")
  uri.path = Pathname.new(uri.path).cleanpath.to_s
  uri
end