@@ -240,7 +240,11 @@ public function getUnit(): ?string
240240 public function request (): Request
241241 {
242242 // Prepare headers
243- $ headers = ['content-type ' => 'application/x-www-form-urlencoded ' ];
243+ $ headers = [
244+ 'Content-Type ' => 'application/x-amz-json-1.0 ' ,
245+ 'X-Amz-Target ' => 'GraniteServiceVersion20100801.GetMetricStatistics ' ,
246+ 'Accept ' => 'application/json ' ,
247+ ];
244248
245249 // Prepare query
246250 $ query = [];
@@ -249,7 +253,8 @@ public function request(): Request
249253 $ uriString = '/ ' ;
250254
251255 // Prepare Body
252- $ body = http_build_query (['Action ' => 'GetMetricStatistics ' , 'Version ' => '2010-08-01 ' ] + $ this ->requestBody (), '' , '& ' , \PHP_QUERY_RFC1738 );
256+ $ bodyPayload = $ this ->requestBody ();
257+ $ body = empty ($ bodyPayload ) ? '{} ' : json_encode ($ bodyPayload , 4194304 );
253258
254259 // Return the Request
255260 return new Request ('POST ' , $ uriString , $ query , $ headers , StreamFactory::create ($ body ));
@@ -342,41 +347,42 @@ private function requestBody(): array
342347 }
343348 $ payload ['MetricName ' ] = $ v ;
344349 if (null !== $ v = $ this ->dimensions ) {
345- $ index = 0 ;
346- foreach ($ v as $ mapValue ) {
350+ $ index = -1 ;
351+ $ payload ['Dimensions ' ] = [];
352+ foreach ($ v as $ listValue ) {
347353 ++$ index ;
348- foreach ($ mapValue ->requestBody () as $ bodyKey => $ bodyValue ) {
349- $ payload ["Dimensions.member. $ index. $ bodyKey " ] = $ bodyValue ;
350- }
354+ $ payload ['Dimensions ' ][$ index ] = $ listValue ->requestBody ();
351355 }
352356 }
353357 if (null === $ v = $ this ->startTime ) {
354358 throw new InvalidArgument (\sprintf ('Missing parameter "StartTime" for "%s". The value cannot be null. ' , __CLASS__ ));
355359 }
356- $ payload ['StartTime ' ] = $ v ->format (\DateTimeInterface:: ATOM );
360+ $ payload ['StartTime ' ] = $ v ->getTimestamp ( );
357361 if (null === $ v = $ this ->endTime ) {
358362 throw new InvalidArgument (\sprintf ('Missing parameter "EndTime" for "%s". The value cannot be null. ' , __CLASS__ ));
359363 }
360- $ payload ['EndTime ' ] = $ v ->format (\DateTimeInterface:: ATOM );
364+ $ payload ['EndTime ' ] = $ v ->getTimestamp ( );
361365 if (null === $ v = $ this ->period ) {
362366 throw new InvalidArgument (\sprintf ('Missing parameter "Period" for "%s". The value cannot be null. ' , __CLASS__ ));
363367 }
364368 $ payload ['Period ' ] = $ v ;
365369 if (null !== $ v = $ this ->statistics ) {
366- $ index = 0 ;
367- foreach ($ v as $ mapValue ) {
370+ $ index = -1 ;
371+ $ payload ['Statistics ' ] = [];
372+ foreach ($ v as $ listValue ) {
368373 ++$ index ;
369- if (!Statistic::exists ($ mapValue )) {
370- throw new InvalidArgument (\sprintf ('Invalid parameter "Statistics.member " for "%s". The value "%s" is not a valid "Statistic". ' , __CLASS__ , $ mapValue ));
374+ if (!Statistic::exists ($ listValue )) {
375+ throw new InvalidArgument (\sprintf ('Invalid parameter "Statistics" for "%s". The value "%s" is not a valid "Statistic". ' , __CLASS__ , $ listValue ));
371376 }
372- $ payload [" Statistics.member. $ index" ] = $ mapValue ;
377+ $ payload [' Statistics ' ][ $ index ] = $ listValue ;
373378 }
374379 }
375380 if (null !== $ v = $ this ->extendedStatistics ) {
376- $ index = 0 ;
377- foreach ($ v as $ mapValue ) {
381+ $ index = -1 ;
382+ $ payload ['ExtendedStatistics ' ] = [];
383+ foreach ($ v as $ listValue ) {
378384 ++$ index ;
379- $ payload [" ExtendedStatistics.member. $ index" ] = $ mapValue ;
385+ $ payload [' ExtendedStatistics ' ][ $ index ] = $ listValue ;
380386 }
381387 }
382388 if (null !== $ v = $ this ->unit ) {
0 commit comments