PHP code example of cognifit / cognifit-sdk-php
1. Go to this page and download the library: Download cognifit/cognifit-sdk-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/ */
cognifit / cognifit-sdk-php example snippets
use CognifitSdk\Api\HealthCheck;
$cognifitApiHealthCheck = new HealthCheck(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiHealthCheck->getInfo();
if(!$response->hasError()){
}
use CognifitSdk\Api\UserAccount;
use CognifitSdk\Lib\UserData;
$userName = 'Joe';
$userEmail = '[email protected] ';
$userBirth = '1981-07-15';
$locale = 'en';
$userPassword = 'RANDOM_PASSWORD_OR_USER_KNOWN_PASSWORD';
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccount->registration(new UserData([
'user_name' => $userName,
'user_email' => $userEmail,
'user_birthday' => $userBirth,
'user_locale' => $locale,
'user_password' => $userPassword
]));
if(!$response->hasError()){
$cognifitUserToken = $response->get('user_token');
if($cognifitUserToken){
// Save this user_token for future requests
}
}
use CognifitSdk\Api\UserAccount;
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$userEmail = '[email protected] ';
$callbackUrl = '';
$stateHash = 'RANDOM';
$response = $cognifitApiUserAccount->getAssociateExistingUserAccountUrl(
$userEmail,
$callbackUrl,
$stateHash
);
if(!$response->hasError()){
$cognifitUserToken = $response->get('user_token');
if($cognifitUserToken){
// Save this user_token for future requests
}
}
use CognifitSdk\Api\UserAccessToken;
$cognifitUserToken = 'USER_TOKEN';
$cognifitApiUserAccessToken = new UserAccessToken(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccessToken->issue($cognifitUserToken);
if(!$response->hasError()){
return $response->get('access_token');
}
use CognifitSdk\Api\UserStartSession;
$cognifitStartSession = new UserStartSession(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET'),
false,
env('COGNIFIT_HASH')
);
$userAccessToken = 'USER_ACCESS_TOKEN';
$callbackUrl = '';
$url = $cognifitStartSession->getUrl($userAccessToken, $callbackUrl);
use CognifitSdk\Api\UserAccount;
use CognifitSdk\Lib\UserData;
$userToken = 'USER_TOKEN';
$userName = 'Joe';
$userEmail = '[email protected] ';
$userBirth = '1981-07-15';
$locale = 'en';
$userPassword = 'RANDOM_PASSWORD_OR_USER_KNOWN_PASSWORD';
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccount->update($userToken, new UserData([
'user_name' => $userName,
'user_email' => $userEmail,
'user_birthday' => $userBirth,
'user_locale' => $locale,
'user_password' => $userPassword
]));
if(!$response->hasError()){
// Success
}
use CognifitSdk\Api\UserAccount;
$userToken = 'USER_TOKEN';
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccount->activate($userToken);
if(!$response->hasError()){
// Success
}
use CognifitSdk\Api\UserAccount;
$userToken = 'USER_TOKEN';
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccount->deactivate($userToken);
if(!$response->hasError()){
// Success
}
use CognifitSdk\Api\UserAccount;
$userToken = 'USER_TOKEN';
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccount->grantTrainingLicense($userToken);
if(!$response->hasError()){
// Success
}
use CognifitSdk\Api\UserAccount;
$userToken = 'USER_TOKEN';
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccount->revokeTrainingLicense($userToken);
if(!$response->hasError()){
// Success
}
use CognifitSdk\Api\UserAccount;
$userToken = 'USER_TOKEN';
$cognifitApiUserAccount = new UserAccount(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserAccount->delete($userToken);
if(!$response->hasError()){
// Success
}
use CognifitSdk\Api\Product;
$localesForAssets = ['en', 'es'];
$product = new Product(env('COGNIFIT_CLIENT_ID'), true);
$assessments = $product->getAssessments($localesForAssets);
foreach ($assessments as $assessmentKey => $assessment){
echo $assessment->getKey();
}
use CognifitSdk\Api\Product;
$localesForAssets = ['en', 'es'];
$product = new Product(env('COGNIFIT_CLIENT_ID'), true);
$assessments = $product->getAssessmentTasks($localesForAssets);
foreach ($assessments as $assessmentKey => $assessment){
echo $assessment->getKey();
}
use CognifitSdk\Api\Product;
$localesForAssets = ['en', 'es'];
$product = new Product(env('COGNIFIT_CLIENT_ID'), true);
$questionnaires = $product->getQuestionnaires($localesForAssets);
foreach ($questionnaires as $questionnaireKey => $questionnaire){
echo $questionnaire->getKey();
}
use CognifitSdk\Api\Product;
$localesForAssets = ['en', 'es'];
$product = new Product(env('COGNIFIT_CLIENT_ID'), true);
$trainingPrograms = $product->getTraining($localesForAssets);
foreach ($trainingPrograms as $trainingProgramKey => $trainingProgram){
echo $trainingProgram->getKey();
}
use CognifitSdk\Api\Product;
$localesForAssets = ['en', 'es'];
$product = new Product(env('COGNIFIT_CLIENT_ID'), true);
$games = $product->getGames($localesForAssets);
foreach ($games as $gameKey => $game){
echo $game->getKey();
}
use CognifitSdk\Api\Skills;
$localesForAssets = ['en', 'es'];
$skills = new Skills(env('COGNIFIT_CLIENT_ID'), true);
$skillList = $skills->getSkills($localesForAssets);
foreach ($skillList as $skill){
echo $skill->getKey();
}
use CognifitSdk\Api\UserStartSession;
$userStartSession = new UserStartSession(getenv('TEST_CLIENT_ID'), '', true, getenv('TEST_CLIENT_HASH'));
$urlToStartSession = $userStartSession->getUrlStartCognifitForTraining($this->userToken, $this->callbackUrl, 'DRIVING');
use CognifitSdk\Api\UserStartSession;
$userStartSession = new UserStartSession(getenv('TEST_CLIENT_ID'), '', true, getenv('TEST_CLIENT_HASH'));
$urlToStartSession = $userStartSession->getUrlStartCognifitForAssessment('USER_TOKEN', '', 'DRIVING_ASSESSMENT');
use CognifitSdk\Api\UserStartSession;
$userStartSession = new UserStartSession(getenv('TEST_CLIENT_ID'), '', true, getenv('TEST_CLIENT_HASH'));
$urlToStartSession = $userStartSession->getUrlStartCognifitForGame('USER_TOKEN', '', 'MAHJONG');
use CognifitSdk\Api\UserActivity;
$cognifitUserToken = 'USER_TOKEN';
$cognifitApiUserActivity = new UserActivity(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserActivity->getHistoricalScoreAndSkills($cognifitUserToken);
if(!$response->hasError()){
}
use CognifitSdk\Api\UserActivity;
$cognifitUserToken = 'USER_TOKEN';
$cognifitApiUserActivity = new UserActivity(
env('COGNIFIT_CLIENT_ID'),
env('COGNIFIT_CLIENT_SECRET')
);
$response = $cognifitApiUserActivity->getPlayedGames($cognifitUserToken);
if(!$response->hasError()){
}