client) { $this->client = new IopClient($this->url,$this->appKey,$this->appSecret); } } function secure(){ if(!$this->client) { die(json_encode(array('error' => true, 'message' => 'No se ha establecido la conexión'))); } } function get($endpoint = '', $params = array()) { $this->secure(); $request = new IopRequest($endpoint,'GET'); if($params) { foreach($params as $k => $v) { $request->addApiParam($k,$v); } } try{ $result = $this->client->execute($request,$this->token); }catch(Exception $e) { return $this->error_control($e); } $resp = json_decode($result, true); return $this->response($resp); } function post($endpoint = '', $data = array()) { $this->secure(); $request = new IopRequest($endpoint); if($data) { foreach($data as $k => $v) { $request->addApiParam($k,$v); } } try{ $result = $this->client->execute($request, $this->token); }catch(Exception $e) { return $this->error_control($e); } $resp = json_decode($result, true); return $this->response($resp); } function response($result) { if(isset($result['data'])) { return $result['data']; }else{ //Control de errores return $this->error_control($result); } } function error_control($resp) { // die('
'.print_r($resp, true).''); if($resp->code != '0') { if(isset($resp->detail)) { $errors = $resp->detail; }else{ $errors = [$resp->message]; } return array( 'code' => $resp->code, 'errors' => $errors ); }else{ return array( 'code' => '-1', 'errors' => array($resp) ); } } function get_images_batch($batch_id) { return $this->get('/image/response/get', array('batch_id' => $batch_id)); } function get_brands($page) { $to = $page * 20; $from = $to - 20; return $this->get('/category/brands/query', array('start_row' => $from, "page_size" => $to)); } function get_orders($args = array()) { return $this->get('/orders/get', $args); } function get_order($args = array()) { return $this->get('/order/get', $args); } function get_orders_items($args = array()) { return $this->get('/order/items/get', $args); } function get_products($args = array()) { return $this->get('/products/get', $args); } } }