/** * create a transientDocument from a local file. If successful, it returns the transientDocumentId. * @param $filename * @param null $mimeType * @return bool|string */ public function create($filename, $mimeType = null) { $this->transientDocument = new TransientDocuments($this->getToken(), $this->getTransport()); try { $this->response = $this->transientDocument->create($filename, $mimeType); } 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->getTransientDocumentId(); }
public function testCreateDocument() { $transport = new \Echosign\Transports\GuzzleTransport(); $client = $transport->getClient(); $docId = md5(time()); $json = ['transientDocumentId' => $docId]; $stream = Stream::factory(json_encode($json)); $mock = new Mock([new Response(200, ['content-type' => 'application/json'], $stream)]); $client->getEmitter()->attach($mock); $td = new TransientDocuments('12345', $transport); // create a crap sample file. $file = tempnam(sys_get_temp_dir(), 'TMP'); $fp = fopen($file, 'w+'); fwrite($fp, "hey look, I just work here okay?"); fclose($fp); $response = $td->create($file); $this->assertInstanceOf('Echosign\\Responses\\TransientDocumentResponse', $response); $this->assertEquals($docId, $response->getTransientDocumentId()); }