Пример #1
0
 /**
  * Create a library document from a local file, then create a widget for that document. If successful it returns the
  * url to the widget. You can use $this->getResponse() to get the widget object.
  * @param $fileName
  * @param $widgetName
  * @return bool|string
  */
 public function createLibraryDocumentWidgetFromLocalFile($fileName, $widgetName)
 {
     $libraryDocument = new LibraryDocument($this->getToken(), $this->getTransport());
     $libraryDocumentId = $libraryDocument->createFromLocalFile($fileName, basename($fileName), 'DOCUMENT');
     if ($libraryDocumentId === false) {
         $this->response = $libraryDocument->getResponse();
         $this->errorMessages = $libraryDocument->getErrorMessages();
         return false;
     }
     $this->widget = new Widgets($this->getToken(), $this->getTransport());
     $fileInfo = new WidgetFileInfo();
     $fileInfo->setLibraryDocumentId($libraryDocumentId);
     $widgetCreationInfo = new WidgetCreationInfo($widgetName, $this->getSignatureFlow(), $fileInfo);
     $widgetRequest = new WidgetCreationRequest($widgetCreationInfo, new InteractiveOptions());
     try {
         $this->response = $this->widget->create($widgetRequest);
     } 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->getUrl();
 }
Пример #2
0
 public function testFormData()
 {
     $documentId = substr(md5(time()), 8) . '.csv';
     $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.csv';
     $stream = Stream::factory(file_get_contents($sampleFile));
     $mock = new Mock([new Response(200, ['Content-Type' => 'text/csv', 'Content-Length' => filesize($sampleFile)], $stream)]);
     $client->getEmitter()->attach($mock);
     $widget = new Widgets('12335', $transport);
     file_put_contents($file, $stream->__toString());
     $response = $widget->formData('123kf', $file);
     $this->assertTrue($response);
 }