public function testObtener()
 {
     $autorization = sprintf("BASIC  + window.btoa(%s + :xxx)", "asdasdasdas");
     $options = array('body' => array(), 'config' => array(), 'headers' => array("Authorization" => "BASIC  + window.btoa(key + :xxx)"));
     $compania = new Compania();
     $compania->__set("apiKey", "cat952yellow");
     $compania->obtener();
     $response = $compania->__get("response");
     $this->assertTrue($response['status'] == 'exito');
 }
    // create a log channel
    $log = new Logger(basename(__FILE__, ".php"));
    $log->pushHandler(new StreamHandler(dirname(dirname(__FILE__)) . '/logs/your.log', Logger::DEBUG));
    /*	$log->pushProcessor(function ($record) {
    	    $record['extra']['dummy'] = 'Hello world!';
    	
    	    return $record;
    	});
    	
     * 
     */
    // add records to the log
    $log->info('Inicializando proceso ', array("linea " => __LINE__));
    $pdo = new \Slim\PDO\Database(DSN_, USR_, PASSWD_);
    $compania = new Compania();
    $compania->__set("apiKey", APIKEY_);
    $compania->obtener();
    $response = $compania->__get("response");
    if ($response['status'] == 'exito') {
        foreach ($response["body"] as $key => $obj) {
            $log->info(print_r($obj, true));
            $insertStatement = $pdo->insert(array('id', 'name', 'industry', 'website', 'country', 'countrycode', 'cid', 'tagid', 'parent_type', 'parentid'))->into('lkp_companies')->values(array($obj->id, $obj->name, $obj->industry, $obj->website, $obj->country, $obj->countrycode, $obj->cid, 123, 'lkp_companies', $obj->id));
            $insertId = $insertStatement->execute();
        }
        $log->info("Proceso Complento");
    } else {
        $log->error("Respuesta erronea");
        $log->error($response['message']);
    }
} catch (\PDOException $e) {
    $log->error($e->getMessage());
 public function obtener()
 {
     try {
         $compania = new Compania();
         $compania->__set("apiKey", APIKEY_);
         $this->log->addInfo("Inicio flujo de comanias", array(basename(__FILE__) . "::" . __LINE__));
         $compania->obtener();
         $response = $compania->__get("response");
         if ($response['status'] == "exito" && count($response['body']) > 0) {
             $this->log->addInfo("Respuesta de api exitosa", array(basename(__FILE__) . "::" . __LINE__));
             $values = array();
             $pdo = new \Slim\PDO\Database(BD_DNS_, BD_USER_, BD_PWD_);
             //Conexion::getInstance();
             foreach ($response['body'] as $key => $value) {
                 $keys = array();
                 $insertValue = array();
                 foreach ($value as $keyB => $valueB) {
                     array_push($keys, $keyB);
                     array_push($insertValue, empty($valueB) || $valueB == '' ? 0 : $valueB);
                 }
                 // INSERT INTO users ( id , usr , pwd ) VALUES ( ? , ? , ? )
                 $this->log->addDebug(print_r($keys, true), array(basename(__FILE__) . "::" . __LINE__));
                 $this->log->addDebug(print_r($insertValue, true), array(basename(__FILE__) . "::" . __LINE__));
                 $insertStatement = $pdo->insert($keys)->into('lkp_companies')->values($insertValue);
                 $insertId = $insertStatement->execute();
                 $this->insertRel($value);
             }
         }
     } catch (PDOException $e) {
         $this->log->addError("Error de BD", array(basename(__FILE__) . "::" . __LINE__));
         $this->log->addError($e->getMessage(), array(basename(__FILE__) . "::" . __LINE__));
     } catch (\Excetion $e) {
         $this->log->addError("Inesperado ", array(basename(__FILE__) . "::" . __LINE__));
         $this->log->addError($e->getMessage(), array(basename(__FILE__) . "::" . __LINE__));
     }
 }