From f84fb017da1b997583209057c29669442b647d00 Mon Sep 17 00:00:00 2001
From: jon8787 <112368577+jon8787@users.noreply.github.com>
Date: Tue, 20 Feb 2024 14:19:13 +1100
Subject: [PATCH] javadocs
---
.../com/uid2/client/IdentityMapClient.java | 20 ++++++++++++-----
.../com/uid2/client/IdentityMapHelper.java | 11 ++++++++++
.../com/uid2/client/IdentityMapInput.java | 10 ++++-----
.../client/IdentityMapIntegrationTests.java | 22 ++++++++++++++++++-
4 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/uid2/client/IdentityMapClient.java b/src/main/java/com/uid2/client/IdentityMapClient.java
index f91d45e..0f98dea 100644
--- a/src/main/java/com/uid2/client/IdentityMapClient.java
+++ b/src/main/java/com/uid2/client/IdentityMapClient.java
@@ -1,18 +1,28 @@
package com.uid2.client;
public class IdentityMapClient {
+ /**
+ * @param uid2BaseUrl The UID2 Base URL
+ * @param clientApiKey Your client API key
+ * @param base64SecretKey Your client secret key
+ */
IdentityMapClient(String uid2BaseUrl, String clientApiKey, String base64SecretKey) {
- advertiserAndDataProviderUid2Helper = new IdentityMapHelper(base64SecretKey);
+ identityMapHelper = new IdentityMapHelper(base64SecretKey);
uid2ClientHelper = new Uid2ClientHelper(uid2BaseUrl, clientApiKey);
}
+ /**
+ * @param identityMapInput represents the input required for /identity/map
+ * @return an IdentityMapResponse instance
+ * @throws Uid2Exception if the response did not contain a "success" status, or the response code was not 200, or there was an error communicating with the provided UID2 Base URL
+ */
public IdentityMapResponse generateIdentityMap(IdentityMapInput identityMapInput) {
- EnvelopeV2 envelope = advertiserAndDataProviderUid2Helper.createEnvelopeForIdentityMapRequest(identityMapInput);
+ EnvelopeV2 envelope = identityMapHelper.createEnvelopeForIdentityMapRequest(identityMapInput);
String responseString = uid2ClientHelper.makeRequest(envelope, "/v2/identity/map");
- return advertiserAndDataProviderUid2Helper.createIdentityMapResponse(responseString, envelope, identityMapInput);
+ return identityMapHelper.createIdentityMapResponse(responseString, envelope, identityMapInput);
}
- IdentityMapHelper advertiserAndDataProviderUid2Helper;
- Uid2ClientHelper uid2ClientHelper;
+ private final IdentityMapHelper identityMapHelper;
+ private final Uid2ClientHelper uid2ClientHelper;
}
diff --git a/src/main/java/com/uid2/client/IdentityMapHelper.java b/src/main/java/com/uid2/client/IdentityMapHelper.java
index cf00c61..209c610 100644
--- a/src/main/java/com/uid2/client/IdentityMapHelper.java
+++ b/src/main/java/com/uid2/client/IdentityMapHelper.java
@@ -8,11 +8,22 @@ public class IdentityMapHelper {
*/
public IdentityMapHelper(String base64SecretKey) {uid2Helper = new Uid2Helper(base64SecretKey);}
+ /**
+ * @param identityMapInput represents the input required for /identity/map
+ * @return an EnvelopeV2 instance to use in the POST body of /identity/map
+ */
public EnvelopeV2 createEnvelopeForIdentityMapRequest(IdentityMapInput identityMapInput) {
byte[] jsonBytes = identityMapInput.getAsJsonString().getBytes(StandardCharsets.UTF_8);
return uid2Helper.createEnvelopeV2(jsonBytes);
}
+
+ /**
+ * @param responseString the response body returned by a call to /identity/map
+ * @param envelope the EnvelopeV2 instance returned by {@link #createEnvelopeForIdentityMapRequest}
+ * @param identityMapInput the same instance that was passed to {@link #createEnvelopeForIdentityMapRequest}.
+ * @return an IdentityMapResponse instance
+ */
public IdentityMapResponse createIdentityMapResponse(String responseString, EnvelopeV2 envelope, IdentityMapInput identityMapInput) {
String decryptedResponseString = uid2Helper.decrypt(responseString, envelope.getNonce());
return new IdentityMapResponse(decryptedResponseString, identityMapInput);
diff --git a/src/main/java/com/uid2/client/IdentityMapInput.java b/src/main/java/com/uid2/client/IdentityMapInput.java
index 947f120..8d6e1db 100644
--- a/src/main/java/com/uid2/client/IdentityMapInput.java
+++ b/src/main/java/com/uid2/client/IdentityMapInput.java
@@ -10,7 +10,7 @@
public class IdentityMapInput {
/**
* @param emails a list of normalized or unnormalized email addresses
- * @return a IdentityMapInput instance, to be used in {@link PublisherUid2Helper#createEnvelopeForTokenGenerateRequest}
+ * @return a IdentityMapInput instance, to be used in {@link IdentityMapHelper#createEnvelopeForIdentityMapRequest}
*/
public static IdentityMapInput fromEmails(Iterable emails) {
return new IdentityMapInput(IdentityType.Email, emails, false);
@@ -18,7 +18,7 @@ public static IdentityMapInput fromEmails(Iterable emails) {
/**
* @param phones a normalized phone number
- * @return a IdentityMapInput instance, to be used in {@link PublisherUid2Helper#createEnvelopeForTokenGenerateRequest}
+ * @return an IdentityMapInput instance
*/
public static IdentityMapInput fromPhones(Iterable phones) {
return new IdentityMapInput(IdentityType.Phone, phones, false);
@@ -26,7 +26,7 @@ public static IdentityMapInput fromPhones(Iterable phones) {
/**
* @param hashedEmails a normalized and hashed email address
- * @return a IdentityMapInput instance, to be used in {@link PublisherUid2Helper#createEnvelopeForTokenGenerateRequest}
+ * @return an IdentityMapInput instance
*/
public static IdentityMapInput fromHashedEmails(Iterable hashedEmails) {
return new IdentityMapInput(IdentityType.Email, hashedEmails, true);
@@ -34,7 +34,7 @@ public static IdentityMapInput fromHashedEmails(Iterable hashedEmails) {
/**
* @param hashedPhones a normalized and hashed phone number
- * @return a IdentityMapInput instance, to be used in {@link PublisherUid2Helper#createEnvelopeForTokenGenerateRequest}
+ * @return an IdentityMapInput instance
*/
public static IdentityMapInput fromHashedPhones(Iterable hashedPhones) {
return new IdentityMapInput(IdentityType.Phone, hashedPhones, true);
@@ -48,7 +48,7 @@ String getAsJsonString() {
}
}
- private IdentityMapInput(IdentityType identityType, Iterable emailsOrPhones, boolean alreadyHashed) {
+ private IdentityMapInput(IdentityType identityType, Iterable emailsOrPhones, boolean alreadyHashed) {
this.identityType = identityType;
this.emailsOrPhones = emailsOrPhones;
this.alreadyHashed = alreadyHashed;
diff --git a/src/test/java/com/uid2/client/IdentityMapIntegrationTests.java b/src/test/java/com/uid2/client/IdentityMapIntegrationTests.java
index 5cee75b..275e6e9 100644
--- a/src/test/java/com/uid2/client/IdentityMapIntegrationTests.java
+++ b/src/test/java/com/uid2/client/IdentityMapIntegrationTests.java
@@ -14,7 +14,7 @@
//most tests in this class require these env vars to be configured: UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY
@EnabledIfEnvironmentVariable(named = "UID2_BASE_URL", matches = "\\S+")
public class IdentityMapIntegrationTests {
- final IdentityMapClient identityMapClient = new IdentityMapClient(System.getenv("UID2_BASE_URL"), System.getenv("UID2_API_KEY"), System.getenv("UID2_SECRET_KEY"));
+ final private IdentityMapClient identityMapClient = new IdentityMapClient(System.getenv("UID2_BASE_URL"), System.getenv("UID2_API_KEY"), System.getenv("UID2_SECRET_KEY"));
@Test
public void identityMapEmails() {
@@ -157,4 +157,24 @@ public void identityMapEmailsUseOwnHttp() {
}
}
+ @Test
+ public void identityMapBadUrl() {
+ IdentityMapClient identityMapClient = new IdentityMapClient("https://operator-bad-url.uidapi.com", System.getenv("UID2_API_KEY"), System.getenv("UID2_SECRET_KEY"));
+ IdentityMapInput identityMapInput = IdentityMapInput.fromEmails(Collections.singletonList("email@example.com"));
+ assertThrows(Uid2Exception.class, () -> identityMapClient.generateIdentityMap(identityMapInput));
+ }
+
+ @Test
+ public void identityMapBadApiKey() {
+ IdentityMapClient identityMapClient = new IdentityMapClient(System.getenv("UID2_BASE_URL"), "bad-api-key", System.getenv("UID2_SECRET_KEY"));
+ IdentityMapInput identityMapInput = IdentityMapInput.fromEmails(Collections.singletonList("email@example.com"));
+ assertThrows(Uid2Exception.class, () -> identityMapClient.generateIdentityMap(identityMapInput));
+ }
+
+ @Test
+ public void identityMapBadSecret() {
+ IdentityMapClient identityMapClient = new IdentityMapClient(System.getenv("UID2_BASE_URL"), System.getenv("UID2_API_KEY"), "wJ0hP19QU4hmpB64Y3fV2dAed8t/mupw3sjN5jNRFzg=");
+ IdentityMapInput identityMapInput = IdentityMapInput.fromEmails(Collections.singletonList("email@example.com"));
+ assertThrows(Uid2Exception.class, () -> identityMapClient.generateIdentityMap(identityMapInput));
+ }
}