/** * Verifies behaviour when adding a datapoint to the response. * * @return void */ public function testAddDataEntry() { $actual = new HerculesResponse('/endpoint'); $actual->addDataEntry(['a data point']); $actual->addDataEntry(['a key' => 'a keyed data point']); $actual->addDataEntry(['another data point']); $expected = ['a data point', 'a key' => 'a keyed data point', 'another data point']; $this->assertEquals($expected, $actual->getData()); }
/** * Parse the results from Elasticsearch for the Hampton Crime data set. * * @param array $results The json data from the request. * @param HerculesResponse $response The response object to append data to. * * @return HerculesReponse The response object all pretty. */ private function parseResults(array $results, HerculesResponse $response) { // Parse the results. $resultArray = $results['hits']; foreach ($resultArray as $key => $value) { $id = $value['_id']; $offense = $value['_source']['offense']; $category = $value['_source']['category']; $class = $value['_source']['class']; $occured = new \DateTime($value['_source']['occurred']); $city = $value['_source']['city']; $location = $value['_source']['location']; if (isset($occured) && gettype($location) === 'array') { $datapoint = new DataPoint($id, $offense, $occured, $city, $location, $category, $class); $response->addDataEntry($datapoint->toArray()); } } return $response; }