Created
July 18, 2020 19:21
-
-
Save Haumer/e0e740b08c4ee580dd7d0fcbca540505 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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