Skip to content

Instantly share code, notes, and snippets.

@Haumer
Created July 18, 2020 19:21
Show Gist options
  • Select an option

  • Save Haumer/e0e740b08c4ee580dd7d0fcbca540505 to your computer and use it in GitHub Desktop.

Select an option

Save Haumer/e0e740b08c4ee580dd7d0fcbca540505 to your computer and use it in GitHub Desktop.
require "open-uri"
require "json"
class TflApi
def initialize
@url = "https://api.tfl.gov.uk/line/mode/tube,overground,dlr,tflrail/status".freeze
retrieve_data
end
def retrieve_data
opened = open(@url).read
@data = JSON.parse(opened)
end
def extract_lines
@data.map do |line|
newHash = {
name: line["name"],
reason: line["lineStatuses"].first["reason"],
severity: line["lineStatuses"].first["statusSeverityDescription"]
}
end
end
end
# class Line
# def initialize
# end
# end
tfl = TflApi.new
p tfl.extract_lines.first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment