Skip to content

Commit 4559702

Browse files
set new feature for set timeout
1 parent de0f402 commit 4559702

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/ESignBsre.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ class ESignBsre
1414
private $file;
1515
private $fileName;
1616
private $view = 'invisible';
17+
private $timeout;
1718

18-
public function __construct($baseUrl, $username, $password){
19+
public function __construct($baseUrl, $username, $password, $timeout=1){
1920
$this->baseUrl = $baseUrl;
2021

2122
$this->http = new GuzzleClient();
2223
$this->username = $username;
2324
$this->password = $password;
25+
$this->timeout = $timeout;
2426
}
2527

2628
public function setFile($file, $fileName){
@@ -30,11 +32,18 @@ public function setFile($file, $fileName){
3032
return $this;
3133
}
3234

35+
public function setTimeout($timeout){
36+
$this->timeout = $timeout;
37+
38+
return $this;
39+
}
40+
3341
public function sign($nik, $passphrase)
3442
{
3543
try {
3644
$response = $this->http->request('POST', "{$this->getBaseUrl()}/api/sign/pdf", [
3745
'auth' => $this->getAuth(),
46+
'timeout' => $this->timeout,
3847
'multipart' => [
3948
[
4049
'name' => 'file',
@@ -55,18 +64,21 @@ public function sign($nik, $passphrase)
5564
],
5665
],
5766
]);
58-
}catch (\Exception $e) {
67+
}catch(\GuzzleHttp\Exception\ConnectException $e){
68+
return new ESignBsreResponse($e);
69+
} catch (\Exception $e) {
5970
$response = $e->getResponse();
6071
}
6172

62-
return new ESignBsreResponse($response);
73+
return (new ESignBsreResponse())->setFromResponse($response);
6374
}
6475

6576
public function verification()
6677
{
6778
try {
6879
$response = $this->http->request('POST', "{$this->getBaseUrl()}/api/sign/verify", [
6980
'auth' => $this->getAuth(),
81+
'timeout' => $this->timeout,
7082
'multipart' => [
7183
[
7284
'name' => 'signed_file',
@@ -75,23 +87,28 @@ public function verification()
7587
],
7688
]
7789
]);
78-
}catch (\Exception $e) {
90+
}catch(\GuzzleHttp\Exception\ConnectException $e){
91+
return new ESignBsreResponse($e);
92+
} catch (\Exception $e) {
7993
$response = $e->getResponse();
8094
}
8195

82-
return new ESignBsreResponse($response);
96+
return (new ESignBsreResponse())->setFromResponse($response);
8397
}
8498

8599
public function statusUser($nik) {
86100
try {
87101
$response = $this->http->request('GET', "{$this->getBaseUrl()}/api/user/status/$nik", [
88-
'auth' => $this->getAuth()
102+
'auth' => $this->getAuth(),
103+
'timeout' => $this->timeout,
89104
]);
105+
} catch(\GuzzleHttp\Exception\ConnectException $e){
106+
return (new ESignBsreResponse())->setFromExeption($e, ESignBsreResponse::STATUS_TIMEOUT);
90107
} catch (\Exception $e) {
91108
$response = $e->getResponse();
92109
}
93110

94-
return new ESignBsreResponse($response);
111+
return (new ESignBsreResponse())->setFromResponse($response);
95112
}
96113

97114
private function getAuth(){

src/ESignBsreResponse.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ class ESignBsreResponse
88
private $errors;
99
private $data;
1010
private $response;
11-
private const STATUS_OK = 200;
11+
public const STATUS_OK = 200;
12+
public const STATUS_TIMEOUT = 408;
1213

13-
public function __construct($response)
14-
{
15-
$this->setFromResponse($response);
14+
public function setFromExeption($error, $status){
15+
$this->status = $status;
16+
$this->errors = $error->getMessage();
17+
18+
return $this;
1619
}
1720

1821
public function setFromResponse($response){

0 commit comments

Comments
 (0)