Skip to content

Commit

Permalink
Add Get/Put/Delete Script endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Jul 23, 2014
1 parent a9376d4 commit 07ddc97
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,82 @@ public function update($params)
}


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

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

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

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

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

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

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

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

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



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

namespace Elasticsearch\Endpoints\Script;

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

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

class Delete extends AbstractEndpoint
{
/** @var String */
private $lang;


/**
* @param $lang
*
* @return $this
*/
public function setLang($lang)
{
if (isset($lang) !== true) {
return $this;
}

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


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

return $uri;
}


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


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

namespace Elasticsearch\Endpoints\Script;

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

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

class Get extends AbstractEndpoint
{
/** @var String */
private $lang;


/**
* @param $lang
*
* @return $this
*/
public function setLang($lang)
{
if (isset($lang) !== true) {
return $this;
}

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


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

return $uri;
}


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


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

namespace Elasticsearch\Endpoints\Script;

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

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

class Put extends AbstractEndpoint
{
/** @var String */
private $lang;

/**
* @param $lang
*
* @return $this
*/
public function setLang($lang)
{
if (isset($lang) !== true) {
return $this;
}

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


/**
* @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->lang) !== true) {
throw new Exceptions\RuntimeException(
'lang is required for Put'
);
}
if (isset($this->id) !== true) {
throw new Exceptions\RuntimeException(
'id is required for put'
);
}
$id = $this->id;
$lang = $this->lang;
$uri = "/_scripts/$lang/$id";

return $uri;
}


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


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

0 comments on commit 07ddc97

Please sign in to comment.