-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathim_modul.rb
More file actions
46 lines (42 loc) · 1.03 KB
/
im_modul.rb
File metadata and controls
46 lines (42 loc) · 1.03 KB
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
module IM
class Kayac
HOST = 'im.kayac.com'
def initialize(to, params={})
if to.nil?
raise ArgumentError
else
@to = to
end
@id = params[:id]
@pwd = params[:password]
@sig = params[:sig]
end
def notify(msg,han)
if !@sig.nil?
sig = Digest::SHA1.hexdigest(msg + @sig)
data = 'message=%s&handler=%s;sig=%s' % [u(msg),u(han),sig]
elsif !@pwd.nil?
data = 'message=%s&password=%s;handler=%s' % [u(msg), u(@pwd),u(han)]
else
data = 'message=%s;handler=%s' % [u(msg),u(han)]
end
data << '&id=%s' % [u(@id)] unless @id.nil?
header = {
'Host' => HOST,
'Content-Type' => 'application/x-www-form-urlencoded',
'Content-length' => data.size.to_s,
}
path = '/api/post/%s' % [@to]
Net::HTTP.version_1_2
Net::HTTP.start(HOST, 80) do |http|
http.post(path, data, header)
end
end
private
def u(str)
str.to_s do
'%%%02X' % $&.unpack("C").first
end
end
end
end