コード例 #1
0
 /**
  * Makes a recursive request to the data api, dependant on
  * whether 'next' is returned in the meta object
  *
  * @param  string  $endpoint       URL to send the request
  * @param  array   $securityPacket Security details
  * @param  string  $secret         Private key
  * @param  array   $requestPacket  Request packet
  * @param  string  $action         Action for the request
  * @param  mixed   $callback       Optional callback to execute instead of returning data
  * @return array                   Array of all data requests or [] or using a callback
  */
 public function requestRecursive($endpoint, $securityPacket, $secret, $requestPacket = null, $action = null, $callback = null)
 {
     $response = array();
     do {
         $request = $this->request($endpoint, $securityPacket, $secret, $requestPacket, $action);
         $data = Json::isJson($request->getBody()) ? json_decode($request->getBody(), true) : $request->getBody();
         if ($data['meta']['status'] === true) {
             if (!empty($callback) && is_callable($callback)) {
                 call_user_func($callback, $data);
             } else {
                 $response = array_merge($response, $data['data']);
             }
         } else {
             throw new Exception(Json::encode($data));
         }
         if (array_key_exists('next', $data['meta']) && !empty($data['data'])) {
             $requestPacket['next'] = $data['meta']['next'];
         } else {
             unset($requestPacket['next']);
         }
     } while (array_key_exists('next', $requestPacket));
     return $response;
 }
コード例 #2
0
<?php 
use LearnositySdk\Utils\Json;
if (!isset($signedRequest)) {
    die('Make sure you call your PHP var $signedRequest for initialisation preview to work');
}
$previewObject = is_array($signedRequest) ? json_decode($signedRequest, true) : $signedRequest;
if (is_array($previewObject)) {
    if (isset($previewObject['request']['api_type'])) {
        unset($previewObject['request']['api_type']);
    } elseif (isset($previewObject['request']['config']['api_type'])) {
        unset($previewObject['request']['config']['api_type']);
    }
    if (array_key_exists('security', $previewObject)) {
        $previewBody = '{"security": ' . Json::encode($previewObject['security']) . ', "request": ' . Json::encode($previewObject['request']) . '}';
    } else {
        $previewBody = Json::encode($previewObject);
    }
} else {
    $previewBody = $previewObject;
}
?>

<script>
    var init = <?php 
echo $previewBody;
?>
;
    delete init.api_type;
    $('#preview-body').html(prettyPrint.render(init));
</script>
コード例 #3
0
<?php

include_once '../../config.php';
include_once 'includes/header.php';
use LearnositySdk\Utils\Json;
$security = array('consumer_key' => $consumer_key, 'domain' => $domain, 'timestamp' => gmdate('Ymd-Hi'));
$request = array('limit' => 100, 'tags' => array(array('type' => 'course', 'name' => 'commoncore')));
$security['signature'] = generateSignature($security, $consumer_secret, $request);
$signedRequest = Json::encode(array('request' => $request, 'security' => $security));
?>

<div class="jumbotron section">
    <div class="toolbar">
        <ul class="list-inline">
            <li data-toggle="tooltip" data-original-title="Preview API Initialisation Object"><a href="#"  data-toggle="modal" data-target="#initialisation-preview"><span class="glyphicon glyphicon-search"></span></a></li>
            <li data-toggle="tooltip" data-original-title="Visit the documentation"><a href="http://docs.learnosity.com/authorapi/" title="Documentation"><span class="glyphicon glyphicon-book"></span></a></li>
            <li data-toggle="tooltip" data-original-title="Toggle product overview box"><a href="#"><span class="glyphicon glyphicon-chevron-up jumbotron-toggle"></span></a></li>
        </ul>
    </div>
    <div class="overview">
        <h1>Author API</h1>
        <p>Learnosity's Author API allows searching and integration of Learnosity powered content into your content management system.<p>
    </div>
</div>

<div class="section">
    <section>
        <h3>Sample CMS/LMS Integration</h3>
        <p>Below is an edit page for a fictional Content/Learning Management System.</p>
        <p>The buttons on the right show how you might integrate the Author API to search for, and add items &mdash;
        allowing your authors to integrate rich content items into existing pages.</p>
コード例 #4
0
ファイル: Init.php プロジェクト: arpita-singh/bootjuly
 /**
  * Generate a JSON string from the requestPacket (array) or null
  * if no requestPacket is required for this request
  *
  * @return mixed
  */
 private function generateRequestString()
 {
     if (empty($this->requestPacket)) {
         return null;
     }
     $requestString = Json::encode($this->requestPacket);
     if (false === $requestString) {
         throw new ValidationException('Invalid data, please check your request packet - ' . Json::checkError());
     }
     return $requestString;
 }