Skip to content

Commit

Permalink
Add a new parameter to pass a custom timeout value
Browse files Browse the repository at this point in the history
  • Loading branch information
yanncoupin committed Dec 20, 2012
1 parent b13776c commit 7b10204
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions CloudKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class CloudKey
$api_key = null,
$base_url = null,
$cdn_url = null,
$proxy = null;
$proxy = null,
$timeout = 30;

public function __construct($user_id, $api_key, $base_url = null, $cdn_url = null, $proxy = null)
public function __construct($user_id, $api_key, $base_url = null, $cdn_url = null, $proxy = null, $timeout = 30)
{
$this->user_id = $user_id;
$this->api_key = $api_key;
$this->base_url = $base_url;
$this->cdn_url = $cdn_url;
$this->proxy = $proxy;
$this->timeout = $timeout;
}

public function __get($name)
Expand All @@ -39,7 +41,7 @@ public function __get($name)
{
$class = 'CloudKey_Api';
}
$this->objects[$name] = new $class($this->user_id, $this->api_key, $this->base_url, $this->cdn_url, $name, $this->proxy);
$this->objects[$name] = new $class($this->user_id, $this->api_key, $this->base_url, $this->cdn_url, $name, $this->proxy, $this->timeout);
$this->objects[$name]->parent = $this;
}

Expand Down Expand Up @@ -191,9 +193,10 @@ class CloudKey_Api
$base_url = 'http://api.dmcloud.net',
$cdn_url = 'http://cdn.dmcloud.net',
$object = null,
$proxy = null;
$proxy = null,
$timeout = null;

public function __construct($user_id, $api_key, $base_url = null, $cdn_url = null, $object = null, $proxy = null)
public function __construct($user_id, $api_key, $base_url = null, $cdn_url = null, $object = null, $proxy = null, $timeout = 30)
{
if ($user_id === null || $api_key === null)
{
Expand All @@ -203,6 +206,7 @@ public function __construct($user_id, $api_key, $base_url = null, $cdn_url = nul
$this->user_id = $user_id;
$this->api_key = $api_key;
$this->proxy = $proxy;
$this->timeout = $timeout;

if ($base_url !== null)
{
Expand Down Expand Up @@ -273,8 +277,8 @@ public function __call($method, $args)
CURLOPT_POSTFIELDS => json_encode($request),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => $this->timeout,
CURLOPT_TIMEOUT => $this->timeout,
CURLOPT_PROXY => $this->proxy,
));

Expand Down

0 comments on commit 7b10204

Please sign in to comment.