/** * Create a libraryDocument from a local file. If successful, it returns the libraryDocumentId. You can get the full * libraryDocument object with $this->getResponse() * @param $localFilename * @param $libraryFilename * @param $templateType * @param string $sharingMode * @return bool|string */ public function createFromLocalFile($localFilename, $libraryFilename, $templateType, $sharingMode = 'USER') { // first create a transient document $transientDocument = new TransientDocument($this->getToken(), $this->getTransport()); $transientDocumentId = $transientDocument->create($localFilename); if ($transientDocumentId === false) { $this->response = $transientDocument->getResponse(); $this->errorMessages = $transientDocument->getErrorMessages(); return false; } $this->libraryDocument = new LibraryDocuments($this->getToken(), $this->getTransport()); $fileInfo = new FileInfo(); $fileInfo->setTransientDocumentId($transientDocumentId); $docCreationInfo = new LibraryDocumentCreationInfo($libraryFilename, $templateType, $fileInfo, $sharingMode); $libCreationInfo = new LibraryCreationInfo($docCreationInfo, new InteractiveOptions()); try { $this->response = $this->libraryDocument->create($libCreationInfo); } catch (JsonApiResponseException $e) { $this->errorMessages[$e->getCode()] = sprintf('%s - %s', $e->getApiCode(), $e->getMessage()); return false; } catch (\Exception $e) { $this->errorMessages[$e->getCode()] = $e->getMessage(); return false; } return $this->response->getLibraryDocumentid(); }
public function testCombinedDocument() { $documentId = substr(md5(time()), 8) . '.pdf'; $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $documentId; $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); /* HTTP/1.1 200 OK Date: Fri, 30 Jan 2015 00:59:05 GMT Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 Last-Modified: Fri, 21 Nov 2014 20:57:09 GMT ETag: "2265-50864b0336560" Accept-Ranges: bytes Content-Length: 8805 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: application/pdf */ $sampleFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files/sample.pdf'; $stream = Stream::factory(file_get_contents($sampleFile)); $mock = new Mock([new Response(200, ['Content-Type' => 'application/pdf', 'Content-Length' => filesize($sampleFile)], $stream)]); $client->getEmitter()->attach($mock); $agreement = new LibraryDocuments('12335', $transport); file_put_contents($file, $stream->__toString()); $response = $agreement->combinedDocument('123kf', $file); $this->assertTrue($response); }