public function testThrowsExceptionWhenAttemptingToMutateCredentialsOrRegion() { $client = CloudSearchDomainClient::factory(array('base_url' => 'example.com')); $this->setExpectedException('BadMethodCallException'); $client->setRegion('us-west-2'); $this->setExpectedException('BadMethodCallException'); $client->setCredentaisl(new Credentials('foo', 'bar')); }
/** * Create a CloudSearchDomainClient for a particular domain to do searching * and document uploads. * * @param string $domainName Name of the CloudSearch domain. * @param array $config Config options for the CloudSearchDomainClient * * @return CloudSearchDomainClient */ public function getDomainClient($domainName, array $config = []) { $config['endpoint'] = $this->describeDomains(['DomainNames' => [$domainName]])->getPath('DomainStatusList/0/SearchService/Endpoint'); if (!isset($config['scheme'])) { $config['scheme'] = 'https'; } // Create an absolute URI for the endpoint. $config['endpoint'] = $config['scheme'] . '://' . $config['endpoint']; return CloudSearchDomainClient::factory($config); }
public function testSignsRequests() { $mock = new MockPlugin(array(new Response(200), new Response(200))); $config = array(Opt::BASE_URL => 'foo.us-east-1.cloudsearch.amazonaws.com', Opt::VALIDATION => false, Opt::CREDENTIALS => new Credentials('foo', 'bar')); $getAuthorizationHeader = function (Event $event) use(&$auth) { $auth = (string) $event['request']->getHeader('Authorization'); }; $client1 = CloudSearchDomainClient::factory($config); $client1->addSubscriber($mock); $client1->getEventDispatcher()->addListener('request.before_send', $getAuthorizationHeader, -999); $client1->search(); $this->assertNotEmpty($auth); $config[Opt::CREDENTIALS] = false; $client2 = CloudSearchDomainClient::factory($config); $client2->addSubscriber($mock); $client2->getEventDispatcher()->addListener('request.before_send', $getAuthorizationHeader, -999); $client2->search(); $this->assertEmpty($auth); }
<?php require_once 'vendor/autoload.php'; use Aws\CloudSearchDomain\CloudSearchDomainClient; $csDomainClient = CloudSearchDomainClient::factory(['endpoint' => 'http://search-my-search-wzfnq73vja7om3qna37iaupkgm.us-east-1.cloudsearch.amazonaws.com', 'credentials' => false, 'version' => '2013-01-01']); $suggest = $csDomainClient->suggest(['query' => 'articl', 'suggester' => 'title_suggestions']); print_r($suggest['suggest']);
/** * Create a CloudSearchDomainClient for a particular domain to do searching * and document uploads. * * @param string $domainName Name of the domain for which to create a domain client. * @param array $config Config options for the CloudSearchDomainClient * * @return CloudSearchDomainClient * @link http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#client-configuration-options */ public function getDomainClient($domainName, array $config = array()) { // Determine the Domain client's endpoint $config['endpoint'] = $this->describeDomains(array('DomainNames' => array($domainName)))->getPath('DomainStatusList/0/SearchService/Endpoint'); return CloudSearchDomainClient::factory($config); }
public function connect() { $this->_connection = CloudSearchDomainClient::factory($this->config); $this->connected = true; }
<?php require_once 'vendor/autoload.php'; use Aws\CloudSearchDomain\CloudSearchDomainClient; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); $csDomainClient = CloudSearchDomainClient::factory(['endpoint' => 'http://doc-my-search-wzfnq73vja7om3qna37iaupkgm.us-east-1.cloudsearch.amazonaws.com', 'credentials' => ['key' => getenv('AWS_KEY'), 'secret' => getenv('AWS_SECRET')], 'version' => '2013-01-01']); $batch = [['type' => 'add', 'id' => '1', 'fields' => ['title' => 'Article 1', 'body' => 'This is the first example.', 'date' => '2015-01-22T10:03:06Z']], ['type' => 'add', 'id' => '2', 'fields' => ['title' => 'Article 2', 'body' => 'The second example is presented.', 'date' => '2015-01-23T10:03:06Z']], ['type' => 'add', 'id' => '3', 'fields' => ['title' => 'Article 3', 'body' => 'Third article.', 'date' => '2015-01-25T10:03:06Z']]]; $result = $csDomainClient->uploadDocuments(['documents' => json_encode($batch), 'contentType' => 'application/json']); print_r($result);
/** * Set if you want to use a different client/endpoint for pushing than the one inserted in the constructor. * * @param $endpoint * @param $key * @param $secret */ public function setSearchClient($endpoint, $key, $secret) { $this->searchClient = CloudSearchDomainClient::factory(['endpoint' => $endpoint, 'credentials' => ['key' => $key, 'secret' => $secret], 'version' => '2013-01-01']); }
protected function _factoryEndpointClient($type, $domain) { $var = sprintf('_%sClient', $type); $this->{$var} = false; $key = sprintf('%s_%s_%s_endpoint', ConnectionManager::getSourceName($this), $domain, $type); $key = preg_replace('/[^A-Za-z0-9_\\-.+]/', '_', $key); $endpoint = Cache::read($key, '_cake_model_'); if (empty($endpoint) && ($client = $this->_factoryClient())) { $result = $client->describeDomains(['DomainNames' => [$domain]]); $service = Inflector::camelize($type) . 'Service'; $endpoint = $result['DomainStatusList'][0][$service]['Endpoint']; Cache::write($key, $endpoint, '_cake_model_'); } if (!empty($endpoint)) { $this->{$var} = CloudSearchDomainClient::factory(['base_url' => $endpoint]); } return $this->{$var}; }