Skip to content

Instantly share code, notes, and snippets.

@bennacer860
Last active August 29, 2015 14:14
Show Gist options
  • Save bennacer860/da38fd5e596a5f686d76 to your computer and use it in GitHub Desktop.
Save bennacer860/da38fd5e596a5f686d76 to your computer and use it in GitHub Desktop.
require 'httparty'
class Wmata
include HTTParty
base_uri "https://api.wmata.com"
#debug_output $stdout
def initialize(api_key="aad8b98dbe614b879c472e88a621d2d0")
@options = {query: {api_key: api_key} }
end
def next_trains(stations='A06')
response = self.class.get("/StationPrediction.svc/json/GetPrediction/#{stations}", @options)
JSON.parse(response.body)["Trains"]
end
def train_stations(line='RD', formated=true)
@options[:query][:LineCode]=line
response = self.class.get("/Rail.svc/json/jStations", @options)
JSON.parse(response.body)["Stations"]
end
def train_path(from,to)
@options[:query][:FromStationCode] = from
@options[:query][:ToStationCode] = to
response = self.class.get("/Rail.svc/json/jPath", @options)
JSON.parse(response.body)["Path"]
end
def train_incidents
response = self.class.get("/Incidents.svc/json/Incidents", @options)
JSON.parse(response.body)["Incidents"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment