1. Go to this page and download the library: Download lmc/matej-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lmc / matej-client example snippets
use Lmc\Matej\Matej; // in all following examples namespaces and use statements are ommited from the code samples
$matej = new Matej('accountId', 'apikey');
echo 'Number of commands: ' . $response->getNumberOfCommands() . "\n";
echo 'Number of successful commands: ' . $response->getNumberOfSuccessfulCommands() . "\n";
echo 'Number of failed commands: ' . $response->getNumberOfFailedCommands()() . "\n";
// Use $response->isSuccessful() to check whether all of the commands send in request were successful or not:
if (!$response->isSuccessful()) {
echo 'At least one command response was not succesful!';
}
// Iterate over getCommandResponses() to get response for each command passed to the builder.
// Commands in the response are present in the same order as they were added to the requets builder.
foreach ($response->getCommandResponses() as $commandResponse) {
if ($commandResponse->isSuccessful()) {
// Methods $commandResponse->getData(), ->getMessage() and ->getStatus() are available
} else {
// Log error etc.
}
}
$matej = new Matej('accountId', 'apikey');
// Create new item property in database:
$response = $matej->request()
->setupItemProperties()
->addProperty(ItemPropertySetup::timestamp('valid_to'))
->addProperty(ItemPropertySetup::string('title'))
->send();
// Get list of item properties that are defined in Matej
$response = $matej->request()
->getItemProperties()
->send();
$properties = $response->getData(); // this is shortcut for $response->getCommandResponse(0)->getData()
// Delete item property from database:
$response = $matej->request()
->deleteItemProperties()
->addProperty(ItemPropertySetup::timestamp('valid_from'))
->addProperty(ItemPropertySetup::string('title'))
->send();
$matej = new Matej('accountId', 'apikey');
$response = $matej->request()
->resetDatabase()
->send();
var_dump($response->isSuccessful()); // true on success
$matej = new Matej('accountId', 'apikey');
$response = $matej->request()
->resetData()
->send();
var_dump($response->isSuccessful()); // true on success
$matej = new Matej('accountId', 'apikey');
$response = $matej->request()
->events()
// Add interaction between user and item
->addInteraction(Interaction::withItem('purchases', 'user-id', 'item-id'))
->addInteractions([/* array of Interaction objects */])
// Update item data
->addItemProperty(ItemProperty::create('item-id', ['valid_from' => time(), 'title' => 'Title']))
->addItemProperties([/* array of ItemProperty objects */])
// Merge user
->addUserMerge(UserMerge::mergeInto('target-user-id', 'source-user-id', 1629361884))
->addUserMerges([/* array of UserMerge objects */])
->send();
$recommendation = UserItemRecommendation::create('user-id', 'test-scenario')
->setCount(5)
->setRotationRate(1.0)
->setRotationTime(3600)
->setFilters(['for_recommendation = 1'])
->setMinimalRelevance(ItemMinimalRelevance::HIGH())
->enableHardRotation()
// You can further modify which items will be recommended by providing boosting rules.
// Priority of items matching the query will be multiplied by the value of multiplier:
->addBoost(Boost::create('valid_to >= NOW()', 2));
$response = $matej->request()
->recommendation($recommendation)
->send();
$matej = new Matej('accountId', 'apikey');
try {
$response = $matej
->request()
->sorting(/* ... */)
// ...
->send();
} catch (\Lmc\Matej\Exception\RequestException $exception) {
echo $e->getMessage(); // this will output just HTTP reason phrase, like "Bad Request"
$serverResponseContents = $exception->getResponse()
->getBody()
->getContents();
echo $serverResponseContents; // this will output the full response body which Matej server gave
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.