Skip to content

Commit 6512884

Browse files
author
idjuric
committed
Generate headers made as static method
1 parent a3fc613 commit 6512884

File tree

5 files changed

+441
-340
lines changed

5 files changed

+441
-340
lines changed

src/main/java/com/telesign/PhoneIdClient.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package com.telesign;
22

33
import java.io.IOException;
4+
import java.io.UnsupportedEncodingException;
45
import java.net.Proxy;
56
import java.security.GeneralSecurityException;
67
import java.util.Map;
78

9+
import okhttp3.MediaType;
10+
import okhttp3.RequestBody;
11+
import com.google.gson.Gson;;
12+
813
/**
914
* A set of APIs that deliver deep phone number data attributes that help optimize the end user
1015
* verification process and evaluate risk.
1116
*/
1217
public class PhoneIdClient extends RestClient {
1318

1419
private static final String PHONEID_RESOURCE = "/v1/phoneid/%s";
20+
21+
public static final MediaType JSON = MediaType.parse("application/json"); // ; charset=utf-8
1522

1623
public PhoneIdClient(String customerId, String apiKey) {
1724
super(customerId, apiKey);
@@ -37,10 +44,22 @@ public PhoneIdClient(String customerId,
3744
* The PhoneID API provides a cleansed phone number, phone type, and telecom carrier information to determine the
3845
* best communication method - SMS or voice.
3946
* <p>
40-
* See https://developer.telesign.com/docs/phoneid-api for detailed API documentation.
47+
* See https://developer.te
48+
* lesign.com/docs/phoneid-api for detailed API documentation.
4149
*/
42-
public TelesignResponse phoneid(String phoneNumber, Map<String, String> params) throws IOException, GeneralSecurityException {
50+
public TelesignResponse phoneid(String phoneNumber, Map<String, ? extends Object> params) throws IOException, GeneralSecurityException {
4351

4452
return this.post(String.format(PHONEID_RESOURCE, phoneNumber), params);
45-
}
53+
}
54+
55+
@Override
56+
public RequestBody createRequestBody(Map<String, ? extends Object> params) throws UnsupportedEncodingException {
57+
String jsonString = (new Gson()).toJson(params);
58+
return params != null ? RequestBody.create(PhoneIdClient.JSON, jsonString.getBytes()) : RequestBody.create(PhoneIdClient.JSON, "");
59+
}
60+
61+
@Override
62+
protected String getContentType() {
63+
return "application/json";
64+
}
4665
}

0 commit comments

Comments
 (0)