Skip to content

Commit

Permalink
new: add the function downloadFinalDocument() (#68)
Browse files Browse the repository at this point in the history
* new:  add the function downloadFinalDocument()

* fix: Config::DOCUMENT_FINAL_URL instead of string

Co-authored-by: Julien SCHERMANN <[email protected]>
  • Loading branch information
Snowbaha and julien-proxi authored Jun 13, 2022
1 parent 328d556 commit 196a161
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sdk/Eversign/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ public function startRequest() {
}
]);
}
else if($this->payLoad && is_array($this->payLoad) && array_key_exists("stream", $this->payLoad)) {
$response = $this->guzzleClient->request($this->httpType, $this->endPoint, [
'timeout' => $this->guzzleRequestTimeout,
'query' => $this->createQuery(),
'stream' => $this->payLoad["stream"],
'on_stats' => function (TransferStats $stats) use (&$effectiveUrl) {
$effectiveUrl = $stats->getEffectiveUri();
}
]);
}
else {
$requestOptions = [
'timeout' => $this->guzzleRequestTimeout,
Expand Down Expand Up @@ -236,7 +246,10 @@ public function startRequest() {
$body = $response->getBody();

if($this->payLoad && is_array($this->payLoad) && array_key_exists("sink", $this->payLoad)) {
return file_exists($this->payLoad["sink"]);
return file_exists($this->payLoad["sink"]);

} else if($this->payLoad && is_array($this->payLoad) && array_key_exists("stream", $this->payLoad)) {
return $body;
} else {
$responseJson = json_decode($body, true);
if(json_last_error() !== JSON_ERROR_NONE) {
Expand Down
26 changes: 26 additions & 0 deletions sdk/Eversign/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,32 @@ public function downloadDocumentToPath(Document $document, $path, $auditTrail =
return $request->startRequest();
}

public function downloadFinalDocument(Document $document, $auditTrail = 0, $onlyUrl = false, $documentId = "") {

$parameters = [
"business_id" => $this->selectedBusiness->getBusinessId(),
"document_hash" => $document->getDocumentHash(),
"audit_trail" => $auditTrail,
"document_id" => $documentId,
"url_only" => $onlyUrl
];

$payLoad = $onlyUrl ? null : ["stream" => false];

$request = new ApiRequest(
"GET",
$this->accessKey,
Config::DOCUMENT_FINAL_URL,
$onlyUrl ? "Eversign\Url" : "",
$parameters,
$payLoad,
$this->apiBaseUrl,
$this->apiRequestTimeout
);

return $request->startRequest();
}

/**
* Deletes the specified Document. Only works on Drafts and canceled Documents
* @param \Eversign\Document $document
Expand Down
46 changes: 46 additions & 0 deletions sdk/Eversign/Url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* The MIT License
*
* Copyright 2017 Patrick Leeb.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Eversign;

use JMS\Serializer\Annotation\Type;

class Url {

/**
* @var boolean $success
* @Type("boolean")
*/
public $success;

/**
* @var boolean $success
* @Type("string")
*/
public $url;


}

0 comments on commit 196a161

Please sign in to comment.