Skip to content

Commit

Permalink
Merge pull request #4 from ProCycleDev/master
Browse files Browse the repository at this point in the history
Allow a custom curl timeout value for doRequest()
  • Loading branch information
GeNyaa authored Sep 8, 2022
2 parents 456f47e + 0a85f03 commit 9b2b531
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ class Rate extends USPSBase
/**
* Perform the API call.
*
* @param int $timeout
* Optionally override the cURL timeout.
*
* @return string
*/
public function getRate()
public function getRate(int $timeout)
{
return $this->doRequest();
return $this->doRequest(NULL,$timeout);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/USPSBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ public function getResponseApiName()
* make the request.
*
* @param resource $ch Optional initialized cURL handle
*
* @param int $timeout
* Optional cURL timeout value.
*
* @return string the response text
*/
protected function doRequest($ch = null)
protected function doRequest($ch = null, int $timeout)
{
if (!$ch) {
$ch = curl_init();
Expand All @@ -189,7 +191,9 @@ protected function doRequest($ch = null)
if (strpos($opts[CURLOPT_URL], 'https://') === false) {
$opts[CURLOPT_PORT] = 80;
}

if (is_int($timeout)) {
$opts[CURLOPT_TIMEOUT] = $timeout;
}
// set options
curl_setopt_array($ch, $opts);

Expand Down

0 comments on commit 9b2b531

Please sign in to comment.