forked from aws/aws-sdk-php
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the CloudSearchDomain client.
The CloudSearchDomain client can be used to search and upload documents to you CloudSearch domains.
- Loading branch information
1 parent
7aaeadf
commit e1046a0
Showing
14 changed files
with
659 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
==================================================================================== | ||
Amazon CloudSearch Domains | ||
==================================================================================== | ||
|
||
This guide focuses on the AWS SDK for PHP client for Amazon CloudSearch domains. The ``CloudSearchDomainClient`` allows | ||
you to search and upload documents to your CloudSearch domains. This guide assumes that you have already downloaded and | ||
installed the AWS SDK for PHP. See :doc:`installation` for more information on getting started. | ||
|
||
Creating a client | ||
----------------- | ||
|
||
First you need to create a client object using one of the following techniques. | ||
|
||
Factory method | ||
~~~~~~~~~~~~~~ | ||
|
||
Similar to the way other service clients are used, you can instantiate the ``CloudSearchDomainClient`` with the | ||
``Aws\CloudSearchDomain\CloudSearchDomainClient::factory()`` method. | ||
|
||
.. code-block:: php | ||
use Aws\CloudSearchDomain\CloudSearchDomainClient; | ||
$client = CloudSearchDomainClient::factory(array( | ||
'base_url' => '<your cloudsearch domain endpoint>', | ||
)); | ||
The ``CloudSearchDomainClient`` is unlike other clients, because it does not require you to provide AWS credentials. | ||
The only thing you need to provide is the ``base_url`` option, which represents the domain's endpoint. Domain | ||
endpoints are unique to each domain, and you can get it by describing your domain with the :doc:`Amazon CloudSearch | ||
configuration client <service-cloudsearch>`. | ||
|
||
Helper method | ||
~~~~~~~~~~~~~ | ||
|
||
An easy way to instantiate the ``CloudSearchDomainClient`` is to use the ``CloudSearchClient::getDomainClient()`` | ||
helper method. This method use the CloudSearch configuration API to retrieve the domain endpoint, and instantiates the | ||
domain client for you. | ||
|
||
.. code-block:: php | ||
use Aws\CloudSearch\CloudSearchClient; | ||
$configClient = CloudSearchClient::factory(array( | ||
'profile' => '<profile in your aws credentials file>', | ||
'region' => '<region name>', | ||
)); | ||
$domainClient = $configClient->getDomainClient('<domain name>'); | ||
// Use the search operation | ||
$result = $domainClient->search(array('query' => 'foobar')); | ||
$hitCount = $result->getPath('hits/found'); | ||
echo "Number of Hits: {$hitCount}\n"; | ||
.. apiref:: CloudSearchDomain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Aws\CloudSearchDomain; | ||
|
||
use Aws\Common\Client\AbstractClient; | ||
use Aws\Common\Credentials\CredentialsInterface; | ||
use Aws\Common\Enum\ClientOptions as Options; | ||
use Aws\Common\Exception\BadMethodCallException; | ||
use Guzzle\Common\Collection; | ||
use Guzzle\Service\Resource\Model; | ||
|
||
/** | ||
* Client to interact with Amazon CloudSearchDomain | ||
* | ||
* @method Model search(array $args = array()) {@command CloudSearchDomain Search} | ||
* @method Model suggest(array $args = array()) {@command CloudSearchDomain Suggest} | ||
* @method Model uploadDocuments(array $args = array()) {@command CloudSearchDomain UploadDocuments} | ||
* | ||
* @link http://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-cloudsearchdomain.html User guide | ||
* @link http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.CloudSearchDomain.CloudSearchDomainClient.html API docs | ||
*/ | ||
class CloudSearchDomainClient extends AbstractClient | ||
{ | ||
const LATEST_API_VERSION = '2013-01-01'; | ||
|
||
/** | ||
* Factory method to create a new Amazon CloudSearchDomain client using an array of configuration options. | ||
* | ||
* You must provide the `base_url` option for this client, but credentials and `region` are not needed. | ||
* | ||
* @param array|Collection $config Client configuration data | ||
* | ||
* @return self | ||
* @link http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#client-configuration-options | ||
*/ | ||
public static function factory($config = array()) | ||
{ | ||
return CloudSearchDomainClientBuilder::factory(__NAMESPACE__) | ||
->setConfig($config) | ||
->setConfigDefaults(array( | ||
Options::VERSION => self::LATEST_API_VERSION, | ||
Options::SERVICE_DESCRIPTION => __DIR__ . '/Resources/cloudsearchdomain-%s.php' | ||
)) | ||
->build(); | ||
} | ||
|
||
/** | ||
* @internal | ||
* @throws \Aws\Common\Exception\BadMethodCallException Do not call this method | ||
*/ | ||
public function setCredentials(CredentialsInterface $credentials) | ||
{ | ||
throw new BadMethodCallException('The CloudSearchDomain client does not require AWS credentials.'); | ||
} | ||
|
||
/** | ||
* @internal | ||
* @throws \Aws\Common\Exception\BadMethodCallException Do not call this method | ||
*/ | ||
public function setRegion($region) | ||
{ | ||
throw new BadMethodCallException('You cannot change the region of a CloudSearchDomain client.'); | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
src/Aws/CloudSearchDomain/CloudSearchDomainClientBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace Aws\CloudSearchDomain; | ||
|
||
use Aws\Common\Client\ClientBuilder; | ||
use Aws\Common\Client\ThrottlingErrorChecker; | ||
use Aws\Common\Client\UserAgentListener; | ||
use Aws\Common\Credentials\Credentials; | ||
use Aws\Common\Enum\ClientOptions as Options; | ||
use Aws\Common\Exception\ExceptionListener; | ||
use Aws\Common\Exception\InvalidArgumentException; | ||
use Aws\Common\Exception\NamespaceExceptionFactory; | ||
use Aws\Common\Exception\Parser\JsonQueryExceptionParser; | ||
use Aws\Common\Signature\SignatureV4; | ||
use Guzzle\Common\Collection; | ||
use Guzzle\Http\Url; | ||
use Guzzle\Plugin\Backoff\BackoffPlugin; | ||
use Guzzle\Plugin\Backoff\CurlBackoffStrategy; | ||
use Guzzle\Plugin\Backoff\ExponentialBackoffStrategy; | ||
use Guzzle\Plugin\Backoff\HttpBackoffStrategy; | ||
use Guzzle\Plugin\Backoff\TruncatedBackoffStrategy; | ||
use Guzzle\Service\Description\ServiceDescription; | ||
|
||
/** | ||
* Builder for creating CloudSearchDomain clients | ||
* | ||
* @internal | ||
*/ | ||
class CloudSearchDomainClientBuilder extends ClientBuilder | ||
{ | ||
protected static $commonConfigDefaults = array( | ||
'scheme' => 'https', | ||
'signature.ignore' => true | ||
); | ||
|
||
public function build() | ||
{ | ||
// Resolve configuration | ||
$config = Collection::fromConfig( | ||
$this->config, | ||
array_merge(self::$commonConfigDefaults, $this->configDefaults), | ||
$this->configRequirements | ||
); | ||
|
||
// Make sure base_url is correctly set | ||
if (!($baseUrl = $config->get(Options::BASE_URL))) { | ||
throw new InvalidArgumentException('You must provide the endpoint for the CloudSearch domain.'); | ||
} elseif (strpos($baseUrl, 'http') !== 0) { | ||
$config->set(Options::BASE_URL, Url::buildUrl(array( | ||
'scheme' => $config->get(Options::SCHEME), | ||
'host' => $baseUrl, | ||
))); | ||
} | ||
|
||
// Create dependencies | ||
$exceptionParser = new JsonQueryExceptionParser(); | ||
$signature = new SignatureV4(); | ||
$credentials = new Credentials('',''); | ||
$description = ServiceDescription::factory(sprintf( | ||
$config->get(Options::SERVICE_DESCRIPTION), | ||
$config->get(Options::VERSION) | ||
)); | ||
|
||
// Resolve backoff strategy | ||
$backoff = $config->get(Options::BACKOFF); | ||
if ($backoff === null) { | ||
$backoff = new BackoffPlugin( | ||
// Retry failed requests up to 3 times if it is determined that the request can be retried | ||
new TruncatedBackoffStrategy(3, | ||
// Retry failed requests with 400-level responses due to throttling | ||
new ThrottlingErrorChecker($exceptionParser, | ||
// Retry failed requests with 500-level responses | ||
new HttpBackoffStrategy(array(500, 503, 509), | ||
// Retry failed requests due to transient network or cURL problems | ||
new CurlBackoffStrategy(null, | ||
new ExponentialBackoffStrategy() | ||
) | ||
) | ||
) | ||
) | ||
); | ||
$config->set(Options::BACKOFF, $backoff); | ||
} | ||
if ($backoff) { | ||
$this->addBackoffLogger($backoff, $config); | ||
} | ||
|
||
// Create client | ||
$client = new CloudSearchDomainClient($credentials, $signature, $config); | ||
$client->setDescription($description); | ||
|
||
// Add exception marshaling so that more descriptive exception are thrown | ||
$client->addSubscriber(new ExceptionListener(new NamespaceExceptionFactory( | ||
$exceptionParser, | ||
__NAMESPACE__ . '\\Exception', | ||
__NAMESPACE__ . '\\Exception\\CloudSearchDomainException' | ||
))); | ||
|
||
// Add the UserAgentPlugin to append to the User-Agent header of requests | ||
$client->addSubscriber(new UserAgentListener); | ||
|
||
// Filters used for the cache plugin | ||
$client->getConfig()->set( | ||
'params.cache.key_filter', | ||
'header=date,x-amz-date,x-amz-security-token,x-amzn-authorization' | ||
); | ||
|
||
// Disable parameter validation if needed | ||
if ($config->get(Options::VALIDATION) === false) { | ||
$params = $config->get('command.params') ?: array(); | ||
$params['command.disable_validation'] = true; | ||
$config->set('command.params', $params); | ||
} | ||
|
||
return $client; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Aws/CloudSearchDomain/Exception/CloudSearchDomainException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Aws\CloudSearchDomain\Exception; | ||
|
||
use Aws\Common\Exception\ServiceResponseException; | ||
|
||
/** | ||
* Exception thrown by the CloudSearchDomain client. | ||
*/ | ||
class CloudSearchDomainException extends ServiceResponseException {} |
Oops, something went wrong.