@@ -32,17 +32,20 @@ class Client
3232 protected $ curlOptions ;
3333 /** @var array */
3434 private $ methods ;
35+ /** @var bool */
36+ private $ retryOnLimit ;
3537
3638 /**
3739 * Initialize the client
3840 *
39- * @param string $host the base url (e.g. https://api.sendgrid.com)
40- * @param array $headers global request headers
41- * @param string $version api version (configurable)
42- * @param array $path holds the segments of the url path
43- * @param array $curlOptions extra options to set during curl initialization
41+ * @param string $host the base url (e.g. https://api.sendgrid.com)
42+ * @param array $headers global request headers
43+ * @param string $version api version (configurable)
44+ * @param array $path holds the segments of the url path
45+ * @param array $curlOptions extra options to set during curl initialization
46+ * @param bool $retryOnLimit set default retry on limit flag
4447 */
45- public function __construct ($ host , $ headers = null , $ version = null , $ path = null , $ curlOptions = null )
48+ public function __construct ($ host , $ headers = null , $ version = null , $ path = null , $ curlOptions = null , $ retryOnLimit = false )
4649 {
4750 $ this ->host = $ host ;
4851 $ this ->headers = $ headers ?: [];
@@ -51,6 +54,8 @@ public function __construct($host, $headers = null, $version = null, $path = nul
5154 $ this ->curlOptions = $ curlOptions ?: [];
5255 // These are the supported HTTP verbs
5356 $ this ->methods = ['delete ' , 'get ' , 'patch ' , 'post ' , 'put ' ];
57+
58+ $ this ->retryOnLimit = $ retryOnLimit ;
5459 }
5560
5661 /**
@@ -138,7 +143,7 @@ private function buildUrl($queryParams = null)
138143 *
139144 * @return Response object
140145 */
141- public function makeRequest ($ method , $ url , $ body = null , $ headers = null , $ retryOnLimit = true )
146+ public function makeRequest ($ method , $ url , $ body = null , $ headers = null , $ retryOnLimit = false )
142147 {
143148 $ curl = curl_init ($ url );
144149
@@ -221,7 +226,8 @@ public function __call($name, $args)
221226 $ queryParams = isset ($ args [1 ]) ? $ args [1 ] : null ;
222227 $ url = $ this ->buildUrl ($ queryParams );
223228 $ headers = isset ($ args [2 ]) ? $ args [2 ] : null ;
224- return $ this ->makeRequest ($ name , $ url , $ body , $ headers );
229+ $ retryOnLimit = isset ($ args [3 ]) ? $ args [3 ] : $ this ->retryOnLimit ;
230+ return $ this ->makeRequest ($ name , $ url , $ body , $ headers , $ retryOnLimit );
225231 }
226232
227233 return $ this ->_ ($ name );
0 commit comments