1.0.0 • Published 3 years ago

opentable-widget v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

OpenTable Widget

This package dynamically generates a OpenTable reservation widget link and an OpenTable restaurant ID's (rid) using a restaurant's name and location.

OpenTable provides a to generate OpenTable widgets. Unfortunately there is no official API to dynamically generate widgets. OpenTable does not have any public API's.

Usage

npm install opentable-widget
const getWidget = require('opentable-widget');

const restaurantName = 'terroni'
const location = {
  city: 'toronto',
  state: 'ontario',
  zip: 'M6J 1E8',
}
const options = {
  theme: 'button',
  language: 'en-CA',
}

getWidget(restaurantName, location, options).then(widget => {
  const scriptElement = document.getElementById('some-script-element');
  scriptElement.type = 'text/javascript'
  scriptElement.src = widget.source;

  console.log(widget.source);
});

// '//www.opentable.ca/widget/reservation/loader?rid=112426&type=multi&theme=standard&iframe=true&domain=ca&lang=en-CA&newtab=false&ot_source=Restaurant%20website'

Widget Source

The widget source, as OpenTable intends, should be set as the src property of a script tag in order to be rendered.

Location

Since this package scrapes raw HTML from multiple sources to find rid's and widgets, there is a chance for incorrect data to be returned if not all search parameters are given.

The package needs the restaurant name at a minimum. Providing additional location data of the restaurant such as city, state, country and zip codes will improve the accuracy of the widget returned.

If all location parameters city, state, country and zip are provided, it is guaranteed that the widget returned is correct.

Options

An optional options parameter can be passed to getWidget to alter the type of widget returned.

Possible options: theme, language, iframe, newtab Defaults: 'standard', 'en-US', true, false

Check the OpenTable widget website for the values available for each of these options.