-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathhttp.rb
More file actions
40 lines (31 loc) · 1.07 KB
/
http.rb
File metadata and controls
40 lines (31 loc) · 1.07 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
module ClockworkSMS
# @author James Inman <james@mediaburst.co.uk>
# Wrapper around NET/HTTP
class HTTP
# Build a HTTP POST request.
# @param [string] url URL to POST to
# @param [string] data Body of the POST request.
# @param [boolean] use_ssl Whether to use SSL when making the request.
# @return [string] XML data
def self.post url, data = '', use_ssl = true
if use_ssl
uri = URI.parse "https://#{url}"
req = Net::HTTP::Post.new( uri.path )
socket = Net::HTTP.new( uri.host, uri.port )
socket.use_ssl = true
socket.verify_mode = OpenSSL::SSL::VERIFY_PEER
else
uri = URI.parse "http://#{url}"
req = Net::HTTP::Post.new( uri.path )
socket = Net::HTTP.new( uri.host, uri.port )
end
req.content_type = "text/xml"
req.body = data
req.add_field "User-Agent", "ClockworkSMS Ruby Wrapper/#{ClockworkSMS::VERSION}"
response = socket.start do |http|
http.request( req )
end
response
end
end
end