Exemplo n.º 1
0
 /**
  * @param \Pipe\Organization $org
  * @throws \Exception
  */
 public function saveToPipe(\Pipe\Organization $org)
 {
     $postData = array('name' => $org->getName(), 'owner_id' => Config::get('pipedrive')['org_owner_id'], 'visible_to' => $org::VISIBLE_TO_COMPANY);
     $this->log->write('Saving ' . print_r($postData, true) . 'to pipe drive');
     try {
         $responseData = (new PipeApi())->makeRequest($postData, 'organizations');
         $response = json_decode($responseData, true);
     } catch (\Exception $e) {
         $this->logAndForwardException($e);
     }
     $this->log->write('Response' . print_r($response, true));
     if ($response) {
         if (!$response['success']) {
             throw new \Exception($response['error']);
         } else {
             $org->setPipeId($response['data']['id']);
         }
     } else {
         throw new \Exception('No RESPONSE!');
     }
     //save daughters
     if (count($org->getDaughters())) {
         foreach ($org->getDaughters() as $daughter) {
             $this->saveToPipe($daughter);
         }
     }
 }
Exemplo n.º 2
0
 public function run()
 {
     $request = $_REQUEST['_url'];
     if (in_array($request, array_keys(Config::get('requestMap')))) {
         $controllerName = '\\Pipe\\Controller\\' . Config::get('requestMap')[$request];
         (new $controllerName())->setRequestType($_SERVER['REQUEST_METHOD'])->setDb($this->db)->run();
     } else {
         echo json_encode(array('success' => false, 'error' => "Unknown request {$request}"));
     }
 }
Exemplo n.º 3
0
 public function getCurl(array $requestData = null, $endPoint, $requestType = PipeApi::REQUEST_POST)
 {
     $this->requestUrl = Config::get('pipedrive')['api_url'] . $endPoint . '?api_token=' . Config::get('pipedrive')['api_token'];
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $this->requestUrl);
     switch ($requestType) {
         case PipeApi::REQUEST_POST:
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $requestData);
             break;
         case PipeApi::REQUEST_DELETE:
             curl_setopt($curl, CURLOPT_POSTFIELDS, is_array($requestData) ? http_build_query($requestData) : $requestData);
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
             break;
     }
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 100);
     curl_setopt($curl, CURLOPT_TIMEOUT, 100);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     return $curl;
 }
Exemplo n.º 4
0
<?php

//ini_set('display_errors', 1);
error_reporting(E_ALL);
define('ROOT_PATH', realpath(dirname(__FILE__)));
require_once 'config/config.php';
require_once 'source/Utils/AutoLoad.class.php';
$autoload = new \Utils\Autoload();
$autoload->addNameSpaceMap(ROOT_PATH . '/source');
\Utils\Config::init($config);
$DB = new \Utils\DB(\Utils\Config::get('mysql'));
Exemplo n.º 5
0
/**
 * @param $key
 * @param mixed $default
 * @return mixed
 */
function setting($key, $default = null)
{
    return Config::fast($key, $default);
}
Exemplo n.º 6
0
<?php

namespace Test;

define('ROOT_PATH', './');
require_once ROOT_PATH . 'config/config.php';
require_once ROOT_PATH . 'source/Utils/AutoLoad.class.php';
$autoload = new \Utils\Autoload();
$autoload->addNameSpaceMap(ROOT_PATH . '/unittest');
\Utils\Config::init($config);