Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.9.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/co/dapi/DapiRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import co.dapi.types.UserInput;
import com.google.gson.*;
import okhttp3.*;
import okhttp3.logging.HttpLoggingInterceptor;

import java.io.IOException;
import java.lang.reflect.Type;
Expand All @@ -24,10 +25,19 @@ public class DapiRequest {
.registerTypeAdapter(HashMap.class, new SDKRequestSerializer())
.create();

private final static OkHttpClient httpClient = new OkHttpClient().newBuilder()
.readTimeout(2, TimeUnit.MINUTES)
.build();
private static OkHttpClient httpClient = null;

private static OkHttpClient getHttpClient(){
if(httpClient == null){
HttpLoggingInterceptor logger = new HttpLoggingInterceptor();
logger.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient = new OkHttpClient().newBuilder()
.addInterceptor(logger)
.readTimeout(2, TimeUnit.MINUTES)
.build();
}
return httpClient;
}

public static Response HandleSDK(String bodyJson, HashMap<String, String> headersMap) throws IOException {
headersMap.put("host", "dd.dapi.com");
Expand Down Expand Up @@ -73,7 +83,7 @@ private static Response doRequest(String bodyJson, String url, HashMap<String, S
.build();

// Execute the request and return the response
return httpClient.newCall(req).execute();
return getHttpClient().newCall(req).execute();
}

static class BaseRequest {
Expand Down
43 changes: 39 additions & 4 deletions src/main/java/co/dapi/types/UserInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import java.util.Optional;

public class UserInput {
private final UserInputID id;
private final int index;
private final String query;
private final String answer;
private UserInputID id;
private int index;
private String query;
private String answer;

/**
* Creates an empty UserInput object.
*
*/
public UserInput() {
}

/**
* Creates a UserInput object with all of its info.
Expand Down Expand Up @@ -50,6 +57,13 @@ public UserInputID getId() {
return id;
}

/**
* Sets the id field.
*/
public void setId(UserInputID id) {
this.id = id;
}

/**
* returns the index of this UserInput, starting from 0.
* will always be 0 if only one input is requested.
Expand All @@ -58,13 +72,27 @@ public int getIndex() {
return index;
}

/**
* Sets the index.
*/
public void setIndex(int index) {
this.index = index;
}

/**
* returns the textual description of what is required from the user side by this UserInput.
*/
public Optional<String> getQuery() {
return Optional.ofNullable(query);
}

/**
* Sets the query.
*/
public void setQuery(String query) {
this.query = query;
}

/**
* returns the UserInput that must be submitted.
* in the response it will always be empty.
Expand All @@ -73,6 +101,13 @@ public Optional<String> getAnswer() {
return Optional.ofNullable(answer);
}

/**
* Sets the answer.
*/
public void setAnswer(String answer) {
this.answer = answer;
}

public enum UserInputID {
otp,
secret_question,
Expand Down