Current section

Files

Jump to
ndc_ex_sdk lib message soap_helper.ex
Raw

lib/message/soap_helper.ex

defmodule SoapHelper do
#require Tuple
defp get_attributes(method, config, type) do
method = if Enum.member?(config["attributes"], :all), do: :all
if (Enum.member?(config["attributes"], method) && Enum.member?(config["attributes"][method], type)) do
for {key, val} <- config["attributes"][method][type], into: %{}, do: {String.to_atom(key), val}
else
%{}
end
end
defp change_credential({header, nil, [{transaction, attr_trans, [{tc, nil, [{iden, t}, trace, script]}]}]}) do
{header, nil, [{transaction, attr_trans, [{tc, nil, [{iden, t}, trace, script]}]}]}
end
defp get_soap_header(nil), do: {}
defp get_soap_header(config) when is_binary(config), do: {String.to_atom(config), nil, nil}
defp get_soap_header(config), do: change_credential(config)
#defp fix_structure({type, attrs, [document]}), do: [{type, attrs, document}]
defp fix_structure({type, attrs, document}), do: [{type, attrs, document}]
def add_soap(xml, nil, method, options), do: xml
def add_soap(xml, config, method, options) do
#IO.inspect xml
if(!is_nil(config["soap_header"]) && !is_nil(options["wrapper"])) do
{
config["request_namespace"] <> ":Envelope",
get_attributes(method, config, "envelope"),
[
get_soap_header(config["soap_header"]),
{config["request_namespace"] <> ":Body", get_attributes(method, config, "body"), Tuple.to_list(xml)}
]
}
else
if(!is_nil(config["soap_header"])) do
{
config["request_namespace"] <> ":Envelope",
get_attributes(method, config, "envelope"),
[
get_soap_header(config["soap_header"]),
{
config["request_namespace"] <> ":Body",
get_attributes(method, config, "body"),
fix_structure(xml)
}
]
}
else
{
config["request_namespace"] <> ":Envelope",
get_attributes(method, config, "envelope"),
[
{
config["request_namespace"] <> ":Body",
get_attributes(method, config, "body"),
fix_structure(xml)
}
]
}
end
end
end
end