Skip to content

Commit b127cc9

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/ThreatMonitoring/AlertClient.php
2 parents 646789d + 4a1911f commit b127cc9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Client.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace UKFast\SDK;
44

5+
use DateTime;
56
use GuzzleHttp\Client as HttpClient;
67
use GuzzleHttp\Exception\ClientException;
78
use GuzzleHttp\Exception\GuzzleException;
@@ -282,6 +283,14 @@ public function apiToFriendly($item, $map)
282283
*/
283284
public function friendlyToApi($item, $map)
284285
{
285-
return $this->apiToFriendly($item, array_flip($map));
286+
$item = $this->apiToFriendly($item, array_flip($map));
287+
288+
array_walk_recursive($item, function (&$value) {
289+
if (is_object($value) && get_class($value) === DateTime::class) {
290+
$value = $value->format(DateTime::ATOM);
291+
}
292+
});
293+
294+
return $item;
286295
}
287296
}

tests/ClientTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests;
44

5+
use DateTime;
56
use GuzzleHttp\Client as Guzzle;
67
use GuzzleHttp\HandlerStack;
78
use GuzzleHttp\Handler\MockHandler;
@@ -446,6 +447,25 @@ public function maps_friendly_names_to_api_names()
446447
], $api);
447448
}
448449

450+
/**
451+
* @test
452+
*/
453+
public function maps_friendly_names_to_api_names_with_datetime_objects()
454+
{
455+
$map = ['created_at' => 'createdAt'];
456+
$api = (new Client)->friendlyToApi([
457+
'id' => 1,
458+
'createdAt' => new DateTime('2018-01-01T10:00:00+00:00'),
459+
'name' => 'Test',
460+
], $map);
461+
462+
$this->assertEquals([
463+
'id' => 1,
464+
'created_at' => '2018-01-01T10:00:00+00:00',
465+
'name' => 'Test',
466+
], $api);
467+
}
468+
449469
/**
450470
* @test
451471
*/

0 commit comments

Comments
 (0)