Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'oauth'
- require 'addressable/uri'
- require 'json'
- require 'rest-client'
- CONSUMER_KEY = ENV['YELP_CONSUMER_KEY']
- CONSUMER_SECRET = ENV['YELP_CONSUMER_SECRET']
- TOKEN = ENV['YELP_TOKEN']
- TOKEN_SECRET = ENV['YELP_TOKEN_SECRET']
- def yelp_search(keyword)
- # lat, lng = lat_lng
- api_host = 'api.yelp.com'
- 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=#{keyword}&location=Mountain%20View"
- url = Addressable::URI.new(
- :scheme => "https",
- :host => "api.yelp.com",
- :path => "/v2/search",
- :query_values => {
- :term => keyword,
- :location => "Mountain View"
- }).to_s
- ugly = access_token.get(path).body
- JSON.parse(ugly)
- # response = JSON.parse(ugly)
- # response
- # ["results"].map do |result|
- # result.select { |k, v| ["name", "vicinity", "reference"].include?(k) }
- # end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement