Weebo
Weebo is an XML-RPC parser/formatter for Elixir, with full data-type support.
Weebo can be combined with GenServer, Phoenix, HTTPoison (and others!) to create fully-featured XML-RPC clients & servers.
request = Weebo.parse("<?xml version=\"1.0\"?><methodCall><methodName>math.sum</methodName><params><param><value><int>1</int></value></param><param><value><int>2</int></value></param><param><value><int>3</int></value></param></params></methodCall>")
#=> %Weebo.Request{method: "math.sum", params: [1, 2, 3]}
sum = Enum.sum(request.params)
response = %Weebo.Response{error: nil, params: [sum]}
Weebo.format(response)
#=> "<?xml version=\"1.0\"?><methodResponse><params><param><value><int>6</int></value></param></params></methodResponse>"
Data Type Mapping
All the following data-types are supported, and will be automatically serialized in format/1
and parse/1
:
XMLRPC | Elixir |
---|---|
<string> |
Bitstring - "string" |
<int> |
Integer - 8 |
<boolean> |
Boolean - true false |
<double> |
Float - 6.3 |
<array> |
List - [1, 2, 3] |
<struct> |
Map - %{key: "value"} |
<dateTime.iso8601> |
Tuple - {{2015, 6, 7}, {16, 24, 18}} |
<nil> |
Nil atom - nil |
In addition, the following extra data-types are supported only in parse/1
:
XMLRPC | Elixir |
---|---|
<base64> |
Bitstring - "string" (will decode the base64 first) |
<i4> |
Integer - 8 |
Summary↑
format(subject) | Formats |
parse(string) | Parses an XML-RPC string into |
Types ↑
xml_tree :: {atom, [String.t | tuple]}
Tuple-representation of an XML element. This is the format Weebo uses internally during parsing/formatting.
The first element is an atom that represents the XML node's name, and the second element is a list of child elements that follow the same pattern.
Example
The following bit of XML:
<value>
<string>Hello</string>
</value>
Would be represented as:
{:value, [{:string, ["Hello"]}]}
Functions
Specs:
- format(Weebo.Request.t | Weebo.Response.t) :: String.t
Formats %Weebo.Response
and %Weebo.Request
into an XML-RPC string.
Examples
Weebo.format(%Weebo.Response{error: nil, params: [%{success: true}]})
#=> "<?xml version=\"1.0\"?><methodResponse><params><param><value><struct><member><name>success</name><value><boolean>1</boolean></value></member></struct></value></param></params></methodResponse>"
Specs:
- parse(String.t) :: Weebo.Request.t | Weebo.Response.t
Parses an XML-RPC string into %Weebo.Request
and %Weebo.Response
.
Examples
Weebo.parse("<?xml version=\"1.0\"?><methodCall><methodName>math.sum</methodName><params><param><value><int>1</int></value></param><param><value><int>4</int></value></param></params></methodCall>")
#=> %Weebo.Request{method: "math.sum", params: [1, 4]}