PHP code example of riddle / client-sdk

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

    

riddle / client-sdk example snippets




// [... your code, e.g. fetching riddles / stats / ...]



$client = new Riddle\Api\Client('...');



$client = new Riddle\Api\Client('access token');



$client = new Riddle\Api\Client('access token');
$riddles = $client->riddle()->list();



$client = new Riddle\Api\Client('access token');
$riddleStats = $client->stats()->fetchRiddleStats('[RIDDLE_ID]');



$teamId = 123;
$tagIds = [2]; // to get tag IDs use the tag list endpoint
$client = new Riddle\Api\Client('access token');
$riddles = $client->riddle()->list($teamId, null, $tagIds);



try {
    $webhook = new Riddle\Api\Webhook\Webhook('WveoGBv11xet392jUwPWbmEbicUn13zR');
    $payload = $webhook->parse();
    \file_put_contents(__DIR__.'/test-webhook.json', \json_encode($payload->getPayload())); // log the webhook payload

    // now work with the payload
    $resultId = $webhookResponse->getResultData()['blockId'];
    // ...
} catch (\Throwable $ex) {
    \file_put_contents(__DIR__.'/exception.txt', $ex->getMessage()); // write to a log file in case of an exception
}



$client = new Riddle\Api\Client('access token');
$pollBuilder = new Riddle\Api\Builder\PollBuilder($client);



$client = new Riddle\Api\Client('access token');
$pollBuilder = new Riddle\Api\Builder\PollBuilder($client);

// configure the poll's settings, such as questions / title / result
$pollBuilder
    ->setTitle('My Riddle Title')
    ->addSingleChoiceQuestion('What is the answer?', ['Yes', 'No', 'Maybe'])
    ->addMultipleChoiceQuestion('What are the answers?', ['Yes', 'No', 'Maybe'])
    ->setResult('Thanks for participating!', 'We will process your answers accordingly.');

// requests the API and returns the built poll
$builtPoll = $pollBuilder->build();



$client = new Riddle\Api\Client('access token');
$quizBuilder = new Riddle\Api\Builder\QuizBuilder($client);

// configure the quizz settings, such as questions / title / results
$quizBuilder
    ->setTitle('My Riddle Title')
    ->addSingleChoiceQuestion('What is the capital of germany?', ['Berlin' => true, 'Munich' => false, 'Hamburg' => false])
    ->addMultipleChoiceQuestion('Which words can you use to say "Hello" in German?', ['Hallo' => true, 'Ciao' => false, 'Guten Tag' => true])
    ->addResult('Not so good', 'You answered most questions incorrectly.', 0, 50)
    ->addResult('Well done', 'You answered most questions correctly.', 51, 100);

// requests the API and returns the built quiz
$builtQuiz = $quizBuilder->build();

$builtQuiz = $quizBuilder->build(false);