Project

go_transit

0.0
The project is in a healthy, maintained state
Ruby Interface for the Go Transit API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
= 0.17

Runtime

 Project Readme

Go Transit API Ruby Wrapper

Tests Maintainability Test Coverage

This gem is intended to make working with the Go Transit API easier and more consistent. The API endpoints were re-created as close to the API spec wherever possible, but some exceptions do exist. Reference the Go Transit API documenation for details on available fields.

This gem does not parse any of the GTFS feeds. For those I recommend using a gem dedicated to parsing GTFS Real Time feeds since it is a stardized data type.

API Keys

You can get a Go Transit API key here http://api.openmetrolinx.com/OpenDataAPI/Help/Registration/en.

Usage

Import go_transit and set your API key.

require "go_transit"

GoTransit.configure do |config|
  config.api_key = "YOUR_API_KEY"
end

This gem exposes the Go Transit API endpoints and hydrates objects related to the returned data.

Stop

Method Reference
GoTransit::Stop.all Link
GoTransit::Stop.details(stop_code: <string>) Link
GoTransit::Stop.next_service(stop_code: <string>) Link
GoTransit::Stop.destinations(stop_code: <string>, from_time: <string>, to_time: <string>) Link

Service Update

Method Reference
GoTransit::ServiceUpdate.service_alerts Link
GoTransit::ServiceUpdate.information_alerts Link
GoTransit::ServiceUpdate.marketing_alerts Link
GoTransit::ServiceUpdate.union_departures Link
GoTransit::ServiceUpdate.service_guarantee(trip_number: <string>, operational_day: <string>) Link
GoTransit::ServiceUpdate::Exceptions.train Link
GoTransit::ServiceUpdate::Exceptions.bus Link
GoTransit::ServiceUpdate::Exceptions.all Link

Service At Glance

Method Reference
GoTransit::ServiceAtAGlance.buses Link
GoTransit::ServiceAtAGlance.trains Link
GoTransit::ServiceAtAGlance.upx Link

Schedule

Method Reference
GoTransit::Schedule.journey(date: <Date>, from_stop_code: <string>, to_stop_code: <string>, start_time: <string>, max_journey: <int>) Link
GoTransit::Schedule.line(date: <Date>, line_code: <string>, line_direction: <string>) Link
GoTransit::Schedule::AllLines.all(date: <Date>) Link
GoTransit::Schedule::Line.stop(date: <Date>, line_code: <string>, line_direction: <string>) Link
GoTransit::Schedule.trip(date: <Date>, trip_number: <string>) Link

Fare

Method Reference
GoTransit::Fare.get(from_stop_code: <string>, to_stop_code: <string>, operational_day: <nil|string>) Link or Link

Dates & Times

All dates & times returned from the GO Transit API are in the America/Toronto timezone. All date and time fields have an additional method to convert into UTC. For example departure_time_utc on a stop will return the regular departure_time converted unto UTC.

Missing Test Data

At the time of development I was unable to get test data for the following endpoints. Some of these seem like they are restricted access endpoints and my key is unable to fetch any data. I'm not sure if the others are caused by API issues. These endpoints should work assuming the documenation is correct, but the lack of data means testing was not possible. If you are able to get data for these endpoints please open a PR and submit it, it would greatly help development.

  • GET api/V1/ServiceataGlance/UPX/All - 204 No Content
  • GET api/V1/ServiceUpdate/ServiceGuarantee/{TripNumber}/{OperationalDay} - 204 No Content
  • GET api/V1/ServiceUpdate/MarketingAlert/All - 204 No Content
  • GET api/V1/Fleet/Consist/All - 403 Forbidden
  • GET api/V1/Fleet/Consist/Engine/{EngineNumber} - 403 Forbidden

Changing the API base url

In some cases you may want to change the base go transit API url. You can use the custom_base_url config to set one:

GoTransit.configure do |config|
  config.custom_base_url = "https://example.com"
end