\GravityClient

The GravityClient class can be used to send events, item and user information to the recommendation engine and get recommendations.

Example usage:

    function createGravityClient() {
        $config = new GravityClientConfig();
        $config->remoteUrl = 'https://saas.gravityrd.com/grrec-CustomerID-war/WebshopServlet';
        $config->user = 'sampleUser';
        $config->password = 'samplePasswd';
        $config->retry = 0;
        return new GravityClient($config);
    }
    $client = createGravityClient();
    $context = new GravityRecommendationContext();
    $context->numberLimit = 5;
    $context->scenarioId = 'HOMEPAGE_MAIN';
             $context->nameValues = array(
                     new GravityNameValue('minPrice', '100'),
             );
    $client->getItemRecommendation('user1', '123456789abcdef', $context);

Please do not modify the GravityClient.php file (e.g. do not write your configuration parameters into the GravityClient.php file). Using an unmodified client makes version updates easier. Use your own factory function (like createGravityClient in the example above) to pass your configuration information to the GravityClient constructor.

Summary

Methods
Properties
Constants
__construct()
addEvent()
addEvents()
addItem()
addItems()
updateItem()
updateItems()
addUser()
addUsers()
getItemRecommendation()
getItemRecommendationBulk()
test()
testException()
$version
No constants found
No protected methods found
No protected properties found
N/A
getRequestQueryString()
sendRequestRetry()
sendRequest()
handleError()
guessOriginalRequestURI()
$config
N/A

Properties

$version

$version : 

The version info of the client.

Type

Methods

__construct()

__construct(\GravityClientConfig  $config) 

Creates a new client instance with the specified configuration

Parameters

\GravityClientConfig $config

addEvent()

addEvent(\GravityEvent  $event,   $async) 

Adds an event to the recommendation engine.

Parameters

\GravityEvent $event
$async

addEvents()

addEvents(array  $events,   $async) 

Adds multiple events to the recommendation engine.

Parameters

array $events
$async

addItem()

addItem(\GravityItem  $item,   $async) 

Adds an item to the recommendation engine.

If the item already exists with the specified itemId, the entire item along with its NameValue pairs will be replaced to the new item specified here.

Parameters

\GravityItem $item
$async

addItems()

addItems(array  $items,   $async) 

Adds items to the recommendation engine.

If an item already exists with the specified itemId, the entire item along with its NameValue pairs will be replaced to the new item specified here.

Parameters

array $items
$async

updateItem()

updateItem(\GravityItem  $item) 

Existing item will be updated. If item does not exist Exception will be thrown.

Update rules:

  • Key-value pairs won't be deleted only existing ones updated or new ones added. But If a key occurs in the key value list, then all values with the given key will be deleted and new values added in the recengine.
  • Hidden field has to be always specified!

Parameters

\GravityItem $item

The item to update

updateItems()

updateItems(array<mixed,\GravityItem>  $items) 

Existing items will be updated. If item does not exist Exception will be thrown.

Update rules:

  • Key-value pairs won't be deleted only existing ones updated or new ones added. But If a key occurs in the key value list, then all values with the given key will be deleted and new values added in the recengine.
  • Hidden field has to be always specified!

Parameters

array<mixed,\GravityItem> $items

The items to update

addUser()

addUser(\GravityUser  $user,   $async) 

Adds user to the recommendation engine.

If the user already exists with the specified userId, the entire user will be replaced with the new user specified here.

Parameters

\GravityUser $user
$async

addUsers()

addUsers(array  $users,   $async) 

Adds users to the recommendation engine. The existing users will be updated.

If a user already exists with the specified userId, the entire user will be replaced with the new user specified here.

Parameters

array $users
$async

getItemRecommendation()

getItemRecommendation(  $userId,   $cookieId, \GravityRecommendationContext  $context) : \GravityItemRecommendation

Returns a list of recommended items, based on the given context parameters.

Parameters

$userId
$cookieId
\GravityRecommendationContext $context

Returns

\GravityItemRecommendation

An object containing the recommended items and other information about the recommendation.

getItemRecommendationBulk()

getItemRecommendationBulk(  $userId,   $cookieId, array  $context) : array<mixed,\GravityItemRecommendation>

Given the userId and the cookieId, we can request recommendations for multiple scenarios (described by the context).

This function returns lists of recommended items for each of the given scenarios in an array.

Parameters

$userId
$cookieId
array $context

Returns

array<mixed,\GravityItemRecommendation> —

An Array containing the recommended items for each scenario with other information about the recommendation.

test()

test(  $name) : string

Simple test function to test without side effects whether the service is alive.

Parameters

$name

Returns

string —

"Hello " + $name

testException()

testException() 

Simple test function to test throwing an exception.

getRequestQueryString()

getRequestQueryString(  $methodName,   $queryStringParams) 

Parameters

$methodName
$queryStringParams

sendRequestRetry()

sendRequestRetry(  $requestUrl,   $requestBody,   $isLast) 

Parameters

$requestUrl
$requestBody
$isLast

sendRequest()

sendRequest(  $methodName,   $queryStringParams,   $requestBody,   $hasAnswer) 

Parameters

$methodName
$queryStringParams
$requestBody
$hasAnswer

handleError()

handleError(  $ch,   $result,   $verbStr) 

Parameters

$ch
$result
$verbStr

guessOriginalRequestURI()

guessOriginalRequestURI()