/** * @param $pathToFile * @param null $mimeType * @return TransientDocumentResponse */ public function create($pathToFile, $mimeType = null) { if (!file_exists($pathToFile)) { throw new \RuntimeException("{$pathToFile} does not exist"); } $this->pathToFile = $pathToFile; $this->fileName = basename($pathToFile); $this->mimeType = $this->detectMimeType($pathToFile, $mimeType); $request = new PostRequest($this->getOAuthToken(), $this->getRequestUrl()); $request->setJsonRequest(false); $request->setBody(['File-Name' => $this->fileName, 'Mime-Type' => $this->mimeType, 'File' => fopen($this->pathToFile, 'r')]); $this->setRequest($request); $this->logDebug("Creating POST request to " . $this->getRequestUrl(), [$this->pathToFile, $this->mimeType]); $transport = $this->getTransport(); $response = $transport->handleRequest($request); if (!is_array($response)) { $this->responseReceived = $response; throw new \RuntimeException('Bad response received! Please inspect responseReceived'); } $this->logDebug("response", $response); return new TransientDocumentResponse($response); }
/** * assumes JSON request and JSON response. Most requests are like this, so this simplifies the whole process.It * bases the url generation on calling $this->getRequestUrl() internally. So make sure * you set the api request path first. $this->setApiRequestUrl( 'agreementAssetEvents' ) for example. * @param array $data * @param null $userId * @param null $userEmail * @return mixed */ protected function simplePostRequest(array $data, $userId = null, $userEmail = null) { $request = new PostRequest($this->getOAuthToken(), $this->getRequestUrl()); if ($userId && $userEmail) { $request->setHeader('x-user-id', $userId); $request->setHeader('x-user-email', $userEmail); } $request->setBody($data); $this->setRequest($request); $this->logDebug("POST: " . $this->getRequestUrl()); $transport = $this->getTransport(); $response = $transport->handleRequest($request); if (!is_array($response)) { $this->responseReceived = $response; throw new \RuntimeException('Bad response received! Please inspect responseReceived'); } $this->logDebug("response", $response); return $response; }