forked from github/github-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-services.rb
50 lines (45 loc) · 1.15 KB
/
github-services.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
$:.unshift *Dir["#{File.dirname(__FILE__)}/vendor/**/lib"]
# stdlib
require 'net/http'
require 'net/https'
require 'net/smtp'
require 'socket'
require 'timeout'
require 'xmlrpc/client'
require 'openssl'
require 'cgi'
#~ require 'date' # This is needed by the CIA service in ruby 1.8.7 or later
# vendor
require 'rack'
require 'sinatra'
require 'tinder'
require 'json'
require 'tinder'
require 'basecamp'
require 'tmail'
require 'xmpp4r'
require 'xmpp4r-simple'
require 'rubyforge'
module GitHub
def service(name)
Timeout.timeout(20) do
post "/#{name}/" do
data = JSON.parse(params[:data])
payload = JSON.parse(params[:payload])
yield data, payload
end
end
rescue Timeout::Error
end
def shorten_url(url)
Timeout::timeout(6) do
short = Net::HTTP.get("api.bit.ly", "/shorten?version=2.0.1&longUrl=#{url}&login=github&apiKey=R_261d14760f4938f0cda9bea984b212e4")
short = JSON.parse(short)
short["errorCode"].zero? ? short["results"][url]["shortUrl"] : url
end
rescue Timeout::Error
url
end
end
include GitHub
Dir["#{File.dirname(__FILE__)}/services/**/*.rb"].each { |service| load service }