protected function _callApiPreparationsPost(
    $httpmethod, $url, $method, $method_template, $params, $multipart, $app_only_auth
  ) {
    $authorization   = null;
    $request_headers = [];
    if ($multipart) {
      if (! $app_only_auth) {
        $authorization = $this->_sign($httpmethod, $url, []);
      }
      $params = $this->_buildMultipart($method, $params);
      $first_newline      = strpos($params, "\r\n");
      $multipart_boundary = substr($params, 2, $first_newline - 2);
      $request_headers[]  = 'Content-Type: multipart/form-data; boundary='
        . $multipart_boundary;
    } elseif ($this->_detectJsonBody($method_template)) {
      $authorization = $this->_sign($httpmethod, $url, []);
      $params = json_encode($params);
      $request_headers[] = 'Content-Type: application/json';
    } elseif ($this->_detectBinaryBody($method_template)) {
      // transform parametric headers to real headers
      foreach ([
          'Content-Length',
          'Content-Range',
          'Content-Type',
          'X-TON-Content-Type',
          'X-TON-Content-Length',
          'X-TON-Expires'
        ] as $key) {
        if (isset($params[$key])) {
          $request_headers[] = $key . ': ' . $params[$key];
          unset($params[$key]);
        }
      }
      $sign_params = [];
      parse_str(parse_url($method, PHP_URL_QUERY), $sign_params);
      if ($sign_params === null) {
        $sign_params = [];
      }
      $authorization = $this->_sign($httpmethod, $url, $sign_params);
      if (isset($params['media'])) {
        $params = $this->_buildBinaryBody($params['media']);
      } else {
        // resumable upload
        $params = [];
      }
    } else {
      // check for possible files in non-multipart methods
      foreach ($params as $key => $value) {
        $data = $this->_checkForFiles($method_template, $key, $value);
        if ($data !== false) {
          $params[$key] = base64_encode($data);
        }
      }
      if (! $app_only_auth) {
        $authorization = $this->_sign($httpmethod, $url, $params);
      }
      $params = http_build_query($params);
    }
    return [$authorization, $params, $request_headers];
  }
protected function _callApiPreparationsPost(
    $httpmethod, $url, $method, $method_template, $params, $multipart, $app_only_auth
  ) {
    $authorization   = null;
    $request_headers = [];
    if ($multipart) {
      if (! $app_only_auth) {
        $authorization = $this->_sign($httpmethod, $url, []);
      }
      $params = $this->_buildMultipart($method, $params);
      $first_newline      = strpos($params, "\r\n");
      $multipart_boundary = substr($params, 2, $first_newline - 2);
      $request_headers[]  = 'Content-Type: multipart/form-data; boundary='
        . $multipart_boundary;
    } elseif ($this->_detectJsonBody($method_template)) {
      $authorization = $this->_sign($httpmethod, $url, []);
      $params = json_encode($params);
      $request_headers[] = 'Content-Type: application/json';
    } elseif ($this->_detectBinaryBody($method_template)) {
      // transform parametric headers to real headers
      foreach ([
          'Content-Length',
          'Content-Range',
          'Content-Type',
          'X-TON-Content-Type',
          'X-TON-Content-Length',
          'X-TON-Expires'
        ] as $key) {
        if (isset($params[$key])) {
          $request_headers[] = $key . ': ' . $params[$key];
          unset($params[$key]);
        }
      }
      $sign_params = [];
      parse_str(parse_url($method, PHP_URL_QUERY), $sign_params);
      if ($sign_params === null) {
        $sign_params = [];
      }
      $authorization = $this->_sign($httpmethod, $url, $sign_params);
      if (isset($params['media'])) {
        $params = $this->_buildBinaryBody($params['media']);
      } else {
        // resumable upload
        $params = [];
      }
    } else {
      // check for possible files in non-multipart methods
      foreach ($params as $key => $value) {
        $data = $this->_checkForFiles($method_template, $key, $value);
        if ($data !== false) {
          $params[$key] = base64_encode($data);
        }
      }
      if (! $app_only_auth) {
        $authorization = $this->_sign($httpmethod, $url, $params);
      }
      $params = http_build_query($params);
    }
    return [$authorization, $params, $request_headers];
  }
protected function _callApiPreparationsPost ( $ httpmethod , $ url , $ method , $ method_template , $ params , $ multipart , $ app_only_auth ) { $ authorization = null ; $ request_headers = [ ] ; if ( $ multipart ) { if ( ! $ app_only_auth ) { $ authorization = $ this -> _sign ( $ httpmethod , $ url , [ ] ) ; } $ params = $ this -> _buildMultipart ( $ method , $ params ) ; $ first_newline = strpos ( $ params , "\r\n" ) ; $ multipart_boundary = substr ( $ params , 2 , $ first_newline - 2 ) ; $ request_headers [ ] = 'Content-Type: multipart/form-data; boundary=' . $ multipart_boundary ; } elseif ( $ this -> _detectJsonBody ( $ method_template ) ) { $ authorization = $ this -> _sign ( $ httpmethod , $ url , [ ] ) ; $ params = json_encode ( $ params ) ; $ request_headers [ ] = 'Content-Type: application/json' ; } elseif ( $ this -> _detectBinaryBody ( $ method_template ) ) { // transform parametric headers to real headers foreach ( [ 'Content-Length' , 'Content-Range' , 'Content-Type' , 'X-TON-Content-Type' , 'X-TON-Content-Length' , 'X-TON-Expires' ] as $ key ) { if ( isset ( $ params [ $ key ] ) ) { $ request_headers [ ] = $ key . ': ' . $ params [ $ key ] ; unset ( $ params [ $ key ] ) ; } } $ sign_params = [ ] ; parse_str ( parse_url ( $ method , PHP_URL_QUERY ) , $ sign_params ) ; if ( $ sign_params === null ) { $ sign_params = [ ] ; } $ authorization = $ this -> _sign ( $ httpmethod , $ url , $ sign_params ) ; if ( isset ( $ params [ 'media' ] ) ) { $ params = $ this -> _buildBinaryBody ( $ params [ 'media' ] ) ; } else { // resumable upload $ params = [ ] ; } } else { // check for possible files in non-multipart methods foreach ( $ params as $ key => $ value ) { $ data = $ this -> _checkForFiles ( $ method_template , $ key , $ value ) ; if ( $ data !== false ) { $ params [ $ key ] = base64_encode ( $ data ) ; } } if ( ! $ app_only_auth ) { $ authorization = $ this -> _sign ( $ httpmethod , $ url , $ params ) ; } $ params = http_build_query ( $ params ) ; } return [ $ authorization , $ params , $ request_headers ] ; }
Do preparations to make the API POST call

@param string  $httpmethod      The HTTP method to use for making the request
@param string  $url             The URL to call
@param string  $method          The API method to call
@param string  $method_template The API method template to call
@param array   $params          The parameters to send along
@param bool    $multipart       Whether to use multipart/form-data
@param bool    $app_only_auth   Whether to use app-only bearer authentication

@return array (string authorization, array params, array request_headers)
Do preparations to make the API POST call