Skip to content

Instantly share code, notes, and snippets.

@allcentury
Created July 8, 2014 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allcentury/3c899bbf8033be08c615 to your computer and use it in GitHub Desktop.
Save allcentury/3c899bbf8033be08c615 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'csv'
require 'json'
require 'pry'
require 'oauth'
consumer_key = ''
consumer_secret = ''
token = ''
token_secret = ''
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)
search_term = "flowers%20candy"
location = "massachusetts"
path = "/v2/search?term=#{search_term}&location=#{location}"
response = JSON.parse(access_token.get(path).body)
resp = []
offset = 0
limit = 20
while !(response["businesses"].empty?)
path = "/v2/search?term=#{search_term}&location=#{location}&limit=#{limit}&offset=#{offset}"
response = JSON.parse(access_token.get(path).body)
resp << response
offset += limit
sleep(1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment