Rails newbie here - I’m grabbing information from an API and it “looks” like I’m getting a hash back, but I can’t address any of the keys in the hash as I’m getting an error that an object NIL doesn’t take a key.
class AtisController < ApplicationController
def index
@atis_information_list = []
airport_list = ["KBDL", "KBOS", "KPVD", "KACK", "KALB", "KGON", "KOXC", "KPWM", "KATL"]
airport_list.each do |airport|
@atis_information_list.push(pull_atis(airport))
end
#@atis_information_list = pull_atis(airport_list)
end
private
def request_api(url)
response = Excon.get(
url
)
return nil if response.status != 200
parsed_JSON = JSON.parse(response.body)[0]
return parsed_JSON
end
def pull_atis(airport)
request_api(
"http://datis.clowd.io/api/#{CGI.escape(airport)}"
)
end
end```
<h1>ATIS Info</h1>
<h4> <%= DateTime.now.utc %></h4>
<p>
<% @atis_information_list.each do |atis| %>
<%= atis %>
<% end %>
</p>
Here is the rendered output right now. I’d like to just have the “airport” and “datis” information so I can render into an HTML table.
{“airport”=>“KBDL”, “type”=>“combined”, “code”=>“N”, “datis”=>“BDL ATIS INFO N 2151Z. 34004KT 10SM FEW200 FEW250 05/M09 A3026 (THREE ZERO TWO SIX). RUNWAYS 24 AND 33 IN USE, EXPECT ILS APPROACH. NOTAMS… 5G NOTAMS IN EFFECT FOR BDL CNTC FLIGHT SERVICE FREQUENCIES. READ BACK ALL HOLD SHORT INSTRUCTIONS AND ASSIGNED ALT. HIWAS INFO FOR CT GEO AREA AVAILABLE ON FSS. …ADVS YOU HAVE INFO N.”}