Пример #1
0
 public function testObtener()
 {
     $autorization = sprintf("BASIC  + window.btoa(%s + :xxx)", "asdasdasdas");
     $options = array('body' => array(), 'config' => array(), 'headers' => array());
     $expense = new Expenses();
     $expense->__set("apiKey", "cat952yellow");
     //var_dump($project -> __get("response"));
     $expense->obtener();
     $response = $expense->__get("response");
     error_log(print_r($response, true));
     $this->assertTrue($response['status'] == 'exito');
     $this->assertGreaterThan(count($response['body']), 0);
 }
Пример #2
0
 public function obtener()
 {
     try {
         $compania = new Expenses();
         $compania->__set("apiKey", APIKEY_);
         $this->log->addInfo("Inicio flujo de Expenses", 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);
                 }
                 $this->log->addInfo(print_r($keys, true), array(basename(__FILE__) . "::" . __LINE__));
                 $this->log->addInfo(print_r($insertValue, true), array(basename(__FILE__) . "::" . __LINE__));
                 $insertStatement = $pdo->insert($keys)->into('lkp_expenses')->values($insertValue);
                 $insertId = $insertStatement->execute();
             }
         } else {
             $this->log->addInfo("Sin recursos encontrados", array(basename(__FILE__) . "::" . __LINE__));
         }
     } catch (PDOException $e) {
         $this->log->addInfo("Error de BD", array(basename(__FILE__) . "::" . __LINE__));
         $this->log->addInfo($e->getMessage(), array(basename(__FILE__) . "::" . __LINE__));
     } catch (\Exception $e) {
         $this->log->addInfo("Error de BD", array(basename(__FILE__) . "::" . __LINE__));
         $this->log->addInfo($e->getMessage(), array(basename(__FILE__) . "::" . __LINE__));
     }
 }