This software is the intellectual property of MediaSift Ltd., and is covered by retained intellectual property rights, including copyright. Distribution of this software is strictly forbidden under the terms of this license. The DataSift_ODP class represents an ODP query.
저자: Ryan Stanley (ryan.stanley@datasift.com)
예제 #1
0
 public function testIngest()
 {
     $response = array('response_code' => 200, 'data' => array('accepted' => 1, 'total_message_bytes' => 1788), 'rate_limit' => 200, 'rate_limit_remaining' => 150);
     DataSift_MockApiClient::setResponse($response);
     $data_set = '[{"id": "234", "body": "yo"}]';
     $source_id = '1f1be6565a1d4ef38f9f4aeec9554440';
     $ingest = new DataSift_ODP($this->user, $source_id);
     $response = $ingest->ingest($data_set);
     $this->assertEquals($response['accepted'], 1, 'Not accepted');
 }
예제 #2
0
// Include the configuration - put your username and API key in this file
require dirname(_FILE_) . '/../config.php';
// Autheticate
echo "Creating user...\n";
$user = new DataSift_User('USER', 'API');
// Setting up the specific resources of the Managed Source
$ODPex = new stdClass();
$ODPex->parameters = new stdClass();
$ODPex->parameters->category = '6d2420bffa3d4fda9a85ccb47f626890_1';
$ODPex->parameters->idml = "web.link = id\r\nweb.content = body";
$resources = array($ODPex);
// Create new ODP Managed Source
$source = new DataSift_Source($user, array('name' => 'My ODP Managed Source', 'source_type' => 'custom', 'resources' => $resources));
try {
    $source->save();
} catch (Exception $e) {
    print_r($e->getMessage());
}
// Assign the Source ID to a vaiable
$source_id = $source->getId();
// Setting up a data set array to send to the endpoint
$data = array(array('id' => '234', 'body' => 'yo'), array('id' => '898', 'body' => 'hey'));
$data_set = "";
foreach ($data as $entry) {
    $data_set .= json_encode($entry) . "\n";
}
// Create the ODP object
$odp = new DataSift_ODP($user, $source_id);
// Use the ingest function and make an API request
$response = $odp->ingest($data_set);
var_dump($response);