Class: SamtrafikenAPI::Resrobot

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

Overview

Samtrafiken ResRobot API.

Documentation: http://www.trafiklab.se/api/resrobot-sok-resa

Examples:

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

See Also:

  • resrobot_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.rb', line 19

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

Instance Method Details

#find_location(query) ⇒ Hash

Endpoint: FindLocation

Documentation: http://www.trafiklab.se/api/resrobot/findlocation

Parameters:

  • query (Hash)

    query keys and values.

Returns:

  • (Hash)

    a hash containing the returned data.



97
98
99
100
# File 'lib/samtrafiken_api/resrobot.rb', line 97

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

#producer_listHash

Endpoint: ProducerList

Documentation: http://www.trafiklab.se/api/resrobot/producerlist

Returns:

  • (Hash)

    a hash containing the returned data.



76
77
78
79
# File 'lib/samtrafiken_api/resrobot.rb', line 76

def producer_list
  @response = self.class.get('/ProducerList.json')
  return read_response @response
end

#search(query) ⇒ Hash

Endpoint: Search

Documentation: http://www.trafiklab.se/api/resrobot/search

Parameters:

  • query (Hash)

    query keys and values.

Returns:

  • (Hash)

    a hash containing the returned data.



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

def search query
  @response = self.class.get('/Search.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.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

#stations_in_zone(query) ⇒ Hash

Endpoint: StationsInZone

Documentation: http://www.trafiklab.se/api/resrobot/stationsinzone

Parameters:

  • query (Hash)

    query keys and values.

Returns:

  • (Hash)

    a hash containing the returned data.



56
57
58
59
# File 'lib/samtrafiken_api/resrobot.rb', line 56

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

#time_table_periodHash

Endpoint: TimeTablePeriod

Documentation: http://www.trafiklab.se/api/resrobot/timetableperiod

Returns:

  • (Hash)

    a hash containing the returned data.



66
67
68
69
# File 'lib/samtrafiken_api/resrobot.rb', line 66

def time_table_period
  @response = self.class.get('/TimeTablePeriod.json')
  return read_response @response
end

#transport_mode_listHash

Endpoint: TransportModeList

Documentation: http://www.trafiklab.se/api/resrobot/transportmodelist

Returns:

  • (Hash)

    a hash containing the returned data.



86
87
88
89
# File 'lib/samtrafiken_api/resrobot.rb', line 86

def transport_mode_list
  @response = self.class.get('/TransportModeList.json')
  return read_response @response
end