Ruby gem to wrap the MBTA v2 "realtime" API
- The API object will return Ruby objects (POROs) representing the responses from the MBTA API.
- Those objects will have public methods to return both the raw JSON they were created from, and a simplified JSON serialization; this latter form can be overloaded to customize JSON delivered to hypothetical clients.
- The objects will also support additional related queries back to the API (e.g. a query for nearby stations will return Station objects, which could in turn be queried for lines and/or next trains.)
- As a commuter rail commuter, I'll start with commuter rail, then subways, then buses
- The data structure of the wrapper will map as closely to the data returned by the API as practical.
- When the data returned from the API maps to native Ruby data structures, it will be parsed as such (e.g. when the API returns timestamps, the wrapper will parse to Ruby DateTime objects).
- API object: initialization, connections, API key setup
- Stub API method calls
- Build out stubs
- Map objects needed
- Iterate over objects to map attributes and methods needed
Add this line to your application's Gemfile:
gem 'mbta-api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mbta-api
It will help me learn the T's API in better detail. Making the API easier to work with should motivate additional developer work in making this data useful for more commuters. And while I can't make my train be on time more often (unfortunately), I can make its data more widely usable.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
.
You will almost certainly benefit from checking out the API Documentation.
In planning this gem, I found (at least) three other similar attempts to provide a wrappers for the MBTA data API, all of which included interesting ideas which are in some way incorporated in mbta-api.
Bug reports and pull requests are welcome on GitHub at https://github.com/pjmorse/mbta-api.