public function testCompile_SuccessThenFailure() { $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'); try { $def->compile(); } catch (DataSift_Exception_CompileFailed $e) { $this->fail('CompileFailed: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } catch (DataSift_Exception_InvalidData $e) { $this->fail('InvalidData: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } catch (DataSift_Exception_APIError $e) { $this->fail('APIError: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } $this->assertEquals(testdata('definition_hash'), $def->getHash(), 'Hash is not correct'); // Now set the invalid definition in that same object $response = array('response_code' => 400, 'data' => array('error' => 'The target interactin.content does not exist'), 'rate_limit' => 200, 'rate_limit_remaining' => 150); DataSift_MockApiClient::setResponse($response); $def->set(testdata('invalid_definition')); $this->assertEquals($def->get(), testdata('invalid_definition'), 'Definition string not set correctly'); try { $def->compile(); $this->fail('CompileFailed exception expected, but not thrown'); } catch (DataSift_Exception_InvalidData $e) { // Do nothing because this is what's supposed to happen } catch (DataSift_Exception_APIError $e) { $this->fail('APIError: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } catch (Exception $e) { $this->fail('Unhandled exception: ' . $e->getMessage() . ' (' . $e->getCode() . ')'); } }
/** * Subscribe this endpoint to a Definition. * * @param DataSift_Definition $definition The definition to which to subscribe. * @param string $name A name for this subscription. * * @return DataSift_PushSubscription The new subscription. * @throws DataSift_Exception_InvalidData * @throws DataSift_Exception_AccessDenied * @throws DataSift_Exception_APIError */ public function subscribeDefinition($definition, $name) { return $this->subscribeStreamHash($definition->getHash(), $name); }
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'); }