Class: Github

Inherits:
Mongrel::HttpHandler
  • Object
show all
Defined in:
lib/irc_cat/http_server/github.rb

Instance Method Summary collapse

Constructor Details

#initialize(bot, config) ⇒ Github

Returns a new instance of Github.



6
# File 'lib/irc_cat/http_server/github.rb', line 6

def initialize(bot, config); @bot = bot; @config = config; puts "Github enabled"; end

Instance Method Details

#process(request, response) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/irc_cat/http_server/github.rb', line 8

def process(request, response)
  response.start(200) do |head,out|
    head["Content-Type"] = "text/plain"
    post = CGI.parse(request.body.read)
    json = JSON.parse(post['payload'].join(','))
    json['commits'].each do |c|
      @bot.say(@config['irc']['channel'],"[#{json['repository']['name']}] New commit by #{c.last['author']['name']} : #{c.last['message'].gsub(/\n(.*)/, '...')} - #{c.last['url']}")
    end
  end
end