PHP code example of gameball / gameball-php

1. Go to this page and download the library: Download gameball/gameball-php 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/ */

    

gameball / gameball-php example snippets




// INITIALIZE PLAYER
$gameball = new \Gameball\GameballClient('Your_API_Key', 'Your_SECRET_Key');

$playerAttributes = new \Gameball\Models\PlayerAttributes();
$playerAttributes->displayName = "display_name";
$playerAttributes->firstName = 'first_name';
$playerAttributes->lastName = 'last_name';
$playerAttributes->gender = 'M';
$playerAttributes->email = '[email protected]';
$playerAttributes->mobile = '_mobile_';
$playerAttributes->dateOfBirth = '1991-09-19T00:00:00.000Z';
$playerAttributes->joinDate = '2022-01-01T21:06:29.158Z';

$playerRequest = \Gameball\Models\PlayerRequest::factory(
        "player_unique_id",
        null, // EMAIL
        null, // MOBILE 
        $playerAttributes
    );

// SEND EVENT
$eventRequest = new \Gameball\Models\EventRequest();
$eventRequest->addEvent('place_order');
$eventRequest->addMetaData('place_order','total_amount','100');
$eventRequest->addMetaData('place_order','category',array("electronics","cosmetics"));
$eventRequest->addEvent('review');

$playerRequest = \Gameball\Models\PlayerRequest::factory('player123');
$eventRequest->playerRequest = $playerRequest;

$res= $gameball->event->sendEvent($eventRequest);

// Accessing response data
echo $res->body;

// Accessing response data as JSON
echo $res->decodedJson;