41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/jazor.rb', line 41
def self.method_missing(method, uri, ={}, data={})
uri_parsed = URI.parse(uri)
http = Net::HTTP.new(uri_parsed.host, port=uri_parsed.port)
if uri_parsed.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
request_uri = uri_parsed.query ? "#{uri_parsed.path}?#{uri_parsed.query}" : uri_parsed.path
request = Net::HTTP.const_get(method.to_s.capitalize).new(request_uri)
.each { |k,v| request.add_field(k, v) }
request.set_form_data(data)
LOG.debug("#{self} #{method.to_s.upcase}: uri=#{File.join(uri_parsed.host, request_uri)} headers=#{.to_json} data=#{data.to_json}")
response = http.request(request)
LOG.debug("#{self} result: code=#{response.code} body=%s" % response.body.gsub("\r", " ").gsub("\n", " "))
response
end
|