What’s that you say? Your Ruby applications are feeling a little empty and meaningless without Yelp data to make them shine? Well, consider your prayers answered because today we’re launching our official Ruby Gem for interfacing with the Yelp API!

Find the gem online now, and start using Yelp data in your Ruby applications with ease. Install the gem with bundle by adding ‘yelp’ to your Gemfile, or without a Gemfile by running gem install yelp.

Your first step on the road to Yelp data awesomeness is to register and get API keys from our developer site. Next, create a new client with your API keys and use that to make requests against the API.

client = Yelp::Client.new({ consumer_key: YOUR_CONSUMER_KEY,

                            consumer_secret: YOUR_CONSUMER_SECRET,

                            token: YOUR_TOKEN,

                            token_secret: YOUR_TOKEN_SECRET

                         })

Integrated into the gem is our Search API, which allows you to to find businesses based on the location provided and any search terms given:

results = client.search(‘San Francisco’, { term: ‘restaurants’ })

results.businesses # => [<…, name = ‘Gary Danko’, …>, <…, name = ‘Little Delhi’, …>, …]

Additionally, the Business API allows for retrieval of more information on specific businesses using the business id returned from the search:

business = client.business(‘gary-danko-san-francisco’)

business.name # => “Gary Danko”

business.rating # => 4.5

business.review_count # => 3701

Yelp + Rails

If you’re still fairly new to Ruby, want to work on a Rails app, and still want to use the gem then we’ve got a solution for you! We’ve created a small sample application to demo the gem and we’ve open sourced that as well.

All you need to do is create a file inside of config/initializers with a configuration block that sets your API keys:

inside config/initializers/yelp.rb

Yelp.client.configure do config

  config.consumer_key = YOUR_CONSUMER_KEY

  config.consumer_secret = YOUR_CONSUMER_SECRET

  config.token = YOUR_TOKEN

  config.token_secret = YOUR_TOKEN_SECRET

end

Here, we’re using a configuration block to tell Yelp what your API keys is. This will automatically create a client instance for you that lives inside of Yelp.client, allowing you to use your client instance over and over again in different places throughout your application.

Inside of your controller you can call Yelp.client with one of the API methods

inside app/controllers/home_controller.rb

class HomeController < ApplicationController

  # …

  def search

    parameters = { term: params[:term], limit: 16 }

    render json: Yelp.client.search(‘San Francisco’, parameters)

  end

end

And that’s it! You’re now able to use the Yelp gem throughout your Rails application. Using the gem should work similarly in other Ruby applications.

Head over to GitHub to check out the source code for the gem and the example app, and find more information on how to use the gem with the readme and documentation.

We can’t wait to see what you create. Learn more about the Yelp API at yelp.com/developers and make sure to share your apps with us!

Please remember to read and follow the Terms of Use and display requirements before creating your applications.

If you want to work with our API team (and why wouldn’t you?!), check out yelp.com/careers for available positions.

Back to blog