-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from plivo/VT-7575
MaskingSessionAdded
- Loading branch information
Showing
23 changed files
with
1,917 additions
and
6 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Written manually. | ||
|
||
version=5.42.0 | ||
version=5.43.0 | ||
groupId=com.plivo | ||
artifactId=plivo-java | ||
|
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
77 changes: 77 additions & 0 deletions
77
src/main/java/com/plivo/api/models/base/MaskingSessionDeleterClass.java
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.plivo.api.models.base; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.plivo.api.PlivoClient; | ||
import com.plivo.api.exceptions.PlivoValidationException; | ||
import com.plivo.api.exceptions.PlivoRestException; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.plivo.api.models.maskingsession.MaskingSession; | ||
import okhttp3.ResponseBody; | ||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
|
||
public abstract class MaskingSessionDeleterClass<T extends BaseResource> extends BaseRequest<T> { | ||
|
||
protected String id; | ||
protected String secondaryId; | ||
public MaskingSessionDeleterClass(String id) { | ||
this.id = id; | ||
|
||
if (id == null) { | ||
throw new IllegalArgumentException("id cannot be null"); | ||
} | ||
} | ||
|
||
public MaskingSessionDeleterClass(String id, String secondaryId) { | ||
if (id == null || secondaryId == null) { | ||
throw new IllegalArgumentException("id/secondaryId cannot be null"); | ||
} | ||
this.id = id; | ||
this.secondaryId = secondaryId; | ||
} | ||
|
||
/** | ||
* Actually delete the resource. | ||
* | ||
* @return | ||
*/ | ||
public String delete() throws IOException, PlivoRestException, PlivoValidationException { | ||
validate(); | ||
Response<ResponseBody> response = obtainCall().execute(); | ||
|
||
if (response.code() >= 500) { | ||
response = obtainFallback1Call().execute(); | ||
if (response.code() >= 500) { | ||
response = obtainFallback2Call().execute(); | ||
} | ||
} | ||
int responseCode = response.code(); | ||
if (responseCode == 400 || responseCode == 401 || responseCode == 404 || responseCode == 405 || responseCode == 500) { | ||
if (response.errorBody() != null) { | ||
return response.errorBody().string(); | ||
} else { | ||
throw new PlivoRestException("Unexpected error with response code: " + responseCode); | ||
} | ||
} else { | ||
if (response.body() != null) { | ||
return response.body().string(); | ||
} else { | ||
throw new PlivoRestException("Empty response body with response code: " + responseCode); | ||
} | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public MaskingSessionDeleterClass<T> client(final PlivoClient plivoClient) { | ||
this.plivoClient = plivoClient; | ||
return this; | ||
} | ||
|
||
|
||
protected abstract Call<ResponseBody> obtainCall() throws PlivoValidationException; | ||
protected abstract Call<ResponseBody> obtainFallback1Call() throws PlivoValidationException; | ||
protected abstract Call<ResponseBody> obtainFallback2Call() throws PlivoValidationException; | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/plivo/api/models/base/MaskingSessionGetterClass.java
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.plivo.api.models.base; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.plivo.api.PlivoClient; | ||
import com.plivo.api.exceptions.PlivoValidationException; | ||
import com.plivo.api.exceptions.PlivoRestException; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.plivo.api.models.maskingsession.MaskingSession; | ||
import com.plivo.api.util.Utils; | ||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
|
||
/** | ||
* Gets an instance of a resource. | ||
* | ||
* @param <T> The type of the resource. | ||
*/ | ||
public abstract class MaskingSessionGetterClass<T extends BaseResource> extends BaseRequest<T> { | ||
|
||
protected final String id; | ||
public MaskingSessionGetterClass(String id) { | ||
this.id = id; | ||
|
||
if (id == null) { | ||
throw new IllegalArgumentException("id cannot be null"); | ||
} | ||
} | ||
|
||
/** | ||
* Actually get an instance of the resource. | ||
*/ | ||
public String get() throws IOException, PlivoRestException, PlivoValidationException { | ||
validate(); | ||
Response<T> response = obtainCall().execute(); | ||
|
||
if(response.code()>=500){ | ||
response = obtainFallback1Call().execute(); | ||
if(response.code()>=500){ | ||
response = obtainFallback2Call().execute(); | ||
} | ||
} | ||
|
||
handleResponse(response); | ||
T responseBody = response.body(); | ||
MaskingSession maskingSession = (MaskingSession) responseBody; | ||
Map<String, Object> newResponse = new HashMap<>(); | ||
newResponse.put("api_id", maskingSession.getApiId()); | ||
newResponse.put("response", maskingSession.getResponse()); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
return objectMapper.writeValueAsString(newResponse); | ||
} | ||
|
||
@Override | ||
public MaskingSessionGetterClass<T> client(final PlivoClient plivoClient) { | ||
this.plivoClient = plivoClient; | ||
return this; | ||
} | ||
|
||
protected Map<String, Object> toMap() { | ||
client(); | ||
return Utils.objectToMap(PlivoClient.getObjectMapper(), this); | ||
} | ||
|
||
protected abstract Call<T> obtainCall() throws PlivoValidationException; | ||
protected abstract Call<T> obtainFallback1Call() throws PlivoValidationException; | ||
protected abstract Call<T> obtainFallback2Call() throws PlivoValidationException; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.plivo.api.models.base; | ||
|
||
import java.util.List; | ||
|
||
public class Response { | ||
private Meta meta; | ||
private Object objects; | ||
|
||
public Meta getMeta() { | ||
return meta; | ||
} | ||
|
||
public Object getObjects() { | ||
return objects; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/plivo/api/models/maskingsession/MaskingSession.java
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.plivo.api.models.maskingsession; | ||
import com.plivo.api.models.base.BaseResource; | ||
import com.plivo.api.util.Utils; | ||
|
||
public class MaskingSession extends BaseResource { | ||
private String sessionUuid; | ||
private Object response; | ||
public Object getResponse() { | ||
return response; | ||
} | ||
public static MaskingSessionCreator creator(String firstParty, String secondParty) { | ||
if (!Utils.allNotNull(firstParty, secondParty)) { | ||
throw new IllegalArgumentException("firstParty and secondParty cannot be null"); | ||
} | ||
|
||
return new MaskingSessionCreator(firstParty, secondParty); | ||
} | ||
|
||
public static MaskingSessionLister lister() { | ||
return new MaskingSessionLister(); | ||
} | ||
|
||
public static MaskingSessionGetter getter(String sessionUuid) { | ||
return new MaskingSessionGetter(sessionUuid); | ||
} | ||
|
||
public static MaskingSessionUpdater updater(String sessionUuid) { | ||
return new MaskingSessionUpdater(sessionUuid); | ||
} | ||
|
||
public static MaskingSessionDeleter deleter(String sessionUuid) { | ||
return new MaskingSessionDeleter(sessionUuid); | ||
} | ||
|
||
public String getMaskingSessionId() { | ||
return sessionUuid; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return getMaskingSessionId(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/plivo/api/models/maskingsession/MaskingSessionCreateResponse.java
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.plivo.api.models.maskingsession; | ||
|
||
import com.plivo.api.models.base.BaseResponse; | ||
|
||
public class MaskingSessionCreateResponse extends BaseResponse { | ||
private String sessionUuid; | ||
private String virtualNumber; | ||
private Object session; | ||
|
||
public String getSessionUuid() { | ||
return sessionUuid; | ||
} | ||
public String getVirtualNumber() { | ||
return virtualNumber; | ||
} | ||
public Object getSession() { | ||
return session; | ||
} | ||
} |
Oops, something went wrong.