public function sendRequest($action, $query, $type = 'GET')
 {
     $result = "";
     $request_url = self::$path . '?action=' . $action;
     if ($query != NULL) {
         $json_query = json_encode($query);
         $request_url .= '&query=' . urlencode($json_query);
     }
     $curl_handle = curl_init();
     curl_setopt($curl_handle, CURLOPT_URL, $request_url);
     if ($type == 'GET') {
         curl_setopt($curl_handle, CURLOPT_HTTPGET, 1);
     }
     // prevent output of response contents to STDOUT
     curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
     // prevent self-signed SSL certificate errors.  Remove in production environments.
     curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
     // set authentication headers
     curl_setopt($curl_handle, CURLOPT_HTTPHEADER, VolunteerMatchAPI::getHTTPHeadersForAuthenticationRequest());
     if (!($response = curl_exec($curl_handle))) {
         $error = self::$errorMap["http_" . $httpStatus];
         self::$errorMessage = $error ? $error : self::$defaultError;
     } else {
         self::$responseBody = $response;
     }
     self::$responseCode = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE);
     curl_close($curl_handle);
 }
 private function sendRequest($action, $query = NULL, $type = 'GET')
 {
     $headers_string = $_COOKIE['vmapi_session_headers'];
     if (!empty($headers_string)) {
         self::$lastHeaders = json_decode($headers_string);
     }
     if (empty(self::$lastHeaders)) {
         // need to recreate our headers
         $timestamp = time();
         $nonce = hash('sha1', openssl_random_pseudo_bytes(20));
         $date = date('Y-m-d\\TH:i:sO', $timestamp);
         $digest = base64_encode(hash('sha256', $nonce . $date . self::$key, TRUE));
         $header_array = array('Content-Type' => 'application/json', 'Authorization' => 'WSSE profile="UsernameToken"', 'X-WSSE' => 'UsernameToken Username="******", PasswordDigest="' . $digest . '", Nonce="' . $nonce . '", Created="' . $date . '"');
         self::$lastHeaders = $header_array;
         // by default, expire headers in 10 minutes
         setcookie('vmapi_session_headers', json_encode(self::$lastHeaders), $timestamp + 600, '/');
     }
     $json_query = json_encode($query);
     //print_r($json_query);
     $url = self::$path;
     $url .= '?action=' . $action;
     if ($query != NULL) {
         $url .= '&query=' . urlencode($json_query);
     }
     // upon reviewing the code for this class, drupal_http_request() is the only method
     // dependant upon drupal. in order to make the entire class drupal-independant
     // we would have to use a native PHP method for sending HTTP requests.
     self::$lastResponse = drupal_http_request($url, self::$lastHeaders, $type);
     if (self::$lastResponse->code > 200) {
         print_r(self::$lastResponse);
     }
 }