Class: WMATA::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/client.rb', line 7

def initialize(api_key)
    @options = {query: {api_key: api_key} }
end

Instance Method Details

#next_trains(stations = 'A06') ⇒ Object



11
12
13
14
# File 'lib/client.rb', line 11

def next_trains(stations='A06')
  response = self.class.get("/StationPrediction.svc/json/GetPrediction/#{stations}", @options)
  JSON.parse(response.body)["Trains"]
end

#train_incidentsObject



29
30
31
32
# File 'lib/client.rb', line 29

def train_incidents
  response = self.class.get("/Incidents.svc/json/Incidents", @options)
  JSON.parse(response.body)["Incidents"]
end

#train_path(from, to) ⇒ Object



22
23
24
25
26
27
# File 'lib/client.rb', line 22

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

#train_stations(line = 'RD', formated = true) ⇒ Object



16
17
18
19
20
# File 'lib/client.rb', line 16

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