
The Batch API lets you make multiple DayPI requests as one request to the daylife servers.
You can use this PHP client to make a Batch.parallel request. You can download this script from the attachment below.
Here is sample code how to use this script to first form your DayPI requests and then provide them as request to the Batch API:
include_once('./batcher.php');
#configure the daylife api server url here
$daylife_server = "freeapi.daylife.com";
$protocol = "xmlrest";
$version = "4.4";
$batcher_access_url = "http://" . $daylife_server . "/" . $protocol . "/batch/1.0/";
#configure your api credentials here
$accesskey = "";
$sharedsecret = "";
#instantiate a PublicApiBatcher instance:
$batcher = new PublicApiBatcher($batcher_access_url, $accesskey, $sharedsecret, $version);
#say you want to get stories, quotes and connections related to "Iraq War" in last 7 days
$query = 'Iraq War';
$end_time = time();
$start_time = $end_time - (7 *86400);
#common params across all calls
$params = array('query' => $query, 'end_time' => $end_time, 'start_time' => $start_time, 'sort' => 'relevance');
$call_list = array();
#get article
$article_params = array('limit' => 10, 'offset' => 0, 'include_image' => 1, 'include_scores' =>1);
$article_params = array_merge($params, $article_params);
$call_list['articles'] = array('call'=>'search_getRelatedArticles','params'=>$article_params);
#get quotes
$quote_params = array('limit' => 10, 'offset' => 0, 'require_speaker' => 1);
$quote_params = array_merge($params, $quote_params);
$call_list['quotes'] = array('call'=>'search_getRelatedQuotes','params'=>$quote_params);
#get Connections
$player_params = array('limit' => 10, 'offset' => 0, 'include_image' => 1);
$player_params = array_merge($params, $player_params);
$call_list['topics'] = array('call'=>'search_getRelatedTopics','params'=>$player_params);
$result = $batcher->parallel($call_list);
echo $result;
Download Sample Batch Response Here.
| Attachment | Size |
|---|---|
| batcher.zip | 1.53 KB |