1<?php
2namespace Aws\LookoutMetrics;
3
4use Aws\AwsClient;
5use Aws\CommandInterface;
6use Psr\Http\Message\RequestInterface;
7
8/**
9 * This client is used to interact with the **Amazon Lookout for Metrics** service.
10 * @method \Aws\Result activateAnomalyDetector(array $args = [])
11 * @method \GuzzleHttp\Promise\Promise activateAnomalyDetectorAsync(array $args = [])
12 * @method \Aws\Result backTestAnomalyDetector(array $args = [])
13 * @method \GuzzleHttp\Promise\Promise backTestAnomalyDetectorAsync(array $args = [])
14 * @method \Aws\Result createAlert(array $args = [])
15 * @method \GuzzleHttp\Promise\Promise createAlertAsync(array $args = [])
16 * @method \Aws\Result createAnomalyDetector(array $args = [])
17 * @method \GuzzleHttp\Promise\Promise createAnomalyDetectorAsync(array $args = [])
18 * @method \Aws\Result createMetricSet(array $args = [])
19 * @method \GuzzleHttp\Promise\Promise createMetricSetAsync(array $args = [])
20 * @method \Aws\Result deleteAlert(array $args = [])
21 * @method \GuzzleHttp\Promise\Promise deleteAlertAsync(array $args = [])
22 * @method \Aws\Result deleteAnomalyDetector(array $args = [])
23 * @method \GuzzleHttp\Promise\Promise deleteAnomalyDetectorAsync(array $args = [])
24 * @method \Aws\Result describeAlert(array $args = [])
25 * @method \GuzzleHttp\Promise\Promise describeAlertAsync(array $args = [])
26 * @method \Aws\Result describeAnomalyDetectionExecutions(array $args = [])
27 * @method \GuzzleHttp\Promise\Promise describeAnomalyDetectionExecutionsAsync(array $args = [])
28 * @method \Aws\Result describeAnomalyDetector(array $args = [])
29 * @method \GuzzleHttp\Promise\Promise describeAnomalyDetectorAsync(array $args = [])
30 * @method \Aws\Result describeMetricSet(array $args = [])
31 * @method \GuzzleHttp\Promise\Promise describeMetricSetAsync(array $args = [])
32 * @method \Aws\Result getAnomalyGroup(array $args = [])
33 * @method \GuzzleHttp\Promise\Promise getAnomalyGroupAsync(array $args = [])
34 * @method \Aws\Result getFeedback(array $args = [])
35 * @method \GuzzleHttp\Promise\Promise getFeedbackAsync(array $args = [])
36 * @method \Aws\Result getSampleData(array $args = [])
37 * @method \GuzzleHttp\Promise\Promise getSampleDataAsync(array $args = [])
38 * @method \Aws\Result listAlerts(array $args = [])
39 * @method \GuzzleHttp\Promise\Promise listAlertsAsync(array $args = [])
40 * @method \Aws\Result listAnomalyDetectors(array $args = [])
41 * @method \GuzzleHttp\Promise\Promise listAnomalyDetectorsAsync(array $args = [])
42 * @method \Aws\Result listAnomalyGroupSummaries(array $args = [])
43 * @method \GuzzleHttp\Promise\Promise listAnomalyGroupSummariesAsync(array $args = [])
44 * @method \Aws\Result listAnomalyGroupTimeSeries(array $args = [])
45 * @method \GuzzleHttp\Promise\Promise listAnomalyGroupTimeSeriesAsync(array $args = [])
46 * @method \Aws\Result listMetricSets(array $args = [])
47 * @method \GuzzleHttp\Promise\Promise listMetricSetsAsync(array $args = [])
48 * @method \Aws\Result listTagsForResource(array $args = [])
49 * @method \GuzzleHttp\Promise\Promise listTagsForResourceAsync(array $args = [])
50 * @method \Aws\Result putFeedback(array $args = [])
51 * @method \GuzzleHttp\Promise\Promise putFeedbackAsync(array $args = [])
52 * @method \Aws\Result tagResource(array $args = [])
53 * @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = [])
54 * @method \Aws\Result untagResource(array $args = [])
55 * @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = [])
56 * @method \Aws\Result updateAnomalyDetector(array $args = [])
57 * @method \GuzzleHttp\Promise\Promise updateAnomalyDetectorAsync(array $args = [])
58 * @method \Aws\Result updateMetricSet(array $args = [])
59 * @method \GuzzleHttp\Promise\Promise updateMetricSetAsync(array $args = [])
60 */
61class LookoutMetricsClient extends AwsClient {
62    public function __construct(array $args)
63    {
64        parent::__construct($args);
65
66        // Setup middleware.
67        $stack = $this->getHandlerList();
68        $stack->appendBuild($this->updateContentType(), 'models.lookoutMetrics.v2.updateContentType');
69    }
70
71    /**
72     * Creates a middleware that updates the Content-Type header when it is present;
73     * this is necessary because the service protocol is rest-json which by default
74     * sets the content-type to 'application/json', but interacting with the service
75     * requires it to be set to x-amz-json-1.1
76     *
77     * @return callable
78     */
79    private function updateContentType()
80    {
81        return function (callable $handler) {
82            return function (
83                CommandInterface $command,
84                RequestInterface $request = null
85            ) use ($handler) {
86                $contentType = $request->getHeader('Content-Type');
87                if (!empty($contentType) && $contentType[0] == 'application/json') {
88                    return $handler($command, $request->withHeader(
89                        'Content-Type',
90                        'application/x-amz-json-1.1'
91                    ));
92                }
93                return $handler($command, $request);
94            };
95        };
96    }
97}
98