/** * 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 testCreate() { $json = '{ "embeddedCode": "<script type=\'text/javascript\' language=\'JavaScript\' src=\'https://poweresq.echosign.com/embed/account/sendProgress?aid=XJ28WY42H5E2T6M&noChrome=true\'></script>", "libraryDocumentId": "2AAABLblqZhCLqOm1s_gWpTxax3wK6csrs22iQOYyLOZHLLnOl2FeL3IxFEkgO09JYWczAt_57Lw*", "url": "https://test.echosign.com/account/sendProgress?aid=XJ28WY42H5E2T6M" }'; $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $stream = Stream::factory($json); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $doc = new LibraryDocuments('1234', $transport); $fileInfo = new \Echosign\RequestBuilders\Agreement\FileInfo(); $fileInfo->setLibraryDocumentId("balls"); $docCreationinfo = new \Echosign\RequestBuilders\LibraryDocument\LibraryDocumentCreationInfo('test', 'DOCUMENT', $fileInfo, 'USER'); $docCreate = new \Echosign\RequestBuilders\LibraryCreationInfo($docCreationinfo, new \Echosign\RequestBuilders\Agreement\InteractiveOptions()); $response = $doc->create($docCreate); $this->assertInstanceOf('Echosign\\Responses\\LibraryDocumentCreationResponse', $response); $this->assertEquals("2AAABLblqZhCLqOm1s_gWpTxax3wK6csrs22iQOYyLOZHLLnOl2FeL3IxFEkgO09JYWczAt_57Lw*", $response->getLibraryDocumentid()); }