Skip to content

Commit

Permalink
Add Get/Put/Delete Template endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Jul 23, 2014
1 parent 02784fd commit f003010
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,74 @@ public function putScript($params)
return $response['data'];
}

/**
* $params['id'] = (string) The search template ID (Required)
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function getTemplate($params)
{
$id = $this->extractArgument($params, 'id');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Template\Get $endpoint */
$endpoint = $endpointBuilder('Template\Get');
$endpoint->setID($id);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['id'] = (string) The search template ID (Required)
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function deleteTemplate($params)
{
$id = $this->extractArgument($params, 'id');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Template\Delete $endpoint */
$endpoint = $endpointBuilder('Template\Delete');
$endpoint->setID($id);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}

/**
* $params['id'] = (string) The search template ID (Required)
*
* @param $params array Associative array of parameters
*
* @return array
*/
public function putTemplate($params)
{
$id = $this->extractArgument($params, 'id');
$body = $this->extractArgument($params, 'body');

/** @var callback $endpointBuilder */
$endpointBuilder = $this->dicEndpoints;

/** @var \Elasticsearch\Endpoints\Template\Put $endpoint */
$endpoint = $endpointBuilder('Template\Put');
$endpoint->setID($id)
->setBody($body);
$endpoint->setParams($params);
$response = $endpoint->performRequest();
return $response['data'];
}



/**
Expand Down
60 changes: 60 additions & 0 deletions src/Elasticsearch/Endpoints/Template/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* User: zach
* Date: 7/23/14
* Time: 2:25 PM
*/

namespace Elasticsearch\Endpoints\Template;

use Elasticsearch\Endpoints\AbstractEndpoint;
use Elasticsearch\Common\Exceptions;

/**
* Class Delete
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Template
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/

class Delete extends AbstractEndpoint
{

/**
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
* @return string
*/
protected function getURI()
{
if (isset($this->id) !== true) {
throw new Exceptions\RuntimeException(
'id is required for Delete'
);
}
$templateId = $this->id;
$uri = "/_search/template/$templateId";

return $uri;
}


/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array();
}


/**
* @return string
*/
protected function getMethod()
{
return 'DELETE';
}
}
60 changes: 60 additions & 0 deletions src/Elasticsearch/Endpoints/Template/Get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* User: zach
* Date: 7/23/14
* Time: 2:25 PM
*/

namespace Elasticsearch\Endpoints\Template;

use Elasticsearch\Endpoints\AbstractEndpoint;
use Elasticsearch\Common\Exceptions;

/**
* Class Get
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Template
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/

class Get extends AbstractEndpoint
{

/**
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
* @return string
*/
protected function getURI()
{
if (isset($this->id) !== true) {
throw new Exceptions\RuntimeException(
'id is required for Get'
);
}
$templateId = $this->id;
$uri = "/_search/template/$templateId";

return $uri;
}


/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array();
}


/**
* @return string
*/
protected function getMethod()
{
return 'GET';
}
}
77 changes: 77 additions & 0 deletions src/Elasticsearch/Endpoints/Template/Put.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* User: zach
* Date: 7/23/14
* Time: 2:25 PM
*/

namespace Elasticsearch\Endpoints\Template;

use Elasticsearch\Endpoints\AbstractEndpoint;
use Elasticsearch\Common\Exceptions;

/**
* Class Put
*
* @category Elasticsearch
* @package Elasticsearch\Endpoints\Template
* @author Zachary Tong <[email protected]>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/

class Put extends AbstractEndpoint
{

/**
* @param array $body
*
* @return $this
*/
public function setBody($body)
{
if (isset($body) !== true) {
return $this;
}

$this->body = $body;
return $this;
}


/**
* @throws \Elasticsearch\Common\Exceptions\RuntimeException
* @return string
*/
protected function getURI()
{
if (isset($this->id) !== true) {
throw new Exceptions\RuntimeException(
'id is required for Put'
);
}

$templateId = $this->id;
$uri = "/_search/template/$templateId";

return $uri;
}


/**
* @return string[]
*/
protected function getParamWhitelist()
{
return array();
}


/**
* @return string
*/
protected function getMethod()
{
return 'PUT';
}
}

0 comments on commit f003010

Please sign in to comment.