Skip to content

Commit

Permalink
set new feature for set timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
maulidannashuha committed Oct 17, 2023
1 parent de0f402 commit 4559702
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
31 changes: 24 additions & 7 deletions src/ESignBsre.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class ESignBsre
private $file;
private $fileName;
private $view = 'invisible';
private $timeout;

public function __construct($baseUrl, $username, $password){
public function __construct($baseUrl, $username, $password, $timeout=1){
$this->baseUrl = $baseUrl;

$this->http = new GuzzleClient();
$this->username = $username;
$this->password = $password;
$this->timeout = $timeout;
}

public function setFile($file, $fileName){
Expand All @@ -30,11 +32,18 @@ public function setFile($file, $fileName){
return $this;
}

public function setTimeout($timeout){
$this->timeout = $timeout;

return $this;
}

public function sign($nik, $passphrase)
{
try {
$response = $this->http->request('POST', "{$this->getBaseUrl()}/api/sign/pdf", [
'auth' => $this->getAuth(),
'timeout' => $this->timeout,
'multipart' => [
[
'name' => 'file',
Expand All @@ -55,18 +64,21 @@ public function sign($nik, $passphrase)
],
],
]);
}catch (\Exception $e) {
}catch(\GuzzleHttp\Exception\ConnectException $e){
return new ESignBsreResponse($e);
} catch (\Exception $e) {
$response = $e->getResponse();
}

return new ESignBsreResponse($response);
return (new ESignBsreResponse())->setFromResponse($response);
}

public function verification()
{
try {
$response = $this->http->request('POST', "{$this->getBaseUrl()}/api/sign/verify", [
'auth' => $this->getAuth(),
'timeout' => $this->timeout,
'multipart' => [
[
'name' => 'signed_file',
Expand All @@ -75,23 +87,28 @@ public function verification()
],
]
]);
}catch (\Exception $e) {
}catch(\GuzzleHttp\Exception\ConnectException $e){
return new ESignBsreResponse($e);
} catch (\Exception $e) {
$response = $e->getResponse();
}

return new ESignBsreResponse($response);
return (new ESignBsreResponse())->setFromResponse($response);
}

public function statusUser($nik) {
try {
$response = $this->http->request('GET', "{$this->getBaseUrl()}/api/user/status/$nik", [
'auth' => $this->getAuth()
'auth' => $this->getAuth(),
'timeout' => $this->timeout,
]);
} catch(\GuzzleHttp\Exception\ConnectException $e){
return (new ESignBsreResponse())->setFromExeption($e, ESignBsreResponse::STATUS_TIMEOUT);
} catch (\Exception $e) {
$response = $e->getResponse();
}

return new ESignBsreResponse($response);
return (new ESignBsreResponse())->setFromResponse($response);
}

private function getAuth(){
Expand Down
11 changes: 7 additions & 4 deletions src/ESignBsreResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ class ESignBsreResponse
private $errors;
private $data;
private $response;
private const STATUS_OK = 200;
public const STATUS_OK = 200;
public const STATUS_TIMEOUT = 408;

public function __construct($response)
{
$this->setFromResponse($response);
public function setFromExeption($error, $status){
$this->status = $status;
$this->errors = $error->getMessage();

return $this;
}

public function setFromResponse($response){
Expand Down

0 comments on commit 4559702

Please sign in to comment.