public function testHeartbeat()
 {
     $this->eventContainer->add(new \Iqu\Sdk\Event\Heartbeat($this->identifiers));
     $this->assertTrue($this->transportContainer->send($this->eventContainer));
     $data = $this->readTmpFiles();
     $data = json_decode(array_shift($data));
     $this->assertEquals(getenv('API_KEY'), $data->api_key);
     $this->assertEquals(1, sizeof($data->data));
     $eventData = array_shift($data->data);
     $this->assertAttributeEquals($this->uniqueSdkId, 'iqu_sdk_id', $eventData->identifiers);
     $this->assertEquals('heartbeat', $eventData->event->type);
     $this->assertGreaterThanOrEqual($this->startTime, strtotime($eventData->event->timestamp));
 }
 public function send(Event_Container $events)
 {
     $result = false;
     $path = $this->createSubPath($this->path, $events->getApiKey(), time());
     $fp = fopen($path . uniqid(mt_rand()), 'a');
     if ($fp) {
         flock($fp, LOCK_EX);
         $result = fputs($fp, json_encode(array('api_key' => $events->getApiKey(), 'data' => $events->getData())));
         fflush($fp);
         flock($fp, LOCK_UN);
         fclose($fp);
     }
     return $result !== false;
 }
 public function send(Event_Container $events)
 {
     $apiKey = $events->getApiKey();
     $data = $events->getData();
     $data = json_encode($data);
     $signature = hash_hmac('sha512', $data, $events->getSecretKey());
     $requestSuccessful = false;
     $try = 0;
     do {
         $try++;
         $response = $this->sendReal($data, $apiKey, $signature);
         if ($response) {
             $response = json_decode($response);
             if ($response && isset($response->status) && $response->status === 'ok') {
                 $requestSuccessful = true;
             }
         }
     } while ($requestSuccessful !== true && $try <= $this->retryCount);
     return $requestSuccessful;
 }