Class: SamtrafikenAPI::ResrobotStops

Inherits:
APIBase
  • Object
show all
Defined in:
lib/samtrafiken_api/resrobot_stops.rb

Overview

Samtrafiken ResRobot Stolptidtabeller API.

Documentation: http://www.trafiklab.se/api/resrobot-stolptidtabeller

Examples:

@rr = SamtrafikenAPI::ResrobotStops.new('MY-API-KEY')
@rr.set_mode(:realtime)
query = {key: "value"}
result = @rr.get_departures query 
#=> {...}

See Also:

  • resrobot_stops_spec.rb for details of how to use this class.

Instance Attribute Summary

Attributes inherited from APIBase

#response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APIBase

#initialize, #read_response

Constructor Details

This class inherits a constructor from SamtrafikenAPI::APIBase

Class Method Details

.urisObject

debug_output $stdout



19
20
21
22
23
24
# File 'lib/samtrafiken_api/resrobot_stops.rb', line 19

def self.uris
  {
    timetable: 'https://api.trafiklab.se/samtrafiken/resrobotstops',
    realtime: 'https://api.trafiklab.se/samtrafiken/resrobotstopssuper'
  }
end

Instance Method Details

#get_departures(query) ⇒ Hash

Parameters:

  • query (Hash)

    query keys and values.

Returns:

  • (Hash)

    a hash containing the returned data.



45
46
47
48
# File 'lib/samtrafiken_api/resrobot_stops.rb', line 45

def get_departures query
  @response = self.class.get('/GetDepartures.json', :query => query)
  return read_response @response
end

#set_mode(mode) ⇒ Object

Set the API mode to use either real time or time table data.

Parameters:

  • mode (Symbol)

    either :timetable or :realtime.



31
32
33
34
35
36
37
# File 'lib/samtrafiken_api/resrobot_stops.rb', line 31

def set_mode mode
  if self.class.uris.has_key? mode
    self.class.base_uri self.class.uris[mode]
  else
    raise "Invalid API mode."
  end
end