Advertisement
Guest User

Untitled

a guest
Apr 18th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. require 'oauth'
  2. require 'addressable/uri'
  3. require 'json'
  4. require 'rest-client'
  5.  
  6. CONSUMER_KEY = ENV['YELP_CONSUMER_KEY']
  7. CONSUMER_SECRET = ENV['YELP_CONSUMER_SECRET']
  8. TOKEN = ENV['YELP_TOKEN']
  9. TOKEN_SECRET = ENV['YELP_TOKEN_SECRET']
  10.  
  11. def yelp_search(keyword)
  12. # lat, lng = lat_lng
  13.  
  14. api_host = 'api.yelp.com'
  15. consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, {:site => "http://#{api_host}"})
  16. access_token = OAuth::AccessToken.new(consumer, TOKEN, TOKEN_SECRET)
  17. path = "/v2/search?term=#{keyword}&location=Mountain%20View"
  18.  
  19. url = Addressable::URI.new(
  20. :scheme => "https",
  21. :host => "api.yelp.com",
  22. :path => "/v2/search",
  23. :query_values => {
  24. :term => keyword,
  25. :location => "Mountain View"
  26. }).to_s
  27.  
  28. ugly = access_token.get(path).body
  29. JSON.parse(ugly)
  30. # response = JSON.parse(ugly)
  31. # response
  32. # ["results"].map do |result|
  33. # result.select { |k, v| ["name", "vicinity", "reference"].include?(k) }
  34. # end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement