-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_nabaztag.rb
53 lines (40 loc) · 1.05 KB
/
github_nabaztag.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'rubygems'
require 'net/http'
require 'yaml'
require 'json'
require 'sinatra'
CONF = YAML.load_file('config.yml')
class GithubNabaztag
API_URL = 'http://api.nabaztag.com/vl/FR/api.jsp'
def initialize(payload)
payload = JSON.parse(payload)
@repository = payload['repository']
@commits = payload['commits']
send
end
def message
msg = "Repository #{@repository['name']} received new commits. "
msg += @commits.collect { |commit| "#{commit['author']['name']} committed: #{commit['message']}"}.join('. ')
msg += "."
msg
end
def send
uri = URI.parse(API_URL)
params = {
'sn' => CONF['key'],
'token' => CONF['token'],
'voice' => 'UK-Shirley',
'tts' => URI.encode(message)
}
response = Net::HTTP.start(uri.host, uri.port) { |http|
http.request(Net::HTTP::Get.new(uri.path + "?" + params.collect {|k,v| "#{k.to_s}=#{v}" }.join('&')))
}
response.body
end
end
get '/' do
'Hello World!'
end
post '/' do
GithubNabaztag.new(params[:payload])
end