Module: XML::XMLRPC::Builder
- Defined in:
- lib/xml/libxml/xmlrpc/builder.rb
Overview
Class to build XML-RPC responses and calls.
Example:
XML::XMLRPC::Builder.foo(1,2,3) # generates xml for method call
# 'foo' with arguments of int 1, 2
# and 3
XML::XMLRPC::Builder.response(1,2,3) # builds a response with args
# 1,2,3
# builds a fault response with faultCode 0 and faultString "Foo"
XML::XMLRPC::Builder.fault_response(2, "Foo")
# builds a call called 'fault_response'
XML::XMLRPC::Builder.call('fault_response', 1, 2, 3)
Notes:
* To build a Base64 object, check out the XML::XMLRPC::Builder::Base64 class.
* Date (and all other) objects must inherit directly from class
Date or be the class themselves, DateTime is an example of direct
inheritance of Date. Time (which inherits from Object) will NOT
work.
* All responses are encoded UTF-8. Be sure your strings, etc are
UTF-8 before passing them into this module.
Defined Under Namespace
Modules: Value Classes: Base64, Error
Class Method Summary collapse
-
.call(methodname, *args) ⇒ Object
Builds the appropriate XML for a methodCall.
-
.debug ⇒ Object
gets the debugging state.
-
.debug=(x) ⇒ Object
toggles builder debugging.
-
.fault_response(faultCode, faultMessage) ⇒ Object
Builds a fault response.
-
.method_missing(*args) ⇒ Object
Just calls #call, your method name will be the first argument and will be passed to call properly.
-
.response(*args) ⇒ Object
Builds a response.
Class Method Details
.call(methodname, *args) ⇒ Object
Builds the appropriate XML for a methodCall.
Takes a methodname and a series of arguments.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/xml/libxml/xmlrpc/builder.rb', line 51 def self.call(methodname, *args) methodname = methodname.to_s output = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" output += "<methodCall><methodName>#{methodname}</methodName>" output += Value.generate(*args) output += "</methodCall>" self.debug_output output return output end |
.debug ⇒ Object
gets the debugging state
41 42 43 |
# File 'lib/xml/libxml/xmlrpc/builder.rb', line 41 def self.debug @debug end |
.debug=(x) ⇒ Object
toggles builder debugging
36 37 38 |
# File 'lib/xml/libxml/xmlrpc/builder.rb', line 36 def self.debug=(x) @debug = x end |
.fault_response(faultCode, faultMessage) ⇒ Object
Builds a fault response. Takes a faultCode (integer) and a faultMessage (string).
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/xml/libxml/xmlrpc/builder.rb', line 81 def self.fault_response(faultCode, faultMessage) output = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" output += "<methodResponse>" output += "<fault><value><struct>" output += "<member><name>faultCode</name><value><int>#{faultCode}</int></value></member>" output += "<member><name>faultString</name><value><string>#{faultMessage}</string></value></member>" output += "</struct></value></fault>" output += "</methodResponse>" self.debug_output output return output end |
.method_missing(*args) ⇒ Object
Just calls #call, your method name will be the first argument and will be passed to call properly.
99 100 101 |
# File 'lib/xml/libxml/xmlrpc/builder.rb', line 99 def self.method_missing(*args) self.call(*args) end |
.response(*args) ⇒ Object
Builds a response. Takes a series of response arguments.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/xml/libxml/xmlrpc/builder.rb', line 67 def self.response(*args) output = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" output += "<methodResponse>" output += Value.generate(*args) output += "</methodResponse>" self.debug_output output return output end |