Skip to content

Instantly share code, notes, and snippets.

@khalib
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save khalib/4e0dae7c3c622e01b8b3 to your computer and use it in GitHub Desktop.

Select an option

Save khalib/4e0dae7c3c622e01b8b3 to your computer and use it in GitHub Desktop.
Example usage of the Common Sense api-php driver.
$api_info = variable_get('csm_api_info');
// the third TRUE param sets to use DEV api server. Remove for launch.
$api = new CommonSenseApi($api_info['clientId'], $api_info['appId'], TRUE);
// Get education API instance.
// There are two magic methods to fetch data from the API
// <type>_list($options) and <type>_item($id, $options)
// where <type> is one of: products, blog, app_flows, lists, user_reviews, boards
$education = $api->education();
// Get some app flows.
// Set options for the call.
$options = array(
'fields' => array('id', 'title', 'author.display_name', 'url'),
'limit' => 5,
'page' => 2,
);
$response = $education->get_app_flows_list($options);
$app_flows = $response->response;
echo '<h1>App Flows List</h1>';
foreach ($app_flows as $app_flow) {
echo '<pre>'; var_dump($app_flow); echo '</pre>';
}
// Get details on a single app flow.
echo '<h1>App Flows Item</h1>';
$options = array(
'fields' => array('id', 'title', 'author.display_name', 'url', 'description'),
);
$app_flow = $education->get_app_flows_item($app_flows[0]->id, $options)->response;
echo '<pre>'; var_dump($app_flow); echo '</pre>';
// Get some products.
// Set options for the call.
$options = array(
'fields' => array('id', 'title', 'review.url'),
'limit' => 5,
'page' => 1,
);
$response = $education->get_products_list($options);
$products = $response->response;
echo '<h1>Products List</h1>';
foreach ($products as $product) {
echo '<pre>'; var_dump($product); echo '</pre>';
}
// Get details on a single product.
echo '<h1>Product Item</h1>';
$options = array(
'fields' => array('id', 'title', 'image', 'review.url'),
);
$product = $education->get_products_item($products[0]->id, $options)->response;
echo '<pre>'; var_dump($product); echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment