Project

mbta-rt

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby API Wrapper around MBTA realtime v2 api.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 5.7.0
~> 1.3.0
~> 3.1.0
~> 10.0
~> 2.9.3
~> 1.21.0

Runtime

 Project Readme

Mbta

Build Status Coverage Status Gem Version

The mbta released a realtime api about a year ago. I have some interest in building a hyperlocal app around public transportation and have this created this api wrapper.

Installation

Add this line to your application's Gemfile:

gem 'mbta-rt'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mbta

Usage

This is very much a WIP. The API is stable and won't be changing much.

In a configuration file add the following:

require 'mbta'
Mbta.api_key = '<INSERT API_KEY>'
Mbta.format = 'json' # acceptable inputs are json, jsonp, and xml.

Once you are properly setup, then it is just a matter of knowing what data you want to get after.

Mbta::RoutesRequest.all #=> returns a jsonified string of all requests

I have built a wrapper around each of the endpoints for their v2 realtime api. Here is what the footprint looks like for each request:

Mbta::RoutesRequest.all
Mbta::RoutesReqest.by_stop(stop_id)

Mbta::PredictionsRequest.by_stop(stop_id, options_hash)
Mbta::PredictionsRequest.by_route(route_id, options_hash)
Mbta::PredictionsRequest.by_trip(trip_id, options_hash)

Mbta::ScheduleRequest.by_stop(stop_id, options_hash)
Mbta::ScheduleRequest.by_route(route_id, options_hash)
Mbta::ScheduleRequest.by_trip(trip_id, options_hash)

Mbta::StopsRequest.by_route(route_id)
Mbta::StopsRequest.by_location(lat, long)

Mbta::VehiclesRequest.by_route(route_id, options_hash)
Mbta::VehiclesRequest.by_trip(tripe_id, options_hash)

I will need to write up some documentation about what each options_hash can take, but peeking at the documentation of their endpoint may help guide you.

Left ToDo

  1. Encapsulate errors from the various endpoints into real Error objects
  2. Instead of just returning raw json, consider returning Ruby objects. Maybe a boolean stating return json or ruby objects.
  3. Build out ruby models with attrs for the various pieces of the json response.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/mbta/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request