Skip to content

Commit cf373e9

Browse files
committed
Pull request #14: Release v2.5.0
Merge in SDK/java_telesign_enterprise from developer to master * commit '8f002111aae891962b3a148d9932546d83d481fc': Updating documentation Updating dependencies Updating changelog Adding verification process update Updating version Improving following PR comments Improving following PR comments Separating OmniVerifyClient and adding retrieve method
2 parents 9d99b9d + 8f00211 commit cf373e9

6 files changed

Lines changed: 235 additions & 112 deletions

File tree

RELEASE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2.5.0
2+
- Added method to retrieve verification process.
3+
- Added unit test for retrieving verification process.
4+
- Added method to update verification process.
5+
- Added unit test for updating verification process.
6+
17
2.4.0
28
- Added tracking to requests.
39

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.telesign.enterprise'
2-
version '2.4.0'
2+
version '2.5.0'
33

44
apply plugin: 'java'
55
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -11,7 +11,7 @@ repositories {
1111
}
1212

1313
dependencies {
14-
implementation('com.telesign:telesign:2.4.0')
14+
implementation('com.telesign:telesign:2.5.0')
1515
//implementation(project(":com.telesign"))
1616
implementation 'com.google.code.gson:gson:[2.7,3.0)'
1717
testImplementation( group: 'junit', name: 'junit', version: '[4.1,)')
@@ -79,7 +79,7 @@ publishing {
7979

8080
groupId = 'com.telesign.enterprise'
8181
artifactId = 'telesignenterprise'
82-
version = '2.3.1'
82+
version = '2.5.0'
8383

8484
pom {
8585
name = 'TeleSign Enterprise SDK'
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package com.telesign.enterprise;
2+
3+
import com.telesign.RestClient;
4+
5+
import java.io.IOException;
6+
import java.net.Proxy;
7+
import java.security.GeneralSecurityException;
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
public class OmniVerifyClient extends RestClient {
14+
private static final String VERIFY_STATUS_RESOURCE = "/v1/verify/%s";
15+
private static final String sdkVersion = VerifyClient.class.getPackage().getImplementationVersion();
16+
private static final String sdkSource = "java_telesign_enterprise";
17+
private static final String sdkVersionDependency = com.telesign.RestClient.class.getPackage()
18+
.getImplementationVersion();
19+
20+
21+
private static final String PATH_VERIFICATION = "/verification";
22+
private static final String PATH_VERIFICATION_RESOURCE = PATH_VERIFICATION + "/%s";
23+
private static final String PATH_VERIFICATION_RESOURCE_UPDATE = PATH_VERIFICATION + "/%s/state";
24+
25+
public OmniVerifyClient(String customerId, String apiKey) {
26+
super(customerId, apiKey, "https://verify.telesign.com", sdkSource, sdkVersion,
27+
sdkVersionDependency);
28+
}
29+
30+
public OmniVerifyClient(String customerId, String apiKey, String restEndpoint) {
31+
super(customerId, apiKey, restEndpoint, sdkSource, sdkVersion, sdkVersionDependency);
32+
}
33+
34+
public OmniVerifyClient(String customerId, String apiKey, String restEndpoint, Integer connectTimeout,
35+
Integer readTimeout, Integer writeTimeout, Proxy proxy, final String proxyUsername,
36+
final String proxyPassword) {
37+
super(customerId, apiKey, restEndpoint, connectTimeout, readTimeout, writeTimeout, proxy, proxyUsername,
38+
proxyPassword, sdkSource, sdkVersion, sdkVersionDependency);
39+
}
40+
41+
/**
42+
* Use this action to create a verification process for the specified phone number.
43+
* <p>
44+
* See https://developer.telesign.com/enterprise/reference/createverificationprocess for detailed API documentation.
45+
*/
46+
public TelesignResponse createVerificationProcess(String phoneNumber, HashMap<String, Object> params)
47+
throws IOException, GeneralSecurityException {
48+
49+
if (params == null) {
50+
params = new HashMap<>();
51+
}
52+
53+
HashMap<String, String> infoRecipient = new HashMap<>();
54+
infoRecipient.put("phone_number", phoneNumber);
55+
params.put("recipient", infoRecipient);
56+
57+
if (!params.containsKey("verification_policy")) {
58+
List<Object> infoVerificationPolicy = new ArrayList<>();
59+
HashMap<String, String> infoMethod = new HashMap<>();
60+
infoMethod.put("method", "sms");
61+
infoVerificationPolicy.add(infoMethod);
62+
params.put("verification_policy", infoVerificationPolicy);
63+
}
64+
return this.post(PATH_VERIFICATION, params, "application/json", "Basic");
65+
}
66+
67+
/**
68+
* Use this action to get a verification process for the specified reference ID.
69+
* <p>
70+
* See https://developer.telesign.com/enterprise/reference/getverificationprocess for detailed API documentation.
71+
*/
72+
public TelesignResponse getVerificationProcess(String referenceId)
73+
throws IOException, GeneralSecurityException {
74+
75+
return this.get(String.format(PATH_VERIFICATION_RESOURCE, referenceId), null);
76+
}
77+
78+
/**
79+
* Use this action to update a verification process for the specified reference ID.
80+
* <p>
81+
* See https://developer.telesign.com/enterprise/reference/updateverificationprocess for detailed API documentation.
82+
*/
83+
public TelesignResponse updateVerificationProcess(String referenceId, String action, String securityFactor)
84+
throws IOException, GeneralSecurityException {
85+
86+
Map<String, String> params = new HashMap<>();
87+
params.put("action", action);
88+
params.put("security_factor", securityFactor);
89+
90+
return patch(String.format(PATH_VERIFICATION_RESOURCE_UPDATE, referenceId), params, JSON_CONTENT_TYPE, AUTH_BASIC);
91+
}
92+
}

src/main/java/com/telesign/enterprise/VerifyClient.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import java.io.IOException;
66
import java.net.Proxy;
77
import java.security.GeneralSecurityException;
8-
import java.util.ArrayList;
98
import java.util.HashMap;
10-
import java.util.List;
119
import java.util.Map;
1210

1311
/**
@@ -128,54 +126,4 @@ public TelesignResponse status(String referenceId, Map<String, String> params) t
128126
public TelesignResponse completion(String referenceId, Map<String, String> params) throws IOException, GeneralSecurityException {
129127
return this.put(String.format(VERIFY_COMPLETION_RESOURCE, referenceId), params);
130128
}
131-
132-
static class OmniVerifyClient extends RestClient
133-
{
134-
private static final String PATH_VERIFICATION = "/verification";
135-
136-
public OmniVerifyClient(String customerId, String apiKey) {
137-
super(customerId, apiKey, "https://verify.telesign.com", sdkSource, sdkVersion, sdkVersionDependency);
138-
}
139-
140-
public OmniVerifyClient(String customerId, String apiKey, String restEndpoint) {
141-
super(customerId, apiKey, restEndpoint, sdkSource, sdkVersion, sdkVersionDependency);
142-
}
143-
144-
public OmniVerifyClient(String customerId,
145-
String apiKey,
146-
String restEndpoint,
147-
Integer connectTimeout,
148-
Integer readTimeout,
149-
Integer writeTimeout,
150-
Proxy proxy,
151-
final String proxyUsername,
152-
final String proxyPassword) {
153-
super(customerId, apiKey, restEndpoint, connectTimeout, readTimeout, writeTimeout, proxy, proxyUsername, proxyPassword, sdkSource, sdkVersion, sdkVersionDependency);
154-
}
155-
156-
/**
157-
* Use this action to create a verification process for the specified phone number.
158-
* <p>
159-
* See https://developer.telesign.com/enterprise/reference/createverificationprocess for detailed API documentation.
160-
*/
161-
public TelesignResponse createVerificationProcess(String phoneNumber, HashMap<String, Object> params) throws IOException, GeneralSecurityException {
162-
163-
if (params == null) {
164-
params = new HashMap<String, Object>();
165-
}
166-
167-
HashMap<String, String> infoRecipient = new HashMap<>();
168-
infoRecipient.put("phone_number", phoneNumber);
169-
params.put("recipient", infoRecipient);
170-
171-
if (!params.containsKey("verification_policy")) {
172-
List<Object> infoVerificationPolicy = new ArrayList<>();
173-
HashMap<String, String> infoMethod = new HashMap<>();
174-
infoMethod.put("method", "sms");
175-
infoVerificationPolicy.add(infoMethod);
176-
params.put("verification_policy", infoVerificationPolicy);
177-
}
178-
return this.post(PATH_VERIFICATION, params, "application/json", "Basic");
179-
}
180-
}
181129
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.telesign.enterprise;
2+
3+
import junit.framework.TestCase;
4+
import okhttp3.mockwebserver.MockResponse;
5+
import okhttp3.mockwebserver.MockWebServer;
6+
import okhttp3.mockwebserver.RecordedRequest;
7+
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.concurrent.TimeUnit;
12+
13+
public class OmniVerifyClientTest extends TestCase {
14+
15+
private MockWebServer mockServer;
16+
17+
private String customerId;
18+
private String apiKey;
19+
20+
public void setUp() throws Exception {
21+
super.setUp();
22+
23+
this.customerId = System.getenv("CUSTOMER_ID");
24+
this.apiKey = System.getenv("API_KEY");
25+
26+
if (this.customerId == null) this.customerId = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890";
27+
if (this.apiKey == null)
28+
this.apiKey = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==";
29+
30+
this.mockServer = new MockWebServer();
31+
this.mockServer.start();
32+
}
33+
34+
public void tearDown() throws Exception {
35+
super.tearDown();
36+
37+
this.mockServer.shutdown();
38+
}
39+
40+
public void testOmniVerifyClientCreateVerificationProcessWithoutParams() throws Exception {
41+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
42+
43+
OmniVerifyClient client = new OmniVerifyClient(this.customerId,
44+
this.apiKey,
45+
this.mockServer.url("").toString().replaceAll("/$", ""));
46+
47+
String phone_number = "11234567890";
48+
49+
client.createVerificationProcess(phone_number, null);
50+
51+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
52+
53+
String bodyExpected = String.format("{\"recipient\":{\"phone_number\":\"%s\"},\"verification_policy\":[{\"method\":\"sms\"}]}", phone_number);
54+
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
55+
assertEquals("method is not as expected", "POST", request.getMethod());
56+
assertEquals("path is not as expected", "/verification", request.getPath());
57+
assertEquals("Content-Type header is not as expected", "application/json", request.getHeader("Content-Type"));
58+
}
59+
60+
public void testOmniVerifyClientCreateVerificationProcessWithParams() throws Exception {
61+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
62+
63+
OmniVerifyClient client = new OmniVerifyClient(this.customerId,
64+
this.apiKey,
65+
this.mockServer.url("").toString().replaceAll("/$", ""));
66+
67+
String phone_number = "11234567890";
68+
69+
HashMap<String, Object> params = new HashMap<>();
70+
71+
List<Object> infoVerificationPolicy = new ArrayList<>();
72+
73+
HashMap<String, String> infoMethod1 = new HashMap<>();
74+
infoMethod1.put("method", "whatsapp");
75+
infoVerificationPolicy.add(infoMethod1);
76+
77+
HashMap<String, String> infoMethod2 = new HashMap<>();
78+
infoMethod2.put("method", "push");
79+
infoVerificationPolicy.add(infoMethod2);
80+
81+
params.put("verification_policy", infoVerificationPolicy);
82+
83+
client.createVerificationProcess(phone_number, params);
84+
85+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
86+
87+
String bodyExpected = String.format("{\"recipient\":{\"phone_number\":\"%s\"},\"verification_policy\":[{\"method\":\"whatsapp\"},{\"method\":\"push\"}]}", phone_number);
88+
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
89+
assertEquals("method is not as expected", "POST", request.getMethod());
90+
assertEquals("path is not as expected", "/verification", request.getPath());
91+
assertEquals("Content-Type header is not as expected", "application/json", request.getHeader("Content-Type"));
92+
}
93+
94+
public void testOmniVerifyClientRetrieveVerificationProcess() throws Exception {
95+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
96+
97+
OmniVerifyClient client = new OmniVerifyClient(this.customerId,
98+
this.apiKey,
99+
this.mockServer.url("").toString().replaceAll("/$", ""));
100+
101+
String referenceId = "referenceId";
102+
103+
client.getVerificationProcess(referenceId);
104+
105+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
106+
107+
assertEquals("body is not as expected", "", request.getBody().readUtf8());
108+
assertEquals("method is not as expected", "GET", request.getMethod());
109+
assertEquals("path is not as expected", String.format("/verification/%s", referenceId), request.getPath());
110+
}
111+
112+
public void testOmniVerifyClientUpdateVerificationProcess() throws Exception {
113+
this.mockServer.enqueue(new MockResponse().setBody("{}"));
114+
115+
OmniVerifyClient client = new OmniVerifyClient(this.customerId,
116+
this.apiKey,
117+
this.mockServer.url("").toString().replaceAll("/$", ""));
118+
119+
String referenceId = "referenceId";
120+
String action = "finalize";
121+
String securityFactor = "121212";
122+
123+
client.updateVerificationProcess(referenceId, action, securityFactor);
124+
125+
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
126+
127+
String bodyExpected = "{\"security_factor\":\"121212\",\"action\":\"finalize\"}";
128+
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
129+
assertEquals("method is not as expected", "PATCH", request.getMethod());
130+
assertEquals("path is not as expected", String.format("/verification/%s/state", referenceId), request.getPath());
131+
}
132+
133+
}

src/test/java/com/telesign/enterprise/VerifyClientTest.java

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -54,60 +54,4 @@ public void testVerifyClientConstructorFull() throws Exception {
5454
"");
5555
assertNotNull(client);
5656
}
57-
58-
public void testVerifyClientEndpointVerificationWithoutParams() throws Exception {
59-
this.mockServer.enqueue(new MockResponse().setBody("{}"));
60-
61-
VerifyClient.OmniVerifyClient client = new VerifyClient.OmniVerifyClient(this.customerId,
62-
this.apiKey,
63-
this.mockServer.url("").toString().replaceAll("/$", ""));
64-
65-
String phone_number = "11234567890";
66-
67-
client.createVerificationProcess(phone_number, null);
68-
69-
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
70-
71-
String bodyExpected = String.format("{\"recipient\":{\"phone_number\":\"%s\"},\"verification_policy\":[{\"method\":\"sms\"}]}", phone_number);
72-
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
73-
assertEquals("method is not as expected", "POST", request.getMethod());
74-
assertEquals("path is not as expected", "/verification", request.getPath());
75-
assertEquals("Content-Type header is not as expected", "application/json", request.getHeader("Content-Type"));
76-
}
77-
78-
public void testVerifyClientEndpointVerificationWithParams() throws Exception {
79-
this.mockServer.enqueue(new MockResponse().setBody("{}"));
80-
81-
VerifyClient.OmniVerifyClient client = new VerifyClient.OmniVerifyClient(this.customerId,
82-
this.apiKey,
83-
this.mockServer.url("").toString().replaceAll("/$", ""));
84-
85-
String phone_number = "11234567890";
86-
87-
HashMap<String, Object> params = new HashMap<>();
88-
89-
List<Object> infoVerificationPolicy = new ArrayList<>();
90-
91-
HashMap<String, String> infoMethod1 = new HashMap<>();
92-
infoMethod1.put("method", "whatsapp");
93-
infoVerificationPolicy.add(infoMethod1);
94-
95-
HashMap<String, String> infoMethod2 = new HashMap<>();
96-
infoMethod2.put("method", "push");
97-
infoVerificationPolicy.add(infoMethod2);
98-
99-
params.put("verification_policy", infoVerificationPolicy);
100-
101-
client.createVerificationProcess(phone_number, params);
102-
103-
RecordedRequest request = this.mockServer.takeRequest(1, TimeUnit.SECONDS);
104-
105-
String bodyExpected = String.format("{\"recipient\":{\"phone_number\":\"%s\"},\"verification_policy\":[{\"method\":\"whatsapp\"},{\"method\":\"push\"}]}", phone_number);
106-
assertEquals("body is not as expected", bodyExpected, request.getBody().readUtf8());
107-
assertEquals("method is not as expected", "POST", request.getMethod());
108-
assertEquals("path is not as expected", "/verification", request.getPath());
109-
assertEquals("Content-Type header is not as expected", "application/json", request.getHeader("Content-Type"));
110-
}
111-
}
112-
113-
57+
}

0 commit comments

Comments
 (0)