diff --git a/lib/ndc_ex.ex b/lib/ndc_ex.ex
index 14ecbbb..c58ddbc 100644
--- a/lib/ndc_ex.ex
+++ b/lib/ndc_ex.ex
@@ -1,7 +1,6 @@
defmodule NDCEx do
require HTTPotion
require Logger
- import SweetXml
@acceptable_ndc_methods [ AirShopping: ["AirShoppingRQ", "AirShoppingRS"],
FlightPrice: ["FlightPriceRQ", "FlightPriceRS"],
SeatAvailability: ["SeatAvailabilityRQ", "SeatAvailabilityRS"],
@@ -15,39 +14,35 @@ defmodule NDCEx do
]
def request(method, params) do
- try do
[request_name, response_name] = @acceptable_ndc_methods[method]
:ndc
|> get_mix_config
|> NDCEx.Message.Base.build_document(request_name, params)
|> rest_call_with_message(get_mix_config(:rest))
- rescue
- e -> {:error, error_message(e.message)}
- end
end
def rest_call_with_message(xml, rest_config) do
Logger.debug xml
- try do
- case HTTPotion.post rest_config[:url], [body: xml, headers: rest_config[:headers]] do
- %HTTPotion.Response{body: body, headers: _headers, status_code: 200 } ->
- {:ok, Exmerl.parse(body)}
- %HTTPotion.Response{body: body, headers: _headers, status_code: _status_code } ->
- {:error, Exmerl.parse(body)}
- apply(NDCEx.Response.Error, :convert, [body])
- %HTTPotion.Response{status_code: 404} ->
- {:error, error_message("Request does not exist")}
- _ ->
- {:error, error_message("Unknown Error")}
- end
- rescue
- e -> {:error, error_message(e.message)}
+ case HTTPotion.post rest_config[:url], [body: xml, headers: rest_config[:headers]] 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
- Exmerl.parse "#{message}"
+ scan "#{message}"
end
def get_mix_config(key) when is_atom(key) do