deliveratorjs v1.1.3
Deliveratorjs - a server for Mustard powered food ordering websites
Deliveratorjs is a node.js module for easily inserting Mustard powered menus into web pages.
Installation
Install from npm with
npm install deliveratorjsQuick Start
Deliverator requires node.js, express (npm install -g express), and git.
You can create a basic express server using deliverator with these five simple steps:
Create an express server with deliverator in the folder you want to use with
express myOrdrinApp cd myOrdrinApp npm install npm install deliveratorjsCopy the contents of
node-modules/deliveratorjs/exampleintoviewsIn
app.js, below the module dependencies, add the lines:var options = { "apiKey" : "your API Key", "servers" : "test" } var deliverator = require("deliveratorjs")(options);In
app.js, add the following to the middlewares aboveapp.router:app.use(deliverator.html.addHtml); app.use(deliverator.injector);In
app.js, add the following lines afterapp.get('/', routes.index);:app.get('/search', deliverator.html.getDefaultRestaurantListMiddleware("search", "/menu")); app.get('/menu/:rid', deliverator.html.getDefaultMenuMiddleware("menu"));
The index page of this server should have a form to search for restaurants near an address. If you fill in the form with a location we support, you will get a list of restaurats that will deliver to you and if you click on a restaurant's name you will get the menu for that restaurant.
Usage
Initialization
Deliverator takes the same initialization arguments as the node Ordr.in wrapper, with the additional argument path, which is a url path that deliverator will use that will not conflict with anything else and defaults to "/ordrin". For example,
var options = {
apiKey = "YOUR-ORDRIN-API-KEY",
restaurantUrl: "r-test.ordr.in",
userUrl: "u-test.ordr.in",
orderUrl: "o-test.ordr.in",
path: "/deliverator"
};
var deliverator = require("deliveratorjs")(options);Rendering
The main purpose of Deliverator is to render pages as necessary to use them with Mustard. This includes properly linking to Mustard JavaScript and CSS and rendering pages server side. This rendering can be done at various levels of granularity, and uses external templates that can be edited. These functions are all members of deliverator.html.
Page Pieces
The most granular method of creating Deliverator pages is the functions to render chunks of pages to strings of HTML.
Head Data
Several functions render stuff that goes in the <head> tag. All of these include a <link> tag to load the Mustard CSS file and JavaScript code to load the Mustard JavaScript file. They also include JavaScript code to put data into the ordrin global variable, which Mustard uses for rendering and functionality.
Restaurant Head
getSimpleRestaurantsHead( data )
getRestaurantsHead( data )The first function puts into ordrin the data needed to request and render the list of restaurants. This should be used if you want Mustard to request the restaurant array and render it to the page client side.
The second sets that data and also inserts the array of restaurant data. This should be used if you want to do the data request and possibly render the page on the server before returning the response.
Both functions take in a single object as its argument. The first function has fewer properties, and the ones that are not necessary for it will be noted. Below are the expected properties:
address: The address for food to be delivered to. Should be an instance ofordrinAPI.addressor equivalent.menu_uri: The base url for menu requests. Mustard assumes that requests tomenuUri/ridwill get responses with restaurant menus.deliveryTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.render: A boolean that determines whether Mustard will render the restaurant list HTML client side. Should be true if the server will not render that HTML in the response.getRestaurantsHeadONLY.data: An object containing arestaurantkey mapping to an array of restaurant objects, as the Delivery List API Call returns.getRestaurantsHeadONLY.head_init: Dictionary of variable names & variable values that may be added to the JavaScript snippet that initializes the necessary Mustard variables.getRestaurantsHeadONLY.isMobile: A boolean for whether or not the rendered pages will be for mobile view or not. If they are, the mustard style file will not be applied to the pages.getRestaurantsHeadONLY.
Menu Head
getSimpleHead( data )
getHead( data )The first function puts into ordrin the data needed to request and render the menu. This should be used if you want Mustard to request the menu data and render the menu to the page client side.
The second sets that data and also inserts the menu data. This should be used if you want to do the data request and possibly render the page on the server before returning the response.
Both functions take in a single object as its argument. The first function has fewer properties, and the ones that are not necessary for it will be noted. Below are the expected properties:
rid: The restaurant IDaddress: The address for food to be delivered to. Should be an instance ofordrinAPI.addressor equivalent.deliveryTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.data: An object containing amenukey mapping to a menu array, as the Restaurant Details API Call returns.getHeadONLY.render: A boolean that determines whether Mustard will render the menu HTML client side. Should be true if the server will not render that HTML in the response.getHeadONLY.details: An object containing the details about a restaurant, as returned by the Restaurant Details API Call.getHeadONLY.head_init: Dictionary of variable names & variable values that may be added to the JavaScript snippet that initializes the necessary Mustard variables.getHeadONLY.isMobile: A boolean for whether or not the rendered pages will be for mobile view or not. If they are, the mustard style file will not be applied to the pages.confirmUrl: A string that contains the (relative) path to the confirm page of the app.
Confirm Head
getSimpleConfirmHead( data )
getConfirmHead( data )The first function puts into ordrin the data needed to request and render a confirm page. This should be used if you want Mustard to parse the tray string and render its contents to the page client side.
The second parses that data and also renders it. This should be used if you want to do the data request and possibly render the page on the server before returning the response.
Both functions take in a single object as its argument. The first function has fewer properties, and the ones that are not necessary for it will be noted. Below are the expected properties:
address: The address for food to be delivered to. Should be an instance ofordrinAPI.addressor equivalent.rid: The restaurant IDdeliveryTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.render: A boolean that determines whether Mustard will render the restaurant list HTML client side. Should be true if the server will not render that HTML in the response.getConfirmHeadONLY.data: An object containing arestaurantkey mapping to an array of restaurant objects, as the Delivery List API Call returns.getConfirmHeadONLY.tray: A string denoting the tray of the order, in the format documented in the Order API Call.tip: A string denoting the tip for the order. In cents.
Address Head
getAddressHead( data )Compared to all other heads, the address head has only a single function, since the address page doesn't rely on Mustard code.
The function takes in a single object as its argument.
isMobile: A boolean for whether or not the rendered pages will be for mobile view or not. If they are, the mustard style file will not be applied to the pages.extraCss: A string of CSS code inside<style>tags, which can optionally be injected into the head of the page.
Rendered HTML
These functions return HTML that belongs in the body of their corresponding pages.
getRestaurants(data)
getMenu(data)Keys for data in getRestaurants:
restaurants: An array of restaurant objects as returned by the Delivery List API Call.
In addition, each restaurant object should have a params key containing an object with the following keys:
menu_uri: The base url for menu requests. Mustard assumes that requests tomenuUri/ridwill get responses with restaurant menus.dateTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.addr: The street address for deliveryaddr2: The second line of the street address (optional)city: The city for deliverystate: The state for deliveryzip: The zip code for deliveryphone: The phone number for delivery.
Keys for data in getMenu:
menu: A menu data array as returned in the Restaurant Details API Call.address: The address for food to be delivered to. Should be an instance ofordrinAPI.addressor equivalent.deliveryTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.
Whole Pages
A less granular method of creating Deliverator pages is a set of functions that send responses containing complete rendered pages.
Restaurant List Pages
renderRestaurantsSimple(res, params, dateTime)
renderRestaurants( res, params, callback )The first renders the page to pass as little data as possible into the response, so the client will have to request the restaurant data list and render the HTML.
The second renders the page with the data and possibly the rendered HTML, so the page will display quickly and the client will do as little work as possible to display the page.
Arguments:
res: The response variable that would be passed to an express middleware.params.template: The name of a template to render into. This template should render the keyheadinto the<head>tag and the keyrestaurantsinto a tag with the idordrinRestaurants, ifrestaurantsexists (renderRestaurantsSimplewill not have that key).params.extra: An object containing any extra data that should be rendered into the template.params.address: The address for food to be delivered to. SHould be an instance ofordrinAPI.addressor equivalent.params.menuUri: The base url for menu requests. Mustard assumes that requests tomenuUri/ridwill get responses with restaurant menus.params.deliveryTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.params.renderList: a boolean that determines whether Mustard or Deliverator will render the restaurant list. Deliverator will render it ifrenderListis truthy.renderRestaurantsONLY.params.filterRestaurants: a function that takes as input an array of restaurants and returns another array of restaurants, which should be displayed (as opposed to the original one).renderRestaurantsONLY.callback: a function that is called once the restaurant rendering is done. Has 2 arguments:(err, res). If call succeeded,nullis returned. If there was an error, it is returned via theerrargument.renderRestaurantsONLY.
Menu Pages
renderSimple(res, params, callback )
render(res, params )The first renders the page to pass as little data as possible into the response, so the client will have to request the restaurant data list and render the HTML.
The second renders the page with the data and possibly the rendered HTML, so the page will display quickly and the client will do as little work as possible to display the page.
Arguments:
res: The response variable that would be passed to an express middleware.params.rid: The restaurant IDparams.template: The name of a template to render into. This template should render the keyheadinto the<head>tag and the keymenuinto a tag with the idordrinMenu, ifmenuexists (renderSimplewill not have that key).params.extra: An object containing any extra data that should be rendered into the template.params.address: The address for food to be delivered to. SHould be an instance ofordrinAPI.addressor equivalent.params.deliveryTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.params.confirmUrl: A string that contains the (relative) path to the confirm page of the app.params.renderMenu: A boolean that determines whether Mustard or Deliverator will render the menu. Deliverator will render it ifrenderMenuis truthy.renderONLY.callback: a function that is called once the restaurant rendering is done. Has 2 arguments:(err, res). If call succeeded,nullis returned. If there was an error, it is returned via theerrargument.
Routes
getDefaultRestaurantListMiddleware(template, menuUri, render_server, extra)
getDefaultMenuMiddleware(template, render_server, extra)These return default route specific middlewares for restaurant lists and menus, respectively. They assume that menus can be requested at menuUri/rid, and both take the following query string parameters:
dateTime: The date and time of when the food should be delivered. Should be"ASAP"or a string of the formMM-dd+HH:mm.addr: The street address for deliveryaddr2: The second line of the street address (optional)city: The city for deliverystate: The state for deliveryzip: The zip code for deliveryphone: The phone number for delivery.
Arguments:
template: The name of a template to render into, with the same requirements as in restaurant list pages for the first function and menu pages for the second.render_server: Renders the entire page and requests the API data on the server if truthy, and all on the client otherwise.extra: An object containing any extra data that should be rendered into the template.menuUri: The base url for menu requests. Mustard assumes that requests tomenuUri/ridwill get responses with restaurant menus.
Middlewares
Injector
The injector middleware serves auxillary Deliverator requests made to URIs starting with path as set when initializing. It will act as a proxy to the Ordr.in API by forwarding any request that starts with /path/api. For any other path starting with /path, it will try to serve the corresponding file in node_modules/mustard.
You can use it in the app simply by calling
app.use(deliverator.injector);Use rendering object
The rendering object adder simply adds a reference to the rendering object to the request so that any middleware after it has a convenient reference to it.
You can use it in the app simply by calling
app.use(deliverator.html.addHtml);11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago