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]}]}]}, credential) do #IO.inspect(Enum.to_list(t)); {header, nil, [{transaction, attr_trans, [{tc, nil, [{iden, t}, trace, script]}]}]} #{transaction, attr_trans, [tc, nil, [{iden, Tuple.append(t, agt: credential)}, trace, script]]} end defp get_soap_header(config, credential) when config == nil, do: {} defp get_soap_header(config, credential), do: change_credential(config, credential) #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, credential) when config == nil, do: xml def add_soap(xml, config, method, credential) when config != nil do if(!is_nil(config[:soap_header])) do {:"#{config[:request_namespace]}:Envelope", get_attributes(method, config, :envelope),[get_soap_header(config[:soap_header], credential), {:"#{config[:request_namespace]}:Body", get_attributes(method, config, :body), Tuple.to_list(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