Sha256: 709d7357aa54cd647458f89a6ab4bef53f29b4d02faabb530d2fecc5c965b7f5
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
class Marty::RpcCall def self.marty_post(host, port, path, script, node, attrs, params) http = Net::HTTP.new(host, port) request = Net::HTTP::Post.new(path) request.add_field('Content-Type', 'application/json') request.body = { "script" => script, "node" => node, "attrs" => attrs.to_json, "params" => params.to_json, }.to_json begin resraw = http.request(request) rescue => e raise "#{e.message} during RPC call to #{host}:#{port}" end res = JSON.parse(resraw.body) raise res["error"] if res.is_a?(Hash) && !res["error"].blank? res end def self.xml_call(host, port, path, body, use_ssl) http = Net::HTTP.new(host, port) request = Net::HTTP::Post.new(path) http.use_ssl = use_ssl request.add_field('Content-Type', 'xml') request.add_field('Accept', 'xml') request.body = body begin resraw = http.request(request) if resraw.class != Net::HTTPOK raise "got #{resraw} during XML call" end rescue => e raise "#{e.message} during RPC call to #{host}:#{port}#{path}" end resraw.body end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
marty-1.0.11 | lib/marty/rpc_call.rb |
marty-1.0.10 | lib/marty/rpc_call.rb |