elixir-book/weather/lib/weather/gov_weather.ex

26 lines
616 B
Elixir

defmodule Weather.Gov do
def url(airport) do
"https://w1.weather.gov/xml/current_obs/#{airport}.xml"
end
def current_observerations(airport) do
url(airport)
|> HTTPoison.get(["Accept": "application/xml"])
|> process_result()
end
def process_result({:ok, %HTTPoison.Response{status_code: 200, body: body}}) do
body
end
def process_result({:ok, %HTTPoison.Response{status_code: status_code}}) do
IO.puts("Wrong status code: #{status_code}")
System.halt(status_code)
end
def process_result({:error, reason}) do
IO.inspect(reason)
System.halt(2)
end
end