Skip to content

Commit c1fb9d4

Browse files
committed
Empty constructor pulbic and with methods for one dii are available
1 parent 3df6e35 commit c1fb9d4

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

src/main/java/com/uid2/client/IdentityMapV3Input.java

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,65 @@ public static IdentityMapV3Input fromHashedPhones(List<String> hashedPhones) {
4545
@SerializedName("phone_hash")
4646
private final List<Identity> hashedPhones = new ArrayList<>();
4747

48-
private IdentityMapV3Input() {}
48+
public IdentityMapV3Input() {}
4949

5050
public IdentityMapV3Input withHashedEmails(List<String> hashedEmails) {
5151
for (String hashedEmail : hashedEmails) {
52-
this.hashedEmails.add(new Identity(hashedEmail));
53-
addToDiiMappings(hashedEmail, hashedEmail);
52+
withHashedEmail(hashedEmail);
5453
}
5554
return this;
5655
}
5756

57+
public IdentityMapV3Input withHashedEmail(String hashedEmail) {
58+
this.hashedEmails.add(new Identity(hashedEmail));
59+
addToDiiMappings(hashedEmail, hashedEmail);
60+
return this;
61+
}
62+
5863
public IdentityMapV3Input withHashedPhones(List<String> hashedPhones) {
5964
for (String hashedPhone : hashedPhones) {
60-
this.hashedPhones.add(new Identity(hashedPhone));
61-
addToDiiMappings(hashedPhone, hashedPhone);
65+
withHashedPhone(hashedPhone);
6266
}
6367
return this;
6468
}
6569

70+
public IdentityMapV3Input withHashedPhone(String hashedPhone) {
71+
this.hashedPhones.add(new Identity(hashedPhone));
72+
addToDiiMappings(hashedPhone, hashedPhone);
73+
return this;
74+
}
75+
6676
public IdentityMapV3Input withEmails(List<String> emails) {
6777
for (String email : emails) {
68-
String hash = InputUtil.normalizeAndHashEmail(email);
69-
this.hashedEmails.add(new Identity(hash));
70-
addToDiiMappings(hash, email);
78+
withEmail(email);
7179
}
7280
return this;
7381
}
7482

83+
public IdentityMapV3Input withEmail(String email) {
84+
String hashedEmail = InputUtil.normalizeAndHashEmail(email);
85+
this.hashedEmails.add(new Identity(hashedEmail));
86+
addToDiiMappings(hashedEmail, email);
87+
return this;
88+
}
89+
7590
public IdentityMapV3Input withPhones(List<String> phones) {
7691
for (String phone : phones) {
77-
if (!InputUtil.isPhoneNumberNormalized(phone)) {
78-
throw new IllegalArgumentException("phone number is not normalized: " + phone);
79-
}
92+
withPhone(phone);
93+
}
94+
return this;
95+
}
8096

81-
String hash = InputUtil.getBase64EncodedHash(phone);
82-
this.hashedPhones.add(new Identity(hash));
83-
addToDiiMappings(hash, phone);
97+
public IdentityMapV3Input withPhone(String phone) {
98+
if (!InputUtil.isPhoneNumberNormalized(phone)) {
99+
throw new IllegalArgumentException("phone number is not normalized: " + phone);
84100
}
101+
102+
String hashedPhone = InputUtil.getBase64EncodedHash(phone);
103+
this.hashedPhones.add(new Identity(hashedPhone));
104+
addToDiiMappings(hashedPhone, phone);
85105
return this;
106+
86107
}
87108

88109
private void addToDiiMappings(String hashedDii, String rawDii) {

src/main/java/com/uid2/client/IdentityMapV3Response.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ private void populateIdentitiesForType(IdentityMapV3Input identityMapInput, Stri
2929
for (int i = 0; i < identities.size(); i++) {
3030
ApiIdentity apiIdentity = identities.get(i);
3131
List<String> rawDiis = identityMapInput.getRawDiis(identityType, i);
32-
for (String rawDii : rawDiis)
32+
for (String rawDii : rawDiis) {
3333
if (apiIdentity.error != null) {
3434
unmappedIdentities.put(rawDii, new UnmappedIdentity(apiIdentity));
3535
} else {
3636
mappedIdentities.put(rawDii, new MappedIdentity(apiIdentity));
3737
}
38+
}
3839
}
3940
}
4041

src/test/java/com/uid2/client/IdentityMapV3IntegrationTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void identityMapAllIdentityTypesInOneRequest() {
170170
.withHashedEmails(Arrays.asList(mappedEmailHash, optedOutEmailHash))
171171
.withPhones(Arrays.asList(mappedPhone, optedOutPhone))
172172
.withHashedPhones(Arrays.asList(mappedPhoneHash, optedOutPhoneHash));
173-
173+
174174
Response response = new Response(identityMapInput);
175175

176176
response.assertMapped(mappedEmail);
@@ -184,6 +184,24 @@ public void identityMapAllIdentityTypesInOneRequest() {
184184
response.assertUnmapped("OPTOUT", optedOutPhoneHash);
185185
}
186186

187+
@Test
188+
public void identityMapAllIdentityTypesInOneRequestAddedOneByOne() {
189+
IdentityMapV3Input identityMapInput = new IdentityMapV3Input();
190+
191+
identityMapInput.withEmail(mappedEmail);
192+
identityMapInput.withPhone(optedOutPhone);
193+
identityMapInput.withHashedPhone(mappedPhoneHash);
194+
identityMapInput.withHashedEmail(optedOutEmailHash);
195+
196+
Response response = new Response(identityMapInput);
197+
198+
response.assertMapped(mappedEmail);
199+
response.assertMapped(mappedPhoneHash);
200+
201+
response.assertUnmapped("OPTOUT", optedOutPhone);
202+
response.assertUnmapped("OPTOUT", optedOutEmailHash);
203+
}
204+
187205

188206
class Response {
189207
Response(IdentityMapV3Input identityMapInput) {

0 commit comments

Comments
 (0)