-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
package com.uid2.client; | ||
|
||
public class IdentityMapClient { | ||
/** | ||
* @param uid2BaseUrl The <a href="https://unifiedid.com/docs/getting-started/gs-environments">UID2 Base URL</a> | ||
* @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 <a href="https://unifiedid.com/docs/endpoints/post-identity-map">/identity/map</a> | ||
* @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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 protected]")); | ||
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 protected]")); | ||
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 protected]")); | ||
assertThrows(Uid2Exception.class, () -> identityMapClient.generateIdentityMap(identityMapInput)); | ||
} | ||
} |