save() public method

Save this Source
public save ( boolean $validate = true ) : DataSift_Source
$validate boolean
return DataSift_Source
Esempio n. 1
0
 protected function createSource()
 {
     $response = array('response_code' => 200, 'data' => array('id' => '78b3601ef667466d95f19570dcb74699', 'name' => 'My PHP managed source', 'created_at' => 1435869526, 'status' => 'active', 'auth' => array(array('identity_id' => '7b1be3a398e646bbb3c7a5cb9717ba45', 'expires_at' => 1495869526, 'parameters' => array('value' => '363056350669209|09af1ce9c5d8d23147ec4eeb9a33aac2'))), 'resources' => array(array('resource_id' => '30bc448896de44b88604ac223cb7f26f', 'status' => 'valid', 'parameters' => array('url' => 'http://www.facebook.com/theguardian', 'title' => 'The Guardian', 'id' => 10513336322))), 'parameters' => array('comments' => true, 'likes' => true, 'page_likes' => true, 'posts_by_others' => true)), 'rate_limit' => 200, 'rate_limit_remaining' => 150);
     DataSift_MockApiClient::setResponse($response);
     $source = new DataSift_Source($this->user, array('name' => 'My PHP managed source', 'source_type' => 'facebook_page', 'parameters' => array('comments' => true, 'likes' => true, 'page_likes' => true, 'posts_by_others' => true), 'auth' => array(array('expires_at' => 1495869526, 'parameters' => array('value' => '363056350669209|09af1ce9c5d8d23147ec4eeb9a33aac2'))), 'resources' => array(array('parameters' => array('url' => 'http://www.facebook.com/theguardian', 'title' => 'The Guardian', 'id' => 10513336322)))));
     $source->save();
     return $source;
 }
Esempio n. 2
0
$theguardian->parameters->url = 'http://www.facebook.com/theguardian';
$theguardian->parameters->title = 'Some news page';
$theguardian->parameters->id = 'theguardian';
//or using an array
$ladyGaga = new stdClass();
$ladyGaga->parameters = array('url' => 'http://www.facebook.com/ladygaga', 'title' => 'Lady Gaga', 'id' => 'ladygaga');
$resources = array($theguardian, $ladyGaga);
$facebookAuth1 = new stdClass();
$facebookAuth1->parameters = new stdClass();
$facebookAuth1->parameters->value = 'facebook_token';
//one or more facebook OAuth tokens can be used to manage the resources
$auth = array($facebookAuth1);
$source = new DataSift_Source($user, array('name' => 'My PHP managed source', 'source_type' => 'facebook_page', 'parameters' => $params, 'auth' => $auth, 'resources' => $resources));
//create the managed source - note the same method is used to update an existing
//managed source if an ID is set on the object
try {
    $source->save();
} catch (Exception $e) {
    print_r($e->getMessage());
}
//after saving the source will have an ID, created at time etc...
echo 'Created managed source ==> ' . $source->getId();
//Add an extra resource
$nintendo = new stdClass();
$nintendo->parameters = array('url' => 'http://www.facebook.com/nintendo', 'title' => 'Nintendo', 'id' => 'nintendo');
$source->addResource(array($nintendo));
$resources = $source->getResources();
//remove the first resource
$source->removeResource(array($resources[0]['resource_id']));
//Check for log messages
$logs = $source->getLogs();