defmodule NDCEx do require HTTPotion require Logger def request(method, params) do NDCEx.Message.Base.build_document(method, params[:ndc]) |> rest_call_with_message(params[:rest]) end def rest_call_with_message(xml, rest_config) do case HTTPotion.post(rest_config[:url], [body: xml, headers: rest_config[:headers], timeout: 30000 ]) do %HTTPotion.Response{body: body, headers: _headers, status_code: 200 } -> {:ok, scan body} %HTTPotion.Response{body: body, headers: _headers, status_code: _status_code } -> {:error, scan body} %HTTPotion.Response{status_code: 404} -> {:error, error_message("Request does not exist")} _ -> {:error, error_message("Unknown Error")} end end def scan(message) do #{ response, _ } = message |> String.to_char_list |> :xmerl_scan.string #response message end defp error_message(message) do scan "#{message}" end def get_mix_config(key) when is_atom(key) do Application.get_env(:ndc_ex_sdk, key) end end