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
if !is_nil(config[:attributes][:all]) do
method = :all;
end
if !is_nil(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(config) when config == 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, config, method, options) when config == nil, do: xml
def add_soap(xml, config, method, options) when config != nil 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