Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

take it #3

Merged
3 commits merged into from
Oct 15, 2010
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 63 additions & 11 deletions lib/AmazonECS.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public function __construct($accessKey, $secretKey, $country = 'DE')
$this->responseConfig['country'] = $country;
}

/**
* execute search
*
* @param string $pattern
*
* @return array|object return type depends on setting
*
* @see returnType()
*/
public function search($pattern)
{
if (false === isset($this->requestConfig['category']))
Expand All @@ -73,7 +82,15 @@ public function search($pattern)
);
}

protected function buildRequestParams($function, $params)
/**
* Builds the request parameters
*
* @param string $function
* @param array $params
*
* @return array
*/
protected function buildRequestParams($function, array $params)
{
return array(
'AWSAccessKeyId' => $this->requestConfig['accessKey'],
Expand All @@ -85,13 +102,25 @@ protected function buildRequestParams($function, $params)
);
}

/**
* Set or get the country
*
* if the country argument is null it will return the current
* country, otherwise it will set the country and reutrn itself.
*
* @param string|null $country
*
* @return string|AmazonECS depends on country argument
*/
public function country($country = null)
{
if (null !== $country)
if (null === $country)
{
$this->responseConfig['country'] = $country;
return $this->responseConfig['country'];
}

$this->responseConfig['country'] = $country;

return $this;
}

Expand All @@ -109,20 +138,36 @@ public function category($category = null)

public function responseGroup($responseGroup = null)
{
if (null !== $responseGroup)
if (null === $responseGroup)
{
$this->responseConfig['responseGroup'] = $responseGroup;
return $this->responseConfig['responseGroup'];
}

$this->responseConfig['responseGroup'] = $responseGroup;

return $this;
}

public function setReturnType($type)
public function returnType($type = null)
{
if (null === $type)
{
return $this->responseConfig['returnType'];
}

$this->responseConfig['returnType'] = $type;

return $this;
}

/**
* @deprected use returnType() instead
*/
public function setReturnType($type)
{
return $this->returnType($type);
}

/**
* Returns the Response either as Array or Array/Object
*
Expand All @@ -143,7 +188,9 @@ protected function returnData($object)
break;

default:
return false;
throw new InvalidArgumentException(sprintf(
"Unknwon return type %s", $this->responseConfig['returnType']
));
break;
}
}
Expand All @@ -160,18 +207,23 @@ protected function objectToArray($object)
$out = array();
foreach ($object as $key => $value)
{
switch(true)
switch (true)
{
case is_object($value):
$out[$key] = $this->objectToArray($value);
break;
break;

case is_array($value):
$out[$key] = $this->objectToArray($value);

break;

default:
$out[$key] = $value;
break;
default:
$out[$key] = $value;
}
}

return $out;
}

Expand Down