app = $app; $this->apiUrl = rtrim($apiUrl, '/') . '/'; $this->cURL = curl_init(); curl_setopt($this->cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'charset=utf-8')); curl_setopt($this->cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->cURL, CURLOPT_FOLLOWLOCATION, false); curl_setopt($this->cURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($this->cURL, CURLOPT_USERPWD, $user.':'.$pass); } /** * @param string $endpoint * @param string $method * @param array $data * @param string $params * * @param bool $asArray * * @return mixed */ public function call($endpoint, $method = self::METHODE_GET, $data = array(), $params='', $asArray = false) { $endpoint = rtrim($endpoint, '?') . '?'; $url = $this->apiUrl . $endpoint . $params; $dataString = json_encode($data); curl_setopt($this->cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'charset=utf-8')); curl_setopt($this->cURL, CURLOPT_URL, $url); curl_setopt($this->cURL, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($this->cURL, CURLOPT_POSTFIELDS, $dataString); $result = curl_exec($this->cURL); return json_decode($result,$asArray); } /** * @param string $bildpfad * @param string $bildtyp * @param string $bildname * * @return mixed */ public function imagecall($bildpfad, $bildtyp = 'image/png', $bildname = 'image') { $url = $this->apiUrl.'product_images'; $data = new CURLFile($bildpfad,$bildtyp,$bildname); $post = [ 'filename' => $bildname, 'upload_product_image' => $data ]; curl_setopt($this->cURL, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data;')); curl_setopt($this->cURL, CURLOPT_URL, $url); curl_setopt($this->cURL, CURLOPT_CUSTOMREQUEST, self::METHODE_POST); curl_setopt($this->cURL, CURLOPT_POST,1); curl_setopt($this->cURL, CURLOPT_POSTFIELDS, $post); $result = curl_exec($this->cURL); return json_decode($result); } /** * @param $nachricht * @param string $dump */ public function GambioLog($nachricht, $dump = '') { if($this->protokoll){ $this->app->erp->LogFile($nachricht, print_r($dump, true)); } } /** * @param $protokoll */ public function setProtokoll($protokoll){ $this->protokoll = $protokoll; } }