Overview  Package  Tree RecipeRPC_Server

Functions

Summary
intcountdbrecipes

Counts the number of recipes in the database.

string|intfetchrecipe

Fetch the recipe specified in the given format.

arrayfindrecipes

Find recipes that match given criteria, starting with the given index.

arraygetcriteria

Fetch the criteria this server can search on, together with their allowable values.

intgetdbsize

Fetches the database size, in bytes.

arraygetfiledata

Extract required data from a RecipeML file.

arraygetformats

Get the recipe formats this server can supply.

booleaninsertrecipe

Insert a new recipe into the database.

stringrecipeupload

Upload into the database the recipes in the given directory.

booleantruncate

Deletes all the recipes in the database.

booleanuploadfile

Upload into the database the recipe in the given file.

Detail

countdbrecipes()

int countdbrecipes()

Counts the number of recipes in the database.

Returns:
Number of recipes.
Since:
RecipeRPC Reference Implementation Server version 0.4

fetchrecipe()

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).

Parameters:
id - Identifier as returned by findrecipes().
format - Format identifier; one of the strings returned by getformats().
Returns:
The desired recipe in the specified format, or an integer indicating a fault, as described above.
Since:
RecipeRPC Reference Implementation Server version 0.2

findrecipes()

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".

The 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.

The return value is always an array. It may be a fault array, which has two keys: "fault" and "faultstring", mapping directly to the fault code and string of XML-RPC fault messages. Or it may be a valid result array: in this case, there is one element with key 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.

Parameters:
criteriaarray - Array giving the search criteria, with contents as above.
index - Index of the first recipe to return, starting from 1, as described above.
Returns:
Either a fault array or a valid result array, with contents as above.
Since:
RecipeRPC Reference Implementation Server version 0.2

getcriteria()

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")); } 

Returns:
An array of arrays, each array giving the details for a criterion as described above.
Since:
RecipeRPC Reference Implementation Server version 0.2

getdbsize()

int getdbsize()

Fetches the database size, in bytes.

From an article on WebMasterWorld (with modifications).

Returns:
Database size in bytes
Since:
RecipeRPC Reference Implementation Server version 0.4

getfiledata()

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.

Parameters:
file - The file from which to extract data.
Returns:
Extracted data (see above).
Since:
RecipeRPC Reference Implementation Server version 0.2

getformats()

array getformats()

Get the recipe formats this server can supply.

Returns:
An array of strings, each the name of an available format.
Since:
RecipeRPC Reference Implementation Server version 0.2

insertrecipe()

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.

Parameters:
title - Title of the recipe.
recipe - Recipe data to be stored.
Returns:
Indicates success (true) or failure (false).
Since:
RecipeRPC Reference Implementation Server version 0.2

recipeupload()

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.

Parameters:
indir - Directory from which to upload.
Returns:
If empty, upload was successful; if not empty, contains a string describing the failure.
Since:
RecipeRPC Reference Implementation Server version 0.2

truncate()

boolean truncate()

Deletes all the recipes in the database.

Caution!!

Returns:
Indicates success (true) or failure (false).
Since:
RecipeRPC Reference Implementation Server version 0.4

uploadfile()

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).

Parameters:
file - File from which to upload.
Returns:
true if the upload succeeded, false if it failed.
Since:
RecipeRPC Reference Implementation Server version 0.2

Overview  Package  Tree RecipeRPC_Server