Skip to content

Commit

Permalink
Merge pull request #275 from plivo/VT-7575
Browse files Browse the repository at this point in the history
MaskingSessionAdded
  • Loading branch information
manjunath-plivo authored May 31, 2024
2 parents 9c4c75c + aef936a commit 3dbd022
Show file tree
Hide file tree
Showing 23 changed files with 1,917 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [5.43.0](https://github.com/plivo/plivo-java/tree/v5.43.0) (2024-05-31)
**Feature - Number Masking Feature Added**
- Number Masking APIs added to create, update, delete and list sessions

## [5.42.0](https://github.com/plivo/plivo-java/tree/v5.42.0) (2024-05-20)
**Feature - Adding support for location whatsapp messages**
- Added new param `location` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support location `whatsapp` messages
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Plivo Java SDK makes it simpler to integrate communications into your Java a

### To Install Stable release

You can use this SDK by adding it as a dependency in your dependency management tool. Alternatively, you can use the [JAR file](https://search.maven.org/remotecontent?filepath=com/plivo/plivo-java/5.42.0/plivo-java-5.42.0.jar).
You can use this SDK by adding it as a dependency in your dependency management tool. Alternatively, you can use the [JAR file](https://search.maven.org/remotecontent?filepath=com/plivo/plivo-java/5.43.0/plivo-java-5.43.0.jar).


If you are using Maven, use the following XML to include the Plivo SDK as a dependency.
Expand All @@ -19,13 +19,13 @@ If you are using Maven, use the following XML to include the Plivo SDK as a depe
<dependency>
<groupId>com.plivo</groupId>
<artifactId>plivo-java</artifactId>
<version>5.42.0</version>
<version>5.43.0</version>
</dependency>
```

If you are using Gradle, use the following line in your dependencies.
```
compile 'com.plivo:plivo-java:5.42.0'
compile 'com.plivo:plivo-java:5.43.0'
```

### To Install Beta release
Expand Down
2 changes: 1 addition & 1 deletion pom.properties
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

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.plivo</groupId>
<artifactId>plivo-java</artifactId>
<version>5.42.0</version>
<version>5.43.0</version>
<name>plivo-java</name>
<description>A Java SDK to make voice calls &amp; send SMS using Plivo and to generate Plivo XML</description>
<licenses>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/plivo/api/PlivoAPIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.plivo.api.models.endpoint.*;
import com.plivo.api.models.enduser.*;
import com.plivo.api.models.identity.*;
import com.plivo.api.models.maskingsession.*;
import com.plivo.api.models.media.Media;
import com.plivo.api.models.media.MediaResponse;
import com.plivo.api.models.message.Message;
Expand Down Expand Up @@ -350,6 +351,27 @@ Call<EndpointCreateResponse> endpointCreate(@Path("authId") String authId,
@POST("Account/{authId}/JWT/Token/")
Call<TokenCreateResponse> tokenCreate(@Path("authId") String authId,
@Body TokenCreator tokenCreator);

@GET("Account/{authId}/Masking/Session/")
Call<ListResponse<MaskingSession>> maskingSessionList(@Path("authId") String authId,
@QueryMap Map<String, Object> params);

@GET("Account/{authId}/Masking/Session/{sessionUuid}/")
Call<MaskingSession> maskingSessionGet(@Path("authId") String authId, @Path("sessionUuid") String sessionUuid);

@DELETE("Account/{authId}/Masking/Session/{sessionUuid}/")
Call<ResponseBody> maskingSessionDelete(@Path("authId") String authId,
@Path("sessionUuid") String sessionUuid);

@POST("Account/{authId}/Masking/Session/{sessionUuid}/")
Call<MaskingSessionUpdateResponse> maskingSessionUpdate(@Path("authId") String authId,
@Path("sessionUuid") String sessionUuid, @Body
MaskingSessionUpdater maskingSessionUpdater);

@POST("Account/{authId}/Masking/Session/")
Call<MaskingSessionCreateResponse> maskingSessionCreate(@Path("authId") String authId,
@Body MaskingSessionCreator maskingSessionCreator);

@GET("Account/{authId}/Endpoint/")
Call<ListResponse<Endpoint>> endpointList(@Path("authId") String authId,
@QueryMap Map<String, Object> params);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/plivo/api/models/base/ListResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ListResponse<T> extends BaseResponse {
private List<T> profiles;
private List<T> campaigns;
private List<T> sessions;
private Response response;

/**
* @return The pagination-related metadata for this list response.
Expand Down Expand Up @@ -46,4 +47,7 @@ public List<T> getCampaigns() {
public List<T> getSessions() {
return sessions;
}
public Response getResponse() {
return response;
}
}
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;
}
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;
}
17 changes: 17 additions & 0 deletions src/main/java/com/plivo/api/models/base/Response.java
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;
}

}
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();
}
}
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;
}
}
Loading

0 comments on commit 3dbd022

Please sign in to comment.