public function testGetBuffered() { $def = new DataSift_Definition($this->user, testdata('definition')); $response = array('response_code' => 200, 'data' => array('hash' => testdata('definition_hash'), 'created_at' => date('Y-m-d H:i:s', time()), 'dpu' => 10), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $this->assertEquals($def->get(), testdata('definition'), 'Definition string not set correctly'); $response = array('response_code' => 200, 'data' => array('stream' => array('Test interaction 1', 'Test interaction 2'), 'hash' => testdata('definition_hash'), 'created_at' => date('Y-m-d H:i:s', time()), 'dpu' => 10), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $interactions = $def->getBuffered(); $this->assertTrue(is_array($interactions), 'Failed to get buffered interactions'); }
public function testGetBuffered() { $response = array('response_code' => 200, 'data' => array('hash' => testdata('definition_hash'), 'created_at' => date('Y-m-d H:i:s', time()), 'dpu' => 10), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $def = new DataSift_Definition($this->user, testdata('definition')); $this->assertEquals($def->get(), testdata('definition'), 'Definition string not set correctly'); $def->getHash(); $response = array('response_code' => 200, 'data' => array('stream' => array(0 => array('interaction' => array('source' => 'Snaptu', 'author' => array('username' => 'nittolexia', 'name' => 'nittosoetreznoe', 'id' => 172192091, 'link' => 'http://johndoe.tumblr.com/'), 'type' => 'tumblr', 'link' => 'http://johndoe.tumblr.com/post', 'created_at' => 'Sat, 09 Jul 2011 05:46:51 +0000', 'content' => 'Mending gak ush maen dehh..', 'id' => '1e0a9eedc207acc0e074ea8aecb2c5ea'), 'tumblr' => array('user' => array('name' => 'nittosoetreznoe', 'description' => 'oh dear', 'location' => 'denpasar, bali', 'statuses_count' => 6830, 'followers_count' => 88, 'friends_count' => 111, 'screen_name' => 'nittolexia', 'lang' => 'en', 'time_zone' => 'Alaska', 'id' => 172192091, 'geo_enabled' => true), 'mentions' => array(0 => 'ayyuchadel', 1 => 'nittolexia', 2 => 'sansan_arie'), 'id' => '89571192838684672', 'text' => 'Mending gak ush maen dehh..', 'source' => '<a href="http://www.snaptu.com" rel="nofollow">Snaptu</a>', 'created_at' => 'Sat, 09 Jul 2011 05:46:51 +0000'), 'klout' => array('score' => 45, 'network' => 55, 'amplification' => 17, 'true_reach' => 31, 'slope' => 0, 'class' => 'Networker'), 'peerindex' => array('score' => 30), 'language' => array('tag' => 'da')))), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $interactions = $def->getBuffered(); $this->assertEquals($response['data']['stream'], $interactions, 'Buffered interactions are not as expected'); }
// Include the DataSift library require dirname(__FILE__) . '/../lib/datasift.php'; // Include the configuration - put your username and API key in this file require dirname(__FILE__) . '/../config.php'; // Authenticate echo "Creating user...\n"; $user = new DataSift_User(USERNAME, API_KEY); // Create the definition $csdl = 'interaction.content contains "football"'; echo "Creating definition...\n {$csdl}\n"; $definition = new DataSift_Definition($user, $csdl); // Get buffered interactions until we've had 10 echo "Getting buffered interactions...\n--\n"; $num = 10; $from_id = false; do { $interactions = $definition->getBuffered($num, $from_id); foreach ($interactions as $interaction) { echo 'Type: ' . $interaction['interaction']['type'] . "\n"; echo 'Content: ' . $interaction['interaction']['content'] . "\n--\n"; $from_id = $interaction['interaction']['id']; $num--; } if ($num > 0) { // Sleep for 10 seconds before trying to get more echo "Sleeping...\n"; sleep(10); echo "--\n"; } } while ($num > 0); echo "Fetched 10 interactions, we're done.\n\n";