go( 'POST', $api, $apiEndpoint, $postData); } public function get( $api, $apiEndpoint, $postData = array() ) { return $this->go( 'GET', $api, $apiEndpoint, $postData); } public function go( $method, $api, $apiEndpoint, $postData = array() ) { $url = $this->baseURL . '/' . $api . '/' . $apiEndpoint; // ================================= $ch = curl_init(); if( 'POST' === $method) { curl_setopt( $ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_POSTFIELDS, json_encode( $postData) ); } elseif( 'GET' === $method) { $url .= '?q=' . urlencode( json_encode( $postData) ); curl_setopt( $ch, CURLOPT_HTTPGET, true); } else { //unknown method: return false; } curl_setopt( $ch, CURLOPT_URL, $url); curl_setopt( $ch, CURLOPT_HEADER, false); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 4); curl_setopt( $ch, CURLOPT_TIMEOUT, 10); $headerFields = array( 'Accept: application/json', 'Content-Type: application/json', 'UserBridge-Version: ' . $this->apiVersion, 'Authorization: Bearer ' . $this->accountAPIAccessToken ); curl_setopt( $ch, CURLOPT_HTTPHEADER, $headerFields); $result = curl_exec( $ch); // ================================= // ================================ $response = array( 'http_code' => curl_getinfo( $ch, CURLINFO_HTTP_CODE), ); if( empty( $result)) { $response['errno'] = curl_errno( $ch); $response['error'] = curl_error( $ch); } else { $response['json'] = json_decode( $result, true); } // ================================ curl_close( $ch); return $response; } } ?>