static function applyRequestOptions(\Psr\Http\Message\RequestInterface $request, array $requestOptions) {
        if(isset($requestOptions['multipart'])) {
            $multipart = new \RingCentral\Psr7\MultipartStream($requestOptions['multipart']);
            
            $request = $request->withBody($multipart)
                            ->withHeader('Content-Type', 'multipart/form-data; boundary="'.$multipart->getBoundary().'"');
        }
        
        if(isset($requestOptions['json'])) {
            $resource = \fopen('php://temp', 'r+');
            if($resource === false) {
                throw new \RuntimeException('Unable to create stream for JSON data');
            }
            
            $json = \json_encode($requestOptions['json']);
            if($json === false) {
                throw new \RuntimeException('Unable to encode json. Error: '.\json_last_error_msg());
            }
            
            \fwrite($resource, $json);
            \fseek($resource, 0);
            
            $stream = new \RingCentral\Psr7\Stream($resource, array('size' => \strlen($json)));
            $request = $request->withBody($stream);
            
            $request = $request->withHeader('Content-Type', 'application/json')
                            ->withHeader('Content-Length', \strlen($json));
        }
        
        if(isset($requestOptions['query'])) {
            $uri = $request->getUri()->withQuery($requestOptions['query']);
            $request = $request->withUri($uri);
        }
        
        if(isset($requestOptions['headers'])) {
            foreach($requestOptions['headers'] as $key => $val) {
                $request = $request->withHeader($key, $val);
            }
        }
        
        return $request;
    }