@@ -14,13 +14,15 @@ class ESignBsre
14
14
private $ file ;
15
15
private $ fileName ;
16
16
private $ view = 'invisible ' ;
17
+ private $ timeout ;
17
18
18
- public function __construct ($ baseUrl , $ username , $ password ){
19
+ public function __construct ($ baseUrl , $ username , $ password, $ timeout = 1 ){
19
20
$ this ->baseUrl = $ baseUrl ;
20
21
21
22
$ this ->http = new GuzzleClient ();
22
23
$ this ->username = $ username ;
23
24
$ this ->password = $ password ;
25
+ $ this ->timeout = $ timeout ;
24
26
}
25
27
26
28
public function setFile ($ file , $ fileName ){
@@ -30,11 +32,18 @@ public function setFile($file, $fileName){
30
32
return $ this ;
31
33
}
32
34
35
+ public function setTimeout ($ timeout ){
36
+ $ this ->timeout = $ timeout ;
37
+
38
+ return $ this ;
39
+ }
40
+
33
41
public function sign ($ nik , $ passphrase )
34
42
{
35
43
try {
36
44
$ response = $ this ->http ->request ('POST ' , "{$ this ->getBaseUrl ()}/api/sign/pdf " , [
37
45
'auth ' => $ this ->getAuth (),
46
+ 'timeout ' => $ this ->timeout ,
38
47
'multipart ' => [
39
48
[
40
49
'name ' => 'file ' ,
@@ -55,18 +64,21 @@ public function sign($nik, $passphrase)
55
64
],
56
65
],
57
66
]);
58
- }catch (\Exception $ e ) {
67
+ }catch (\GuzzleHttp \Exception \ConnectException $ e ){
68
+ return new ESignBsreResponse ($ e );
69
+ } catch (\Exception $ e ) {
59
70
$ response = $ e ->getResponse ();
60
71
}
61
72
62
- return new ESignBsreResponse ($ response );
73
+ return ( new ESignBsreResponse ())-> setFromResponse ( $ response );
63
74
}
64
75
65
76
public function verification ()
66
77
{
67
78
try {
68
79
$ response = $ this ->http ->request ('POST ' , "{$ this ->getBaseUrl ()}/api/sign/verify " , [
69
80
'auth ' => $ this ->getAuth (),
81
+ 'timeout ' => $ this ->timeout ,
70
82
'multipart ' => [
71
83
[
72
84
'name ' => 'signed_file ' ,
@@ -75,23 +87,28 @@ public function verification()
75
87
],
76
88
]
77
89
]);
78
- }catch (\Exception $ e ) {
90
+ }catch (\GuzzleHttp \Exception \ConnectException $ e ){
91
+ return new ESignBsreResponse ($ e );
92
+ } catch (\Exception $ e ) {
79
93
$ response = $ e ->getResponse ();
80
94
}
81
95
82
- return new ESignBsreResponse ($ response );
96
+ return ( new ESignBsreResponse ())-> setFromResponse ( $ response );
83
97
}
84
98
85
99
public function statusUser ($ nik ) {
86
100
try {
87
101
$ response = $ this ->http ->request ('GET ' , "{$ this ->getBaseUrl ()}/api/user/status/ $ nik " , [
88
- 'auth ' => $ this ->getAuth ()
102
+ 'auth ' => $ this ->getAuth (),
103
+ 'timeout ' => $ this ->timeout ,
89
104
]);
105
+ } catch (\GuzzleHttp \Exception \ConnectException $ e ){
106
+ return (new ESignBsreResponse ())->setFromExeption ($ e , ESignBsreResponse::STATUS_TIMEOUT );
90
107
} catch (\Exception $ e ) {
91
108
$ response = $ e ->getResponse ();
92
109
}
93
110
94
- return new ESignBsreResponse ($ response );
111
+ return ( new ESignBsreResponse ())-> setFromResponse ( $ response );
95
112
}
96
113
97
114
private function getAuth (){
0 commit comments