From 48b392142ef9b57c44aa4e7b92870bfa9b7228b3 Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 27 Jul 2022 10:36:31 +0530 Subject: [PATCH 01/12] Added token Creation --- .../com/plivo/api/models/token/Token.java | 27 +++++++++++ .../api/models/token/TokenCreateResponse.java | 10 ++++ .../plivo/api/models/token/TokenCreator.java | 48 +++++++++++++++++++ src/test/java/com/plivo/api/TokenTest.java | 0 .../com/plivo/api/tokenCreateResponse.json | 0 5 files changed, 85 insertions(+) create mode 100644 src/main/java/com/plivo/api/models/token/Token.java create mode 100644 src/main/java/com/plivo/api/models/token/TokenCreateResponse.java create mode 100644 src/main/java/com/plivo/api/models/token/TokenCreator.java create mode 100644 src/test/java/com/plivo/api/TokenTest.java create mode 100644 src/test/resources/com/plivo/api/tokenCreateResponse.json diff --git a/src/main/java/com/plivo/api/models/token/Token.java b/src/main/java/com/plivo/api/models/token/Token.java new file mode 100644 index 00000000..81ce6793 --- /dev/null +++ b/src/main/java/com/plivo/api/models/token/Token.java @@ -0,0 +1,27 @@ +package com.plivo.api.models.token; + +import com.plivo.api.models.base.BaseResource; +import com.plivo.api.models.call.CallCreator; + +import java.util.List; + +public class Token extends BaseResource { + + private String iss; + + private String sub; + + private Integer nbf; + + private Integer exp; + + private Boolean incoming_allow; + + private Boolean outgoing_allow; + + private String app; + + public static TokenCreator creator(String iss, String sub, Integer nbf, Integer exp, Boolean incoming_allow, Boolean outgoing_allow, String app) { + return new TokenCreator(iss, sub, nbf, exp, incoming_allow, outgoing_allow, app); + } +} \ No newline at end of file diff --git a/src/main/java/com/plivo/api/models/token/TokenCreateResponse.java b/src/main/java/com/plivo/api/models/token/TokenCreateResponse.java new file mode 100644 index 00000000..972e9d08 --- /dev/null +++ b/src/main/java/com/plivo/api/models/token/TokenCreateResponse.java @@ -0,0 +1,10 @@ +package com.plivo.api.models.token; + +import com.plivo.api.models.base.BaseResponse; +import java.util.List; + +public class TokenCreateResponse extends BaseResponse { + + + +} diff --git a/src/main/java/com/plivo/api/models/token/TokenCreator.java b/src/main/java/com/plivo/api/models/token/TokenCreator.java new file mode 100644 index 00000000..a7c83c95 --- /dev/null +++ b/src/main/java/com/plivo/api/models/token/TokenCreator.java @@ -0,0 +1,48 @@ +package com.plivo.api.models.token; + +import com.plivo.api.models.base.Creator; +import com.plivo.api.util.Utils; +import retrofit2.Call; + +public class TokenCreator extends Creator { + private String iss; + private String sub; + private Integer nbf; + private Integer exp; + private Boolean incoming_allow; + private Boolean outgoing_allow; + private String app; + + TokenCreator(String iss, String sub, Integer nbf, Integer exp, Boolean incoming_allow, Boolean outgoing_allow, String app) { + this.iss = iss; + this.sub = sub; + this.nbf = nbf; + this.exp = exp; + this.incoming_allow = incoming_allow; + this.outgoing_allow = outgoing_allow; + this.app = app; + } + + public String iss() { + return iss; + } + public String sub() { + return sub; + } + public Integer nbf() { + return nbf; + } + public Integer exp() { + return exp; + } + public Boolean incoming_allow() { + return incoming_allow; + } + public Boolean outgoing_allow() { + return outgoing_allow; + } + public String app() { + return app; + } + +} \ No newline at end of file diff --git a/src/test/java/com/plivo/api/TokenTest.java b/src/test/java/com/plivo/api/TokenTest.java new file mode 100644 index 00000000..e69de29b diff --git a/src/test/resources/com/plivo/api/tokenCreateResponse.json b/src/test/resources/com/plivo/api/tokenCreateResponse.json new file mode 100644 index 00000000..e69de29b From e11e7c4457e868b7ce7c758ea352f7998cfd7a7f Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 09:38:38 +0530 Subject: [PATCH 02/12] added API to create a new JWT token. --- CHANGELOG.md | 5 + pom.xml | 13 +- .../java/com/plivo/api/PlivoAPIService.java | 5 + .../com/plivo/api/models/token/Token.java | 45 +++++- .../api/models/token/TokenCreateResponse.java | 10 +- .../plivo/api/models/token/TokenCreator.java | 129 ++++++++++++------ src/main/resources/com/plivo/api/version.txt | 2 +- 7 files changed, 158 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f81915b3..24d21223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [5.12.0](https://github.com/plivo/plivo-java/tree/v5.12.0) (2022-08-08) +**Feature - Token Creation** +- `JWT Token Creation API` added API to create a new JWT token. + + ## [5.11.0](https://github.com/plivo/plivo-java/tree/v5.11.0) (2022-05-05) **Feature - List all recordings** - `fromNumber` and `toNumber` added to filtering param [List all recordings](https://www.plivo.com/docs/voice/api/recording#list-all-recordings) diff --git a/pom.xml b/pom.xml index c7798573..4b38ca9e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.plivo plivo-java - 5.11.0 + 5.12.0 plivo-java A Java SDK to make voice calls & send SMS using Plivo and to generate Plivo XML @@ -27,6 +27,10 @@ scm:git:git@github.com:plivo/plivo-java.git git@github.com:plivo/plivo-java.git + + 1.8 + 1.8 + com.squareup.retrofit2 @@ -40,6 +44,11 @@ 2.2.0 compile + + com.googlecode.json-simple + json-simple + 1.1.1 + com.squareup.okhttp3 logging-interceptor @@ -76,5 +85,7 @@ 2.7.5 test + + \ No newline at end of file diff --git a/src/main/java/com/plivo/api/PlivoAPIService.java b/src/main/java/com/plivo/api/PlivoAPIService.java index 4662498e..143c9c61 100644 --- a/src/main/java/com/plivo/api/PlivoAPIService.java +++ b/src/main/java/com/plivo/api/PlivoAPIService.java @@ -34,6 +34,8 @@ import com.plivo.api.models.recording.Recording; import com.plivo.api.models.brand.*; import com.plivo.api.models.campaign.*; +import com.plivo.api.models.token.TokenCreateResponse; +import com.plivo.api.models.token.TokenCreator; import okhttp3.RequestBody; import okhttp3.ResponseBody; import retrofit2.Call; @@ -280,6 +282,9 @@ Call recordingDelete(@Path("authId") String authId, Call endpointCreate(@Path("authId") String authId, @Body EndpointCreator endpointCreator); + @POST("Account/{authId}/JWT/Token/") + Call tokenCreate(@Path("authId") String authId, + @Body TokenCreator tokenCreator); @GET("Account/{authId}/Endpoint/") Call> endpointList(@Path("authId") String authId, @QueryMap Map params); diff --git a/src/main/java/com/plivo/api/models/token/Token.java b/src/main/java/com/plivo/api/models/token/Token.java index 81ce6793..e81e32f7 100644 --- a/src/main/java/com/plivo/api/models/token/Token.java +++ b/src/main/java/com/plivo/api/models/token/Token.java @@ -1,9 +1,9 @@ package com.plivo.api.models.token; import com.plivo.api.models.base.BaseResource; -import com.plivo.api.models.call.CallCreator; - -import java.util.List; +import com.plivo.api.util.Utils; +import org.json.simple.JSONObject; +import retrofit2.Call; public class Token extends BaseResource { @@ -20,8 +20,43 @@ public class Token extends BaseResource { private Boolean outgoing_allow; private String app; + private JSONObject per; + + public static TokenCreator creator(String iss) { + if(!Utils.allNotNull(iss)){ + throw new IllegalArgumentException("iss cannot be null"); + } + + return new TokenCreator(iss); + } + + public String getIss() { + return iss; + } + + public String getSub() { + return sub; + } + public Integer getNbf() { + return nbf; + } + public Integer getExp() { + return exp; + } + public Boolean getIncoming_allow() { + return incoming_allow; + } + public Boolean getOutgoing_allow() { + return outgoing_allow; + } + public String getApp() { + return app; + } + public JSONObject getPer() { + return per; + } - public static TokenCreator creator(String iss, String sub, Integer nbf, Integer exp, Boolean incoming_allow, Boolean outgoing_allow, String app) { - return new TokenCreator(iss, sub, nbf, exp, incoming_allow, outgoing_allow, app); + public String getId() { + return null; } } \ No newline at end of file diff --git a/src/main/java/com/plivo/api/models/token/TokenCreateResponse.java b/src/main/java/com/plivo/api/models/token/TokenCreateResponse.java index 972e9d08..36092d6f 100644 --- a/src/main/java/com/plivo/api/models/token/TokenCreateResponse.java +++ b/src/main/java/com/plivo/api/models/token/TokenCreateResponse.java @@ -1,10 +1,16 @@ package com.plivo.api.models.token; import com.plivo.api.models.base.BaseResponse; -import java.util.List; public class TokenCreateResponse extends BaseResponse { + private String api_id; + private String token; + public String getApi_id() { + return api_id; + } - + public String getToken() { + return token; + } } diff --git a/src/main/java/com/plivo/api/models/token/TokenCreator.java b/src/main/java/com/plivo/api/models/token/TokenCreator.java index a7c83c95..96c9d2c0 100644 --- a/src/main/java/com/plivo/api/models/token/TokenCreator.java +++ b/src/main/java/com/plivo/api/models/token/TokenCreator.java @@ -1,48 +1,93 @@ package com.plivo.api.models.token; -import com.plivo.api.models.base.Creator; -import com.plivo.api.util.Utils; +import com.plivo.api.models.base.VoiceCreator; import retrofit2.Call; +import org.json.simple.* ; + + +public class TokenCreator extends VoiceCreator { + + private final String iss; + private String sub; + private Integer nbf; + private Integer exp; + private String app; + private Boolean incoming_allow; + private Boolean outgoing_allow; + private JSONObject per; + + + + + public TokenCreator(String iss) { + this.iss = iss; + } + public String sub() { + return this.sub; + } + public TokenCreator sub(final String sub) { + this.sub = sub; + return this; + } + public Integer nbf() { + return this.nbf; + } + public TokenCreator nbf(final Integer nbf) { + this.nbf = nbf; + return this; + } + public Integer exp() { + return this.exp; + } + public TokenCreator exp(final Integer exp) { + this.exp = exp; + return this; + } + public String app() { + return this.app; + } + public TokenCreator app(final String app) { + this.app = app; + return this; + } + public boolean incoming_allow() { + return this.incoming_allow; + } + public TokenCreator incoming_allow(final boolean incoming_allow) { + this.incoming_allow = incoming_allow; + return this; + } + public boolean outgoing_allow() { + return this.outgoing_allow; + } + public TokenCreator outgoing_allow(final boolean outgoing_allow) { + this.outgoing_allow = outgoing_allow; + return this; + } + public JSONObject per() { + return this.per; + } + public TokenCreator per(final JSONObject per) { + JSONObject permission = new JSONObject(); + JSONObject voice = new JSONObject(); + voice.put("outgoing_allow", outgoing_allow); + permission.put("voice", voice); + this.per = permission; + return this; + } + + @Override + protected Call obtainCall() { + return client().getVoiceApiService().tokenCreate(client().getAuthId(),this); + } + @Override + protected Call obtainFallback1Call() { + return client().getVoiceFallback1Service().tokenCreate(client().getAuthId(),this); + } + @Override + protected Call obtainFallback2Call() { + return client().getVoiceFallback2Service().tokenCreate(client().getAuthId(),this); + } -public class TokenCreator extends Creator { - private String iss; - private String sub; - private Integer nbf; - private Integer exp; - private Boolean incoming_allow; - private Boolean outgoing_allow; - private String app; - - TokenCreator(String iss, String sub, Integer nbf, Integer exp, Boolean incoming_allow, Boolean outgoing_allow, String app) { - this.iss = iss; - this.sub = sub; - this.nbf = nbf; - this.exp = exp; - this.incoming_allow = incoming_allow; - this.outgoing_allow = outgoing_allow; - this.app = app; - } - - public String iss() { - return iss; - } - public String sub() { - return sub; - } - public Integer nbf() { - return nbf; - } - public Integer exp() { - return exp; - } - public Boolean incoming_allow() { - return incoming_allow; - } - public Boolean outgoing_allow() { - return outgoing_allow; - } - public String app() { - return app; - } } \ No newline at end of file diff --git a/src/main/resources/com/plivo/api/version.txt b/src/main/resources/com/plivo/api/version.txt index c68d476c..dd0ad7ae 100644 --- a/src/main/resources/com/plivo/api/version.txt +++ b/src/main/resources/com/plivo/api/version.txt @@ -1 +1 @@ -5.11.0 +5.12.0 From c0727fb3ae2d62b780d21ae966a78a2121550995 Mon Sep 17 00:00:00 2001 From: Kowshik siva sai Motepalli <59483656+kowshiksiva5@users.noreply.github.com> Date: Wed, 10 Aug 2022 09:40:20 +0530 Subject: [PATCH 03/12] changed version in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ba1a697..074f7060 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ If you are using Maven, use the following XML to include the Plivo SDK as a depe com.plivo plivo-java - 5.11.0 + 5.12.0 ``` From 9a6e3b1823d6d35e43fa1ee1826c66fb61396d6d Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 14:29:54 +0530 Subject: [PATCH 04/12] Changed pom file --- pom.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 4b38ca9e..e68a82b1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.plivo plivo-java - 5.12.0 + snapshot-6.0 plivo-java A Java SDK to make voice calls & send SMS using Plivo and to generate Plivo XML @@ -27,10 +27,6 @@ scm:git:git@github.com:plivo/plivo-java.git git@github.com:plivo/plivo-java.git - - 1.8 - 1.8 - com.squareup.retrofit2 From 6d85f5edd8dc92d7a54da5a584b109848ed1a1ce Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 15:13:29 +0530 Subject: [PATCH 05/12] Change in buildgradle --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index eccce3af..1cbd20da 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,7 @@ buildscript { dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.0' } + } buildscript { @@ -23,7 +24,7 @@ buildscript { classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.12.0" } } - +implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' apply plugin: 'checkstyle' From 08faf9f79c97623e05c88878a90342d2aba5bef0 Mon Sep 17 00:00:00 2001 From: kowshik-plivo <107911744+kowshik-plivo@users.noreply.github.com> Date: Wed, 10 Aug 2022 15:57:27 +0530 Subject: [PATCH 06/12] Update pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e68a82b1..70771ce5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.plivo plivo-java - snapshot-6.0 + 5.12.0 plivo-java A Java SDK to make voice calls & send SMS using Plivo and to generate Plivo XML @@ -84,4 +84,4 @@ - \ No newline at end of file + From 33573c3ee1b8eb9a1ef8da47dafb0a3e604f0c76 Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 17:20:15 +0530 Subject: [PATCH 07/12] Testing Build --- pom.xml | 2 +- .../com/plivo/api/models/token/Token.java | 10 +++---- .../plivo/api/models/token/TokenCreator.java | 26 ++++++++-------- src/test/java/com/plivo/api/TokenTest.java | 30 +++++++++++++++++++ .../com/plivo/api/tokenCreateResponse.json | 4 +++ 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index e68a82b1..a0881e2d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.plivo plivo-java - snapshot-6.0 + 5.12.0 plivo-java A Java SDK to make voice calls & send SMS using Plivo and to generate Plivo XML diff --git a/src/main/java/com/plivo/api/models/token/Token.java b/src/main/java/com/plivo/api/models/token/Token.java index e81e32f7..15511dc1 100644 --- a/src/main/java/com/plivo/api/models/token/Token.java +++ b/src/main/java/com/plivo/api/models/token/Token.java @@ -2,7 +2,7 @@ import com.plivo.api.models.base.BaseResource; import com.plivo.api.util.Utils; -import org.json.simple.JSONObject; +//import org.json.simple.JSONObject; import retrofit2.Call; public class Token extends BaseResource { @@ -20,7 +20,7 @@ public class Token extends BaseResource { private Boolean outgoing_allow; private String app; - private JSONObject per; +// private JSONObject per; public static TokenCreator creator(String iss) { if(!Utils.allNotNull(iss)){ @@ -52,9 +52,9 @@ public Boolean getOutgoing_allow() { public String getApp() { return app; } - public JSONObject getPer() { - return per; - } +// public JSONObject getPer() { +// return per; +// } public String getId() { return null; diff --git a/src/main/java/com/plivo/api/models/token/TokenCreator.java b/src/main/java/com/plivo/api/models/token/TokenCreator.java index 96c9d2c0..93308acd 100644 --- a/src/main/java/com/plivo/api/models/token/TokenCreator.java +++ b/src/main/java/com/plivo/api/models/token/TokenCreator.java @@ -2,7 +2,7 @@ import com.plivo.api.models.base.VoiceCreator; import retrofit2.Call; -import org.json.simple.* ; +//import org.json.simple.* ; public class TokenCreator extends VoiceCreator { @@ -14,7 +14,7 @@ public class TokenCreator extends VoiceCreator { private String app; private Boolean incoming_allow; private Boolean outgoing_allow; - private JSONObject per; +// private JSONObject per; @@ -64,17 +64,17 @@ public TokenCreator outgoing_allow(final boolean outgoing_allow) { this.outgoing_allow = outgoing_allow; return this; } - public JSONObject per() { - return this.per; - } - public TokenCreator per(final JSONObject per) { - JSONObject permission = new JSONObject(); - JSONObject voice = new JSONObject(); - voice.put("outgoing_allow", outgoing_allow); - permission.put("voice", voice); - this.per = permission; - return this; - } +// public JSONObject per() { +// return this.per; +// } +// public TokenCreator per(final JSONObject per) { +// JSONObject permission = new JSONObject(); +// JSONObject voice = new JSONObject(); +// voice.put("outgoing_allow", outgoing_allow); +// permission.put("voice", voice); +// this.per = permission; +// return this; +// } @Override protected Call obtainCall() { diff --git a/src/test/java/com/plivo/api/TokenTest.java b/src/test/java/com/plivo/api/TokenTest.java index e69de29b..62a015c8 100644 --- a/src/test/java/com/plivo/api/TokenTest.java +++ b/src/test/java/com/plivo/api/TokenTest.java @@ -0,0 +1,30 @@ +package com.plivo.api; + +import static junit.framework.TestCase.assertEquals; + +import com.plivo.api.models.endpoint.Endpoint; +import com.plivo.api.models.token.Token; +import org.junit.Before; +import org.junit.Test; + +public class TokenTest extends BaseTest { + + private PlivoClient client; + + @Before + public void setUp() throws Exception { + super.setUp(); + client = new PlivoClient("MA123456789012345678", + "Zmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + } + + @Test + public void tokenCreateShouldWork() throws Exception { + expectResponse("TokenCreateResponse.json", 201); + + Token.creator("MA123456789012345678") + .create(); + + assertRequest("POST", "JWT/Token/"); + } +} \ No newline at end of file diff --git a/src/test/resources/com/plivo/api/tokenCreateResponse.json b/src/test/resources/com/plivo/api/tokenCreateResponse.json index e69de29b..7d2415cf 100644 --- a/src/test/resources/com/plivo/api/tokenCreateResponse.json +++ b/src/test/resources/com/plivo/api/tokenCreateResponse.json @@ -0,0 +1,4 @@ +{ + "api_id": "a9acb782-11e9-11ed-96c8-0242ac110002", + "token":"eyJhbGciOiJIUzI1NiIsImN0eSI6InBsaXZvO3Y9MSIsInR5cCI6IkpXVCJ9.eyJhcHAiOiIiLCJleHAiOjE2NTk0Nzk0NzksImlzcyI6Ik1BTURWTFpKWTJaR1k1TVdVMVpKIiwibmJmIjoxNjU5MzkzMDc5LCJwZXIiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOmZhbHNlLCJvdXRnb2luZ19hbGxvdyI6ZmFsc2V9fSwic3ViIjoia293c2hpayJ9.dzmLy1JZb6Z9i7MzomCCh3cxaqyA_78O87E8ASkjk6M" +} \ No newline at end of file From 57d59d215a4605e94137eaf175beaba33a46e0eb Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 17:27:33 +0530 Subject: [PATCH 08/12] Testing Build --- src/test/java/com/plivo/api/TokenTest.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/java/com/plivo/api/TokenTest.java b/src/test/java/com/plivo/api/TokenTest.java index 62a015c8..ed59ac61 100644 --- a/src/test/java/com/plivo/api/TokenTest.java +++ b/src/test/java/com/plivo/api/TokenTest.java @@ -27,4 +27,28 @@ public void tokenCreateShouldWork() throws Exception { assertRequest("POST", "JWT/Token/"); } + + @Test + public void tokenCreateWithClientShouldWork() throws Exception { + expectResponse("tokenCreateResponse.json", 201); + + Token.creator("username") + .client(client) + .create(); + + assertRequest("POST", "JWT/Token/"); + } + + @Test(expected = IllegalArgumentException.class) + public void tokenCreateShouldFailWithoutAllParams() throws Exception { + Token.creator(null) + .create(); + } + + @Test(expected = IllegalArgumentException.class) + public void tokenCreateWithClientShouldFailWithoutAllParams() throws Exception { + Token.creator(null) + .client(client) + .create(); + } } \ No newline at end of file From 3393fff5b376032584f5ac3dce19c9c9f9d01c5b Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 18:19:13 +0530 Subject: [PATCH 09/12] Added Testing --- .../com/plivo/api/models/token/Token.java | 10 +++---- .../plivo/api/models/token/TokenCreator.java | 26 +++++++++---------- src/test/java/com/plivo/api/TokenTest.java | 12 ++++----- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/plivo/api/models/token/Token.java b/src/main/java/com/plivo/api/models/token/Token.java index 15511dc1..e81e32f7 100644 --- a/src/main/java/com/plivo/api/models/token/Token.java +++ b/src/main/java/com/plivo/api/models/token/Token.java @@ -2,7 +2,7 @@ import com.plivo.api.models.base.BaseResource; import com.plivo.api.util.Utils; -//import org.json.simple.JSONObject; +import org.json.simple.JSONObject; import retrofit2.Call; public class Token extends BaseResource { @@ -20,7 +20,7 @@ public class Token extends BaseResource { private Boolean outgoing_allow; private String app; -// private JSONObject per; + private JSONObject per; public static TokenCreator creator(String iss) { if(!Utils.allNotNull(iss)){ @@ -52,9 +52,9 @@ public Boolean getOutgoing_allow() { public String getApp() { return app; } -// public JSONObject getPer() { -// return per; -// } + public JSONObject getPer() { + return per; + } public String getId() { return null; diff --git a/src/main/java/com/plivo/api/models/token/TokenCreator.java b/src/main/java/com/plivo/api/models/token/TokenCreator.java index 93308acd..96c9d2c0 100644 --- a/src/main/java/com/plivo/api/models/token/TokenCreator.java +++ b/src/main/java/com/plivo/api/models/token/TokenCreator.java @@ -2,7 +2,7 @@ import com.plivo.api.models.base.VoiceCreator; import retrofit2.Call; -//import org.json.simple.* ; +import org.json.simple.* ; public class TokenCreator extends VoiceCreator { @@ -14,7 +14,7 @@ public class TokenCreator extends VoiceCreator { private String app; private Boolean incoming_allow; private Boolean outgoing_allow; -// private JSONObject per; + private JSONObject per; @@ -64,17 +64,17 @@ public TokenCreator outgoing_allow(final boolean outgoing_allow) { this.outgoing_allow = outgoing_allow; return this; } -// public JSONObject per() { -// return this.per; -// } -// public TokenCreator per(final JSONObject per) { -// JSONObject permission = new JSONObject(); -// JSONObject voice = new JSONObject(); -// voice.put("outgoing_allow", outgoing_allow); -// permission.put("voice", voice); -// this.per = permission; -// return this; -// } + public JSONObject per() { + return this.per; + } + public TokenCreator per(final JSONObject per) { + JSONObject permission = new JSONObject(); + JSONObject voice = new JSONObject(); + voice.put("outgoing_allow", outgoing_allow); + permission.put("voice", voice); + this.per = permission; + return this; + } @Override protected Call obtainCall() { diff --git a/src/test/java/com/plivo/api/TokenTest.java b/src/test/java/com/plivo/api/TokenTest.java index ed59ac61..5dbdcf43 100644 --- a/src/test/java/com/plivo/api/TokenTest.java +++ b/src/test/java/com/plivo/api/TokenTest.java @@ -2,7 +2,7 @@ import static junit.framework.TestCase.assertEquals; -import com.plivo.api.models.endpoint.Endpoint; +import com.plivo.api.models.token.Token; import com.plivo.api.models.token.Token; import org.junit.Before; import org.junit.Test; @@ -15,14 +15,14 @@ public class TokenTest extends BaseTest { public void setUp() throws Exception { super.setUp(); client = new PlivoClient("MA123456789012345678", - "Zmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + "ZTJiODc5MTM1ODA3MzMyYmY4NTAwYzA3Mjc2OWNh"); } @Test public void tokenCreateShouldWork() throws Exception { - expectResponse("TokenCreateResponse.json", 201); + expectResponse("TokenCreateResponse.json", 200); - Token.creator("MA123456789012345678") + Token.creator("MAMDVLZJY2ZGY5MWU1ZJ") .create(); assertRequest("POST", "JWT/Token/"); @@ -30,9 +30,9 @@ public void tokenCreateShouldWork() throws Exception { @Test public void tokenCreateWithClientShouldWork() throws Exception { - expectResponse("tokenCreateResponse.json", 201); + expectResponse("tokenCreateResponse.json", 200); - Token.creator("username") + Token.creator("MAMDVLZJY2ZGY5MWU1ZJ") .client(client) .create(); From 2425f78d823b8c39dc5a16190bd13b30734c0baf Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 19:29:09 +0530 Subject: [PATCH 10/12] Added changes for the Testing of token creation --- src/test/java/com/plivo/api/TokenTest.java | 28 ++++------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/plivo/api/TokenTest.java b/src/test/java/com/plivo/api/TokenTest.java index 5dbdcf43..c917b976 100644 --- a/src/test/java/com/plivo/api/TokenTest.java +++ b/src/test/java/com/plivo/api/TokenTest.java @@ -1,8 +1,5 @@ package com.plivo.api; -import static junit.framework.TestCase.assertEquals; - -import com.plivo.api.models.token.Token; import com.plivo.api.models.token.Token; import org.junit.Before; import org.junit.Test; @@ -15,24 +12,14 @@ public class TokenTest extends BaseTest { public void setUp() throws Exception { super.setUp(); client = new PlivoClient("MA123456789012345678", - "ZTJiODc5MTM1ODA3MzMyYmY4NTAwYzA3Mjc2OWNh"); - } - - @Test - public void tokenCreateShouldWork() throws Exception { - expectResponse("TokenCreateResponse.json", 200); - - Token.creator("MAMDVLZJY2ZGY5MWU1ZJ") - .create(); - - assertRequest("POST", "JWT/Token/"); + "Zmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); } @Test public void tokenCreateWithClientShouldWork() throws Exception { - expectResponse("tokenCreateResponse.json", 200); + expectResponse("tokenCreateResponse.json", 201); - Token.creator("MAMDVLZJY2ZGY5MWU1ZJ") + Token.creator("MA123456789012345678") .client(client) .create(); @@ -44,11 +31,4 @@ public void tokenCreateShouldFailWithoutAllParams() throws Exception { Token.creator(null) .create(); } - - @Test(expected = IllegalArgumentException.class) - public void tokenCreateWithClientShouldFailWithoutAllParams() throws Exception { - Token.creator(null) - .client(client) - .create(); - } -} \ No newline at end of file +} From e6f485a5c3a6cc7a9071972ce1b00d5714faf74f Mon Sep 17 00:00:00 2001 From: kowshik-plivo Date: Wed, 10 Aug 2022 19:29:24 +0530 Subject: [PATCH 11/12] Added changes for the Testing of token creation --- pom.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.properties b/pom.properties index 74c96996..6f6c38c7 100644 --- a/pom.properties +++ b/pom.properties @@ -1,5 +1,5 @@ # Written manually. -version=5.11.0 +version=5.12.0 groupId=com.plivo artifactId=plivo-java From f3fab25b2970c4f4370ba58d0b174a682d7835a8 Mon Sep 17 00:00:00 2001 From: Prashant Pandey Date: Thu, 11 Aug 2022 01:04:10 +0530 Subject: [PATCH 12/12] build fix --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1cbd20da..95cb5503 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,6 @@ buildscript { classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.12.0" } } -implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' apply plugin: 'checkstyle' @@ -54,6 +53,7 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'com.squareup.okhttp', name: 'mockwebserver', version: '2.7.5' + compile 'com.googlecode.json-simple:json-simple:1.1.1' compile 'com.squareup.retrofit2:converter-jackson:2.2.0' compile 'com.squareup.retrofit2:retrofit:2.2.0' compile 'com.squareup.okhttp3:logging-interceptor:3.7.0'