Overview Package Tree | RecipeRPC_Server |
FRAMES NO FRAMES | |
SUMMARY: FUNCTIONS | DETAIL: FUNCTIONS |
Summary |
---|
int | countdbrecipes Counts the number of recipes in the database. |
string|int | fetchrecipe Fetch the recipe specified in the given format. |
array | findrecipes Find recipes that match given criteria, starting with the given index. |
array | getcriteria Fetch the criteria this server can search on, together with their allowable values. |
int | getdbsize Fetches the database size, in bytes. |
array | getfiledata Extract required data from a RecipeML file. |
array | getformats Get the recipe formats this server can supply. |
boolean | insertrecipe Insert a new recipe into the database. |
string | recipeupload Upload into the database the recipes in the given directory. |
boolean | truncate Deletes all the recipes in the database. |
boolean | uploadfile Upload into the database the recipe in the given file. |
Detail |
---|
int countdbrecipes()
Counts the number of recipes in the database.
string|int fetchrecipe(string id, string format)
Fetch the recipe specified in the given format.
Returns either the desired recipe as a string, or an integer indicating a fault (allowable integers are 404, indicating recipe not found, and 416, indicating an invalid format).
id
- Identifier as returned by findrecipes()
. format
- Format identifier; one of the strings returned by getformats()
. array findrecipes(array criteriaarray, int index)
Find recipes that match given criteria, starting with the given index.
Returns name and ID for each recipe, or else a fault.
The passed-in criteria array maps criterion names to values. For example,
$result = findrecipes(array("name" => "artichoke", "category" => "vegetarian"), 1);requests vegetarian recipes whose names contain "artichoke".
index
parameter indicates where in the list of all matching recipes to start when returning recipes. For instance, if the matching recipes are numbered 1, 2, 3,... and index=7
, recipes should be returned starting with number 7.total
, giving the total number of matches; the other elements are numbered 0, 1, 2, ... and each of these elements is itself an array with two keys, "name" and "id", mapped to (surprise) the name and ID of a matching recipe. criteriaarray
- Array giving the search criteria, with contents as above. index
- Index of the first recipe to return, starting from 1, as described above. array getcriteria()
Fetch the criteria this server can search on, together with their allowable values.
Each element of the returned array is itself an array, whose first element is the name of the criterion and whose subsequent elements give the allowable values for that criterion. If the criterion can accept any string without validation, the second value in the array should be the string "any" and there should be no further elements.
For example, this implementation of the function indicates that any value may be passed for the name
criterion and that either vegetarian
or diabetic
must be passed for the category
criterion.
function getcriteria() { return array(array("name", "any"), array("category", "vegetarian", "diabetic")); }
int getdbsize()
Fetches the database size, in bytes.
From an article on WebMasterWorld (with modifications).
array getfiledata(string file)
Extract required data from a RecipeML file.
Data extracted are the title and the full file contents. These are returned in an array with keys "title" and "recipe". The file should be given as a path relative to the RecipeRPC server home directory.
file
- The file from which to extract data. array getformats()
Get the recipe formats this server can supply.
boolean insertrecipe(string title, string recipe)
Insert a new recipe into the database.
Creates the database and required tables, if they do not already exist.
title
- Title of the recipe. recipe
- Recipe data to be stored. true
) or failure (false
). string recipeupload(string indir)
Upload into the database the recipes in the given directory.
Recipes are assumed to be stored in individual files using RecipeML format. Attempts to upload all files ending in .xml
in the given directory; other files are ignored. The directory should be given as a path relative to the RecipeRPC server home directory. If the database specified by the database name parameter does not exist, or if it does not contain the appropriate tables, the database and tables are created (you need to ensure that your database user has permission to create these items). Sets timeout to 3600 seconds (1 hour) to allow big uploads.
indir
- Directory from which to upload. boolean truncate()
Deletes all the recipes in the database.
Caution!!
true
) or failure (false
). boolean uploadfile(string file)
Upload into the database the recipe in the given file.
The recipe is assumed to be stored using RecipeML format. The file should be given as a path relative to the RecipeRPC server home directory. If the database specified by the database name parameter does not exist, or if it does not contain the appropriate tables, the database and tables are created (you need to ensure that your database user has permission to create these items).
file
- File from which to upload. true
if the upload succeeded, false
if it failed. Overview Package Tree | RecipeRPC_Server |
FRAMES NO FRAMES | |
SUMMARY: FUNCTIONS | DETAIL: FUNCTIONS |