Proximal.Rpc (proximal v0.2.3)
XML-RPC let us to create method calls and responses. It works in both directions, encoding/decoding requests and encoding/decoding responses.
Summary
Functions
Decode params passed to the RPC system. It's performing the opposite as
encode_params/1
does.
Decode a response from RPC. This performs the complementary of
encode_response/1
.
Encode a response. Providing a data, it's generating the XML-RPC valid response.
Functions
Decode params passed to the RPC system. It's performing the opposite as
encode_params/1
does.
Decode a response from RPC. This performs the complementary of
encode_response/1
.
Examples:
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value>Manuel</value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", ["Manuel"]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><int>100</int></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [100]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><base64>AAAA</base64></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [<<0, 0, 0>>]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><nil/></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [nil]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><double>10.5</double></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [10.5]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><dateTime.iso8601>2019-03-31T02:30:00Z</dateTime.iso8601></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [~N[2019-03-31 02:30:00]]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><dateTime.iso8601>2019-03-31T02:30:00Z</dateTime.iso8601></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [~N[2019-03-31 02:30:00]]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><struct><member><name>name</name><value><string>Manuel</string></value></member></struct></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [%{"name" => "Manuel"}]}
iex> import Proximal.Xmlel, only: [sigil_x: 2]
iex> ~x[<methodCall><methodName>io_puts</methodName><params><param><value><array><data><value><boolean>1</boolean></value><value><boolean>0</boolean></value><value><int>10</int></value></data></array></value></param></params></methodCall><methodName>io_puts</methodName>]
iex> |> Proximal.Rpc.decode_request()
{"io_puts", [[true, false, 10]]}
Encode a response. Providing a data, it's generating the XML-RPC valid response.
Example:
iex> Proximal.Rpc.encode_response(100)
iex> |> to_string()
"<methodResponse><params><param><value><int>100</int></value></param></params></methodResponse>"
iex> Proximal.Rpc.encode_response(<<0, 0, 0>>)
iex> |> to_string()
"<methodResponse><params><param><value><base64>AAAA</base64></value></param></params></methodResponse>"
iex> Proximal.Rpc.encode_response(nil)
iex> |> to_string()
"<methodResponse><params><param><value><nil/></value></param></params></methodResponse>"
iex> Proximal.Rpc.encode_response(10.5)
iex> |> to_string()
"<methodResponse><params><param><value><double>10.5</double></value></param></params></methodResponse>"
iex> Proximal.Rpc.encode_response(DateTime.new!(~D[2019-03-31], ~T[02:30:00]))
iex> |> to_string()
"<methodResponse><params><param><value><dateTime.iso8601>2019-03-31T02:30:00Z</dateTime.iso8601></value></param></params></methodResponse>"
iex> Proximal.Rpc.encode_response(NaiveDateTime.new!(~D[2019-03-31], ~T[02:30:00]))
iex> |> to_string()
"<methodResponse><params><param><value><dateTime.iso8601>2019-03-31T02:30:00Z</dateTime.iso8601></value></param></params></methodResponse>"
iex> Proximal.Rpc.encode_response(%{"name" => "Manuel"})
iex> |> to_string()
"<methodResponse><params><param><value><struct><member><name>name</name><value><string>Manuel</string></value></member></struct></value></param></params></methodResponse>"
iex> Proximal.Rpc.encode_response([true, false, 10])
iex> |> to_string()
"<methodResponse><params><param><value><array><data><value><boolean>1</boolean></value><value><boolean>0</boolean></value><value><int>10</int></value></data></array></value></param></params></methodResponse>"