0

I am attempting to use the Yelp API in my Rails app but am having trouble doing so. I'm following the documentation here (https://github.com/Yelp/yelp-api/blob/master/v2/ruby/example.rb) but keep getting an error. Below is the code I'm using in the controller:

    require 'rubygems'
    require 'oauth'

    consumer_key = 'private'
    consumer_secret = 'private'
    token = 'private'
    token_secret = 'private-private'

    api_host = 'api.yelp.com'
    @places = Place.all
    consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {:site => "http://#{api_host}"})
    access_token = OAuth::AccessToken.new(consumer, token, token_secret)
    path = "/v2/search?term=restaurants&location=new%20york"
    p access_token.get(path).body

The error I keep getting is:

cannot load such file -- oauth

I have gem 'omniauth' in my Gemfile and have run bundle install (as well as restarted the server) but still get this error...any ideas on how to troubleshoot this?

Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.12'
gem 'dynamic_form', '1.1.4'
gem 'sqlite3'
gem 'devise', '2.1.0rc'
gem 'bootstrap-sass', '2.1'
gem 'omniauth'
gem 'httparty'

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :test, :development do
    gem 'rspec-rails', '~> 2.11'
end

group :test do
    gem 'capybara', '1.1.2'
end
sharataka
  • 5,014
  • 20
  • 65
  • 125

2 Answers2

0

according to the omniauth documentation, you should be requiring 'omniauth', not 'oauth'

omnikron
  • 2,211
  • 17
  • 30
  • When I do this, I get an error saying uninitialized constant PlacesController::OAuth. It seems the Yelp API is dated (2 years old) and still says OAuth instead of Omniauth. How would I fix this? – sharataka Mar 26 '13 at 13:32
  • right, because the guide you are looking at is for a different gem with a different API (API here meaning 'set of gem classes and methods etc.', NOT the yelp API - the yelp API doesn't care what gem you are using, their example is just old). You need to read the omniauth documentation I linked to above for how to make an API call with the omniauth gem which is somewhat beyond the scope of this question and has been answered [elsewhere](http://stackoverflow.com/questions/5675029/how-to-use-omniauth-to-make-authenticated-calls-to-services). – omnikron Mar 26 '13 at 13:40
  • Here is an omniauth strategy for Yelp API.It needs some more testing though,Browse through the source code and that may help you. https://github.com/dhaneshnm/omniauth-yelp/. – Dhanesh Neela Mana Dec 02 '13 at 15:16
-1

You should run:

sudo gem install oauth

Or add gem oauth in the Gemfile.

Jan Gerlinger
  • 7,361
  • 1
  • 44
  • 52