Namespace
- CLASS XMLRPC::Client::Proxy
Methods
- C
- D
- G
- M
- N
- P
- S
- T
- U
Included Modules
Constants
USER_AGENT | = | "XMLRPC::Client (Ruby #{RUBY_VERSION})" |
Attributes
[RW] | cookie | Cookie support |
[RW] | http_header_extra | add additional HTTP headers to the request |
[R] | http_last_response | makes last HTTP response accessible |
[R] | password | |
[R] | timeout | |
[R] | user |
Class Public methods
new(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil, user=nil, password=nil, use_ssl=nil, timeout=nil)
Link
Constructors ——————————————————————-
# File ../ruby/lib/xmlrpc/client.rb, line 295 def initialize(host=nil, path=nil, port=nil, proxy_host=nil, proxy_port=nil, user=nil, password=nil, use_ssl=nil, timeout=nil) @http_header_extra = nil @http_last_response = nil @cookie = nil @host = host || "localhost" @path = path || "/RPC2" @proxy_host = proxy_host @proxy_port = proxy_port @proxy_host ||= 'localhost' if @proxy_port != nil @proxy_port ||= 8080 if @proxy_host != nil @use_ssl = use_ssl || false @timeout = timeout || 30 if use_ssl require "net/https" @port = port || 443 else @port = port || 80 end @user, @password = user, password set_auth # convert ports to integers @port = @port.to_i if @port != nil @proxy_port = @proxy_port.to_i if @proxy_port != nil # HTTP object for synchronous calls Net::HTTP.version_1_2 @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port) @http.use_ssl = @use_ssl if @use_ssl @http.read_timeout = @timeout @http.open_timeout = @timeout @parser = nil @create = nil end
Instance Public methods
call(method, *args)
Link
Call methods ————————————————————–
call2(method, *args)
Link
call2_async(method, *args)
Link
call_async(method, *args)
Link
multicall(*methods)
Link
Multicall methods ————————————————————–
multicall2(*methods)
Link
multicall2_async(*methods)
Link
multicall_async(*methods)
Link
new2(uri, proxy=nil, timeout=nil)
Link
# File ../ruby/lib/xmlrpc/client.rb, line 340 def new2(uri, proxy=nil, timeout=nil) if match = /^([^:]+):\/\/(([^@]+)@)?([^\/]+)(\/.*)?$/.match(uri) proto = match[1] user, passwd = (match[3] || "").split(":") host, port = match[4].split(":") path = match[5] if proto != "http" and proto != "https" raise "Wrong protocol specified. Only http or https allowed!" end else raise "Wrong URI as parameter!" end proxy_host, proxy_port = (proxy || "").split(":") self.new(host, path, port, proxy_host, proxy_port, user, passwd, (proto == "https"), timeout) end
new3(hash={})
Link
# File ../ruby/lib/xmlrpc/client.rb, line 362 def new3(hash={}) # convert all keys into lowercase strings h = {} hash.each { |k,v| h[k.to_s.downcase] = v } self.new(h['host'], h['path'], h['port'], h['proxy_host'], h['proxy_port'], h['user'], h['password'], h['use_ssl'], h['timeout']) end
password=(new_password)
Link
proxy2(prefix=nil, *args)
Link
proxy2_async(prefix=nil, *args)
Link
proxy_async(prefix=nil, *args)
Link
timeout=(new_timeout)
Link
user=(new_user)
Link
Instance Private methods
do_rpc(request, async=false)
Link
# File ../ruby/lib/xmlrpc/client.rb, line 500 def do_rpc(request, async=false) header = { "User-Agent" => USER_AGENT, "Content-Type" => "text/xml; charset=utf-8", "Content-Length" => request.bytesize.to_s, "Connection" => (async ? "close" : "keep-alive") } header["Cookie"] = @cookie if @cookie header.update(@http_header_extra) if @http_header_extra if @auth != nil # add authorization header header["Authorization"] = @auth end resp = nil @http_last_response = nil if async # use a new HTTP object for each call Net::HTTP.version_1_2 http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port) http.use_ssl = @use_ssl if @use_ssl http.read_timeout = @timeout http.open_timeout = @timeout # post request http.start { resp = http.post2(@path, request, header) } else # reuse the HTTP object for each call => connection alive is possible # we must start connection explicitely first time so that http.request # does not assume that we don't want keepalive @http.start if not @http.started? # post request resp = @http.post2(@path, request, header) end @http_last_response = resp data = resp.body if resp.code == "401" # Authorization Required raise "Authorization failed.\nHTTP-Error: #{resp.code} #{resp.message}" elsif resp.code[0,1] != "2" raise "HTTP-Error: #{resp.code} #{resp.message}" end ct = parse_content_type(resp["Content-Type"]).first if ct != "text/xml" if ct == "text/html" raise "Wrong content-type (received '#{ct}' but expected 'text/xml'): \n#{data}" else raise "Wrong content-type (received '#{ct}' but expected 'text/xml')" end end expected = resp["Content-Length"] || "<unknown>" if data.nil? or data.bytesize == 0 raise "Wrong size. Was #{data.bytesize}, should be #{expected}" elsif expected != "<unknown>" and expected.to_i != data.bytesize and resp["Transfer-Encoding"].nil? raise "Wrong size. Was #{data.bytesize}, should be #{expected}" end set_cookies = resp.get_fields("Set-Cookie") if set_cookies and !set_cookies.empty? require 'webrick/cookie' @cookie = set_cookies.collect do |set_cookie| cookie = WEBrick::Cookie.parse_set_cookie(set_cookie) WEBrick::Cookie.new(cookie.name, cookie.value).to_s end.join("; ") end return data end
gen_multicall(methods=[], async=false)
Link
# File ../ruby/lib/xmlrpc/client.rb, line 580 def gen_multicall(methods=[], async=false) meth = :call2 meth = :call2_async if async ok, params = self.send(meth, "system.multicall", methods.collect {|m| {'methodName' => m[0], 'params' => m[1..-1]} } ) if ok params = params.collect do |param| if param.is_a? Array param[0] elsif param.is_a? Hash XMLRPC::FaultException.new(param["faultCode"], param["faultString"]) else raise "Wrong multicall return value" end end end return ok, params end