Class: SFBATransitAPI::Client
- Inherits:
-
Object
- Object
- SFBATransitAPI::Client
- Defined in:
- lib/sfba_transit_api/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
- #get(method, options = {}) ⇒ Object
- #get_agencies ⇒ Object
- #get_next_departures_by_stop_code(stopcode) ⇒ Object
- #get_routes_for_agencies(agency_names) ⇒ Object
- #get_routes_for_agency(agency_name) ⇒ Object
- #get_stops_for_route(route_info) ⇒ Object
- #get_stops_for_routes(route_infos) ⇒ Object
-
#initialize(token, options = {}) ⇒ String
constructor
Initialize the client.
- #makeRouteIDF(route_info) ⇒ Object
Constructor Details
#initialize(token, options = {}) ⇒ String
Initialize the client
10 11 12 |
# File 'lib/sfba_transit_api/client.rb', line 10 def initialize(token, ={}) self.connection = Connection.new(token, ) end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
4 5 6 |
# File 'lib/sfba_transit_api/client.rb', line 4 def connection @connection end |
Instance Method Details
#get(method, options = {}) ⇒ Object
72 73 74 |
# File 'lib/sfba_transit_api/client.rb', line 72 def get(method, ={}) self.connection.get(method, ) end |
#get_agencies ⇒ Object
14 15 16 17 18 |
# File 'lib/sfba_transit_api/client.rb', line 14 def get_agencies response = get(:get_agencies) Agency.parse(response) end |
#get_next_departures_by_stop_code(stopcode) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/sfba_transit_api/client.rb', line 56 def get_next_departures_by_stop_code(stopcode) response = get(:get_next_departures_by_stop_code, stopcode: stopcode) Agency.parse(response).map do |agency| agency.routes.map do |route| route.stops end.flatten end.flatten.first end |
#get_routes_for_agencies(agency_names) ⇒ Object
26 27 28 29 30 |
# File 'lib/sfba_transit_api/client.rb', line 26 def get_routes_for_agencies(agency_names) response = get(:get_routes_for_agencies, {agency_names: agency_names.join("|")}) Agency.parse(response).map { |agency| agency.routes }.flatten end |
#get_routes_for_agency(agency_name) ⇒ Object
20 21 22 23 24 |
# File 'lib/sfba_transit_api/client.rb', line 20 def get_routes_for_agency(agency_name) response = get(:get_routes_for_agency, {agency_name: agency_name}) Agency.parse(response).map { |agency| agency.routes }.flatten end |
#get_stops_for_route(route_info) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sfba_transit_api/client.rb', line 32 def get_stops_for_route(route_info) route_idf = makeRouteIDF(route_info) response = get(:get_stops_for_route, {route_idf: route_idf}) Agency.parse(response).map do |agency| agency.routes.map do |route| route.stops end.flatten end.flatten end |
#get_stops_for_routes(route_infos) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sfba_transit_api/client.rb', line 44 def get_stops_for_routes(route_infos) route_idf = route_infos.map { |route_info| makeRouteIDF(route_info) }.join("|") response = get(:get_stops_for_routes, {route_idf: route_idf}) Agency.parse(response).map do |agency| agency.routes.map do |route| route.stops end.flatten end.flatten end |
#makeRouteIDF(route_info) ⇒ Object
66 67 68 69 70 |
# File 'lib/sfba_transit_api/client.rb', line 66 def makeRouteIDF(route_info) route_idf = "#{route_info[:agency_name]}~#{route_info[:route_code]}" route_idf += "~#{route_info[:route_direction_code]}" if route_info[:route_direction_code] route_idf end |