1<?php 2/** 3 * Elasticsearch PHP client 4 * 5 * @link https://github.com/elastic/elasticsearch-php/ 6 * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co) 7 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 8 * @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1 9 * 10 * Licensed to Elasticsearch B.V under one or more agreements. 11 * Elasticsearch B.V licenses this file to you under the Apache 2.0 License or 12 * the GNU Lesser General Public License, Version 2.1, at your option. 13 * See the LICENSE file in the project root for more information. 14 */ 15declare(strict_types = 1); 16 17namespace Elasticsearch\Endpoints\Ml; 18 19use Elasticsearch\Common\Exceptions\RuntimeException; 20use Elasticsearch\Common\Exceptions\InvalidArgumentException; 21use Elasticsearch\Endpoints\AbstractEndpoint; 22use Elasticsearch\Serializers\SerializerInterface; 23use Traversable; 24 25/** 26 * Class PostData 27 * Elasticsearch API name ml.post_data 28 * 29 * NOTE: this file is autogenerated using util/GenerateEndpoints.php 30 * and Elasticsearch 7.16.0-SNAPSHOT (dfc9a8e7563ed5f24b5210ed21ed92ae182cd0ee) 31 */ 32class PostData extends AbstractEndpoint 33{ 34 protected $job_id; 35 36 public function __construct(SerializerInterface $serializer) 37 { 38 $this->serializer = $serializer; 39 } 40 41 public function getURI(): string 42 { 43 $job_id = $this->job_id ?? null; 44 45 if (isset($job_id)) { 46 return "/_ml/anomaly_detectors/$job_id/_data"; 47 } 48 throw new RuntimeException('Missing parameter for the endpoint ml.post_data'); 49 } 50 51 public function getParamWhitelist(): array 52 { 53 return [ 54 'reset_start', 55 'reset_end' 56 ]; 57 } 58 59 public function getMethod(): string 60 { 61 return 'POST'; 62 } 63 64 public function setBody($body): PostData 65 { 66 if (isset($body) !== true) { 67 return $this; 68 } 69 if (is_array($body) === true || $body instanceof Traversable) { 70 foreach ($body as $item) { 71 $this->body .= $this->serializer->serialize($item) . "\n"; 72 } 73 } elseif (is_string($body)) { 74 $this->body = $body; 75 if (substr($body, -1) != "\n") { 76 $this->body .= "\n"; 77 } 78 } else { 79 throw new InvalidArgumentException("Body must be an array, traversable object or string"); 80 } 81 return $this; 82 } 83 public function setJobId($job_id): PostData 84 { 85 if (isset($job_id) !== true) { 86 return $this; 87 } 88 $this->job_id = $job_id; 89 90 return $this; 91 } 92 93} 94