Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

OpenTable API Client - Visit http://opentable.herokuapp.com for details

View opentable_client.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
require "faraday"
require "faraday_middleware"
 
module OpenTable
class Error < StandardError ; end
 
module Request
API_BASE = "http://opentable.herokuapp.com"
 
def connection
connection = Faraday.new(API_BASE) do |c|
c.use(Faraday::Request::UrlEncoded)
c.use(Faraday::Response::ParseJson)
c.adapter(Faraday.default_adapter)
end
end
 
def request(method, path, params={}, raw=false)
headers = {'Accept' => 'application/json'}
path = "/api#{path}"
 
response = connection.send(method, path, params) do |request|
request.url(path, params)
end
 
if [404, 403, 400].include?(response.status)
raise OpenTable::Error, response.body["error"]
end
 
raw ? response : response.body
end
 
def get(path, params={})
request(:get, path, params)
end
end
 
class Client
include Request
 
def countries
get("/countries")
end
 
def cities(country=nil)
get("/cities")
end
 
def restaurants(options={})
get("/restaurants", options)
end
 
def restaurant(id)
get("/restaurants/#{id}")
end
end
end

is there is any api for open table for getting reviews of business .

Can you please create a jsonp service, so we can just consume with javascript api without running into cross domain request issues? All you'd have to do is accept an additional argument, 'jsoncallback' and then wrap the data in a function call whose name is specified in that argument, returning content type application/javascript. No need for proxies.

Example jquery usage:
$.getJSON("[YOURDOMAIN]/opentable.php?jsoncallback=?",{name:place.name,zip:zip}).done(function(data) {
if(data.count>0) {
//process data
}
});

opentable.php file:

<?php
header("Content-Type: application/javascript");
echo $_REQUEST['jsoncallback']."(";
readfile("http://opentable.heroku.com/api/restaurants?name=".rawurlencode($_REQUEST['name'])."&zip=".rawurlencode($_REQUEST['zip']));
echo ");";
?>

I'm currently using this, but having to host the php file on my server.

Is there any search available?
send back all restaurants with 7pm reservation for a given date

I presume this is just a search API. There are no API's for locking a slot or making a reservation. Correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.