/**
  * Prints the response from SmartCloud or IBM Connections on Premise.
  *
  * @param unknown $response
  */
 public function outputResponse($response, $url)
 {
     $store = SBTCredentialStore::getInstance();
     if ($response->getStatusCode() == 200) {
         if (isset($_REQUEST["isAuthenticated"]) && $settings->getAuthenticationMethod() == "basic") {
             $result = array('status' => $response->getStatusCode(), 'result' => $response->getStatusCode() == 401 ? false : true);
             print_r(json_encode($result));
         } else {
             foreach ($response->getHeaderLines() as $h) {
                 if (strpos($h, "Content-Type") === 0) {
                     header($h, TRUE);
                 }
             }
             header(':', true, $response->getStatusCode());
             header('X-PHP-Response-Code: ' . $response->getStatusCode(), true, $response->getStatusCode());
             if (isset($_REQUEST['actionType']) && $_REQUEST['actionType'] == 'download' || strpos($url, '/media/') != false && strpos($url, '/document/') != false) {
                 $headers = $response->getHeaders();
                 header('Content-Description: File Transfer');
                 header('Content-Type: application/octet-stream');
                 header('Content-Disposition: ' . $headers['content-disposition']);
                 header('Content-Transfer-Encoding: binary');
                 //changed to chunked
                 header('Expires: 0');
                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                 header('Pragma: public');
             }
             print_r($response->getBody(TRUE));
         }
     } else {
         if ($response->getStatusCode() == 302) {
             $headers = $response->getHeaders();
             $this->route($headers['location']);
         } else {
             if ($response->getStatusCode() == 201) {
                 $result = array('status' => 201, 'result' => true);
                 print_r(json_encode($result));
             } else {
                 if ($response->getStatusCode() == 400) {
                     echo "400 - Bad Request";
                     print_r($response->getBody(TRUE));
                 } else {
                     if ($response->getStatusCode() == 401 || $response->getStatusCode() == '401oauth_token_expired') {
                         if (isset($_GET['endpointName'])) {
                             $store->deleteOAuthCredentials($_GET['endpointName']);
                             $store->deleteBasicAuthCredentials($_GET['endpointName']);
                         } else {
                             $store->deleteOAuthCredentials();
                             $store->deleteBasicAuthCredentials();
                         }
                         print_r($response->getStatusCode());
                     } else {
                         print_r($response->getBody(TRUE));
                     }
                 }
             }
         }
     }
 }
 /**
  * Parse binary frame.
  * 
  * @param unknown $frame
  * @return stdClass | array | 
  */
 public function parseBinaryFrame($frame)
 {
     $data = NULL;
     $frameBody = NULL;
     $traceId = NULL;
     // check frame flags
     $flagStatus = $this->_checkFrameFlags($frame->getFlag());
     // do we need to decompress
     // @TODO need to add check to see which compression has been used, can't assume snappy
     // all the time...
     if ($flagStatus->compression) {
         $frameBody = snappy_uncompress($frame->getBody());
     } else {
         $frameBody = $frame->getBody();
     }
     // do we need to grab a tracing id
     if ($flagStatus->tracing) {
         $traceId = $this->parseUuid($frameBody);
     }
     switch ($frame->getOpcode()) {
         case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_ERROR:
             $data = $this->parseError($frameBody);
             break;
         case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_SUPPORTED:
             $data = $this->parseStringMultimap($frameBody);
             break;
         case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_RESULT:
             $data = $this->parseResult($frameBody);
             break;
         case \McFrazier\PhpBinaryCql\CqlConstants::FRAME_OPCODE_AUTHENTICATE:
             $data = $this->parseString($frameBody);
             break;
     }
     // add the tracing id... if present
     if ($traceId) {
         $data->traceId = $traceId;
     }
     return $data;
 }