1313
1414class Mailin
1515{
16- public $ api_key ;
16+ public $ parameters ;
1717 public $ base_url ;
1818 public $ curl_opts = array ();
1919
20- public function __construct ($ api_key )
20+ public function __construct ($ parameters )
2121 {
2222 if (!function_exists ('curl_init ' ))
2323 {
2424 throw new \RuntimeException ('Mailin requires cURL module ' );
2525 }
26- $ this ->config = $ api_key ;
26+ $ this ->config = $ parameters ;
2727 $ this ->base_url = "https://api.sendinblue.com/v2.0 " ;
2828 $ this ->api_key = $ this ->config ['api_key ' ];
29+ $ this ->timeout = $ this ->config ['timeout ' ];
2930 }
3031 /**
3132 * Do CURL request with authorization
@@ -36,6 +37,9 @@ private function do_request($resource,$method,$input)
3637 $ ch = curl_init ($ called_url );
3738 $ auth_header = 'api-key: ' .$ this ->api_key ;
3839 $ content_header = "Content-Type:application/json " ;
40+ if (isset ($ this ->timeout ) && ($ this ->timeout <= 0 || $ this ->timeout > 60000 )) {
41+ throw new \Exception ('value not allowed for timeout ' );
42+ }
3943 if (strtoupper (substr (PHP_OS , 0 , 3 )) === 'WIN ' ) {
4044 // Windows only over-ride
4145 curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , false );
@@ -44,14 +48,15 @@ private function do_request($resource,$method,$input)
4448 curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , 1 );
4549 curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , $ method );
4650 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
51+ curl_setopt ($ ch , CURLOPT_TIMEOUT_MS , $ this ->timeout );
4752 curl_setopt ($ ch , CURLOPT_HEADER , 0 );
4853 curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ input );
4954
5055 $ data = curl_exec ($ ch );
5156 $ info = curl_getinfo ($ ch );
5257 if (curl_errno ($ ch ))
5358 {
54- throw new \RuntimeException ('Curl error: ' . curl_error ($ ch ));
59+ throw new \RuntimeException ('cURL error: ' . curl_error ($ ch ));
5560 }
5661 curl_close ($ ch );
5762 return json_decode ($ data ,true );
0 commit comments