private function sendEntity($entity_name, array $data, $key_id)
    {
        $client = $this->getClient();
        $this->getLogger()->info('Sending new ' . $entity_name . '.');
        try {
            $this->getLogger()->info('Try to PUT data to existing ' . $entity_name . ' record.');
            $data[$key_id . '_uri'] = $data[$key_id];
            $client->getCommand('put' . $entity_name, $data)
                ->execute();
        } catch (ClientErrorResponseException $e) {
            if ($e->getResponse()->getStatusCode() === 404) {
                // The server doesn't exist yet. We need to POST it.
                $this->getLogger()->info($entity_name . ' was not found on PUT request. Doing POST to create it.');
                $client->getCommand('post' . $entity_name, $data)
                    ->execute();
            } else {
                // This is not a 404 error, throw the exception.
                throw $e;
            }
        }
        $this->getLogger()->info('The ' . $entity_name . ' information has been successfully sent.');
    }
private function sendEntity($entity_name, array $data, $key_id)
    {
        $client = $this->getClient();
        $this->getLogger()->info('Sending new ' . $entity_name . '.');
        try {
            $this->getLogger()->info('Try to PUT data to existing ' . $entity_name . ' record.');
            $data[$key_id . '_uri'] = $data[$key_id];
            $client->getCommand('put' . $entity_name, $data)
                ->execute();
        } catch (ClientErrorResponseException $e) {
            if ($e->getResponse()->getStatusCode() === 404) {
                // The server doesn't exist yet. We need to POST it.
                $this->getLogger()->info($entity_name . ' was not found on PUT request. Doing POST to create it.');
                $client->getCommand('post' . $entity_name, $data)
                    ->execute();
            } else {
                // This is not a 404 error, throw the exception.
                throw $e;
            }
        }
        $this->getLogger()->info('The ' . $entity_name . ' information has been successfully sent.');
    }
private function sendEntity ( $ entity_name , array $ data , $ key_id ) { $ client = $ this -> getClient ( ) ; $ this -> getLogger ( ) -> info ( 'Sending new ' . $ entity_name . '.' ) ; try { $ this -> getLogger ( ) -> info ( 'Try to PUT data to existing ' . $ entity_name . ' record.' ) ; $ data [ $ key_id . '_uri' ] = $ data [ $ key_id ] ; $ client -> getCommand ( 'put' . $ entity_name , $ data ) -> execute ( ) ; } catch ( ClientErrorResponseException $ e ) { if ( $ e -> getResponse ( ) -> getStatusCode ( ) === 404 ) { // The server doesn't exist yet. We need to POST it. $ this -> getLogger ( ) -> info ( $ entity_name . ' was not found on PUT request. Doing POST to create it.' ) ; $ client -> getCommand ( 'post' . $ entity_name , $ data ) -> execute ( ) ; } else { // This is not a 404 error, throw the exception. throw $ e ; } } $ this -> getLogger ( ) -> info ( 'The ' . $ entity_name . ' information has been successfully sent.' ) ; }
Send an entity.
Try put first if 404 create it with POST.

@param string $entity_name Entity name in CamelCase
@param array  $data        Entity data to send.
@param string $key_id      Key of data to use as an id for the request.
Send an entity . Try put first if 404 create it with POST .