commit | 3edce5efe60fef6d2090ae24d34f795de6b7cf33 | [log] [tgz] |
---|---|---|
author | Simon Chan <simon@tappingstone.com> | Mon Apr 01 23:44:57 2013 +0100 |
committer | Simon Chan <simon@tappingstone.com> | Mon Apr 01 23:44:57 2013 +0100 |
tree | 077815a03b0a0f72a0aa1f1c8c8c44f726aee30a | |
parent | 1e21d4c70cc88194a0cb4ced8524572f183ac999 [diff] |
fixed install command; added addItem example
The easiest way to install PredictionIO PHP client is to use Composer.
Add predictionio/predictionio
as a dependency in your project's composer.json
file:
{ "require": { "predictionio/predictionio": "*" } }
Install Composer:
curl -sS https://getcomposer.org/installer | php -d detect_unicode=Off
Use Composer to install your dependencies:
php composer.phar install
Include Composer's autoloader in your PHP code
require_once("vendor/autoload.php");
Assuming you are cloning to your home directory:
cd ~ git clone git://github.com/PredictionIO/PredictionIO-PHP-SDK.git
Build the Phar:
cd ~/PredictionIO-PHP-SDK phing
Once the build finishes you will get a Phar in build/artifacts
, and a set of API documentation. Assuming you have copied the Phar to your current working directory, to use the client, simply
require_once("predictionio.phar");
For a list of supported commands, please refer to the API documentation.
This package is a web service client based on Guzzle. A few quick examples are shown below.
For a full user guide on how to take advantage of all Guzzle features, please refer to http://guzzlephp.org. Specifically, http://guzzlephp.org/tour/using_services.html#using-client-objects describes how to use a web service client.
Many REST request commands support optional arguments. They can be supplied to these commands by the set
method.
use PredictionIO\PredictionIOClient; $client = PredictionIOClient::factory(array("appkey" => "<your app key>"));
// assume you have a user with user ID 5 $command = $client->getCommand('create_user', array('uid' => 5)); $response = $client->execute($command);
// assume you have a book with ID 'bookId1' and we assign 1 as the type ID for book $command = $client->getCommand('create_item', array('iid' => 'bookId1', 'itypes' => 1)); $response = $client->execute($command);
// assume this user has viewed this book item $client->execute($client->getCommand('user_view_item', array('uid' => 5, 'iid' => 'bookId1')));
try { // assume you have created an itemrec engine named 'engine1' // we try to get top 10 recommendations for a user (user ID 5) $command = $client->getCommand('itemrec_get_top_n', array('engine' => 'engine1', 'uid' => 5, 'n' => 10)) $rec = $client->execute($command); print_r($rec); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }