Current section

Files

Jump to
ndc_ex_sdk lib ndc_ex.ex
Raw

lib/ndc_ex.ex

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] 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(doc) do
{ response, _ } = doc |> String.to_char_list |> :xmerl_scan.string
response
end
defp error_message(message) do
scan "<error><message>#{message}</message></error>"
end
def get_mix_config(key) when is_atom(key) do
Application.get_env(:ndc_ex_sdk, key)
end
end