Ruby wrapper for the EMT API
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Gem Version Build Status Coverage Status security

EmtApi is a Ruby wrapper around the Madrid EMT API which provides an easier and more ruby-like access to the information related to Madrid city urban buses.


Add this line to your application's Gemfile:

gem 'emt_api'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install emt_api

The EMT API requires you to have a idClient and passKey (called EMT_CLIENT and EMT_SECRET respectively from now on) to authenticate your requests. You can get these freely by filling this form.

emt_api expects them to be accessible as environment variables. To do this on Mac OS X you'll have to edit your .bash_profile and add the following lines:

# ~/.bash_profile
export EMT_CLIENT="your idClient"
export EMT_SECRET="your passKey"


Get basic info about bus lines

require 'emt_api'

line = EmtApi::Line.find(1)           # => "001"
line.label        # => "1"
line.date_first   # => #<Date: 2017-01-09 ((2457763j,0s,0n),+0s,2299161j)>
line.date_end     # => #<Date: 2999-12-31 ((2816787j,0s,0n),+0s,2299161j)>
line.origin       # => "Cristo Rey"
line.destination  # => "Prosperidad"

all_lines = EmtApi::Line.all

all_lines.size      # => 208  # => "001"
# etc.

Get basic info about bus stops

require 'emt_api'

stop = EmtApi::Stop.find(1)         # => 1       # => "Av. Valdemarin - Altair"
stop.lines      # => ["", "161/1/1"]
stop.wifi?      # => false
stop.latitude   # => 40.47004454502
stop.longitude  # => -3.782887713069

all_stops = EmtApi::Stop.all

all_stops.size      # => 4677  # => 1
# etc.


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. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at


Powered by EMT Madrid - Terms & Conditions

The gem is available as open source under the terms of the MIT License.