Last active
September 15, 2020 14:46
Revisions
-
sosedoff revised this gist
Sep 18, 2013 . 2 changed files with 16 additions and 93 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,86 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,14 @@ 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) @@ -18,12 +18,13 @@ def connection(url) 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 @@ -37,6 +38,14 @@ def get(path, params={}) class Client include Request def countries get("/countries") end def cities(country=nil) get("/cities") end def restaurants(options={}) get("/restaurants", options) end -
sosedoff renamed this gist
May 3, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
sosedoff revised this gist
May 3, 2012 . 1 changed file with 86 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,86 @@ # Unofficial OpenTable API This project was created for one purpose — to make OpenTable data easily accesible to developers. No longer do you have to download XLS file, parse it and insert into your app's database. That shit is annoying. It is absolutely free and open for everyone to use. Created by @dan_sosedoff while drinking beers with @alwaysunday in Austin, TX. ## Usage - API Endpoint: http://opentable.heroku.com/api - Response Format: JSON ### Find restaurants ``` GET /api/restaurants ``` Parameters: (at least one required) - ```name``` - Name of the restaurant (optional) - ```address``` - Address line. Should not contain state or city or zip. (optional) - ```state``` - State code (ex.: IL) (optional) - ```city``` - City name (ex.: Chicago) (optional) - ```zip``` - Zipcode (ex: 60601) (optional) Returns response: ```json { "count": 521, "per_page": 25, "current_page": 1, "restaurants": [ ... ] } ``` ### Find single restaurant ``` GET /api/restaurants/:id ``` Returns a single restaurant record, see reference for details. ## Reference ```json { "id": 55807, "name": "ALC Steaks (Austin Land & Cattle)", "address": "1205 N. Lamar Blvd", "city": "Austin", "state": "TX", "area": "Austin", "postal_code": "78703", "country": "US", "phone": "5124721813", "token": "D70F992E", "reserve_url": "http://www.opentable.com/single.aspx?rid=55807", "mobile_reserve_url": "http://mobile.opentable.com/opentable/?restId=55807" } ``` To generate a proper reservation link just ref parameter with your affiliate ID to reserve_url or mobile_reserve_url ## Consuming API You can use simple client library i wrote — https://gist.github.com/2504683 Example: ```ruby api = OpenTable::Client.new # Find restaurants resp = api.restaurants(:city => "Chicago") # Process response resp['count'] # => records found resp['restaurants'] # => restaurant records # Fetch a single record api.restaurant(81169) ``` -
sosedoff created this gist
Apr 27, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ require 'faraday' require 'faraday_middleware' module OpenTable class Error < StandardError ; end module Request API_BASE = 'http://opentable.heroku.com' def connection(url) connection = Faraday.new(url) 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(API_BASE).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 restaurants(options={}) get("/restaurants", options) end def restaurant(id) get("/restaurants/#{id}") end end end