Skip to content

Commit 756d312

Browse files
committed
feat(contact): Standardize info output with flat postal keys
1 parent 5dbc1fd commit 756d312

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

docs/api-contact.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ array{
5252
id: string|null,
5353
roid: string|null,
5454
statuses: list<string>,
55+
postalType: string|null,
56+
postalName: string|null,
57+
postalOrganization: string|null,
58+
postalStreet1: string|null,
59+
postalStreet2: string|null,
60+
postalStreet3: string|null,
61+
postalCity: string|null,
62+
postalCountryCode: string|null,
63+
postalProvince: string|null,
64+
postalPostalCode: string|null,
5565
postalInfo: array{
5666
type: string,
5767
name: string,

src/Contact/ContactResponseMapper.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public function mapCreateResponse(ContactCreateResponse $response): array
4242
* id: string|null,
4343
* roid: string|null,
4444
* statuses: list<string>,
45+
* postalType: string|null,
46+
* postalName: string|null,
47+
* postalOrganization: string|null,
48+
* postalStreet1: string|null,
49+
* postalStreet2: string|null,
50+
* postalStreet3: string|null,
51+
* postalCity: string|null,
52+
* postalCountryCode: string|null,
53+
* postalProvince: string|null,
54+
* postalPostalCode: string|null,
4555
* postalInfo: array{
4656
* type: string,
4757
* name: string,
@@ -75,8 +85,29 @@ public function mapCreateResponse(ContactCreateResponse $response): array
7585
public function mapInfoResponse(ContactInfoResponse $response): array
7686
{
7787
$postalInfo = null;
88+
$postalType = null;
89+
$postalName = null;
90+
$postalOrganization = null;
91+
$postalStreet1 = null;
92+
$postalStreet2 = null;
93+
$postalStreet3 = null;
94+
$postalCity = null;
95+
$postalCountryCode = null;
96+
$postalProvince = null;
97+
$postalPostalCode = null;
7898

7999
if (null !== $response->postalInfo) {
100+
$postalType = $response->postalInfo->type;
101+
$postalName = $response->postalInfo->name;
102+
$postalOrganization = $response->postalInfo->organization;
103+
$postalStreet1 = $response->postalInfo->address->streets[0] ?? null;
104+
$postalStreet2 = $response->postalInfo->address->streets[1] ?? null;
105+
$postalStreet3 = $response->postalInfo->address->streets[2] ?? null;
106+
$postalCity = $response->postalInfo->address->city;
107+
$postalCountryCode = $response->postalInfo->address->countryCode;
108+
$postalProvince = $response->postalInfo->address->province;
109+
$postalPostalCode = $response->postalInfo->address->postalCode;
110+
80111
$postalInfo = [
81112
'address' => [
82113
'city' => $response->postalInfo->address->city,
@@ -104,7 +135,17 @@ public function mapInfoResponse(ContactInfoResponse $response): array
104135
'identExpiry' => $response->identExpiry,
105136
'identKind' => $response->identKind,
106137
'legalEntity' => $response->legalEntity,
138+
'postalCity' => $postalCity,
139+
'postalCountryCode' => $postalCountryCode,
107140
'postalInfo' => $postalInfo,
141+
'postalName' => $postalName,
142+
'postalOrganization' => $postalOrganization,
143+
'postalPostalCode' => $postalPostalCode,
144+
'postalProvince' => $postalProvince,
145+
'postalStreet1' => $postalStreet1,
146+
'postalStreet2' => $postalStreet2,
147+
'postalStreet3' => $postalStreet3,
148+
'postalType' => $postalType,
108149
'roid' => $response->roid,
109150
'statuses' => $response->statuses,
110151
'transferDate' => $response->transferDate,

tests/Unit/Contact/ContactResponseMapperTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public function testMapInfoResponse(): void
7575

7676
self::assertSame('C-300', $mapped['id']);
7777
self::assertSame('ok', $mapped['statuses'][0]);
78+
self::assertSame('loc', $mapped['postalType']);
79+
self::assertSame('Person Example', $mapped['postalName']);
80+
self::assertNull($mapped['postalOrganization']);
81+
self::assertSame('Main 1', $mapped['postalStreet1']);
82+
self::assertNull($mapped['postalStreet2']);
83+
self::assertNull($mapped['postalStreet3']);
84+
self::assertSame('Belgrade', $mapped['postalCity']);
85+
self::assertSame('RS', $mapped['postalCountryCode']);
86+
self::assertNull($mapped['postalProvince']);
87+
self::assertNull($mapped['postalPostalCode']);
7888
self::assertSame('Belgrade', $mapped['postalInfo']['address']['city']);
7989
self::assertSame('12345', $mapped['ident']);
8090
}

tests/Unit/Contact/ContactServiceTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ public function readFrame(): string
177177
self::assertStringContainsString('<contact:info', $transport->writtenPayload);
178178
self::assertSame('C-300', $result['id']);
179179
self::assertSame('ok', $result['statuses'][0]);
180+
self::assertSame('loc', $result['postalType']);
181+
self::assertSame('Person Example', $result['postalName']);
182+
self::assertSame('Main 1', $result['postalStreet1']);
183+
self::assertNull($result['postalStreet2']);
184+
self::assertNull($result['postalStreet3']);
185+
self::assertSame('Belgrade', $result['postalCity']);
186+
self::assertSame('RS', $result['postalCountryCode']);
180187
self::assertSame('Belgrade', $result['postalInfo']['address']['city']);
181188
self::assertSame('12345', $result['ident']);
182189
}

0 commit comments

Comments
 (0)