Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test pr #214

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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.11.0</version>
<version>5.12.0</version>
</dependency>
```

Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.0'
}

}

buildscript {
Expand All @@ -23,7 +24,6 @@ buildscript {
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.12.0"
}
}

apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'checkstyle'
Expand Down Expand Up @@ -53,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'
Expand Down
2 changes: 1 addition & 1 deletion pom.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Written manually.

version=5.11.0
version=5.12.0
groupId=com.plivo
artifactId=plivo-java
11 changes: 9 additions & 2 deletions 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.11.0</version>
<version>5.12.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 Expand Up @@ -40,6 +40,11 @@
<version>2.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
Expand Down Expand Up @@ -76,5 +81,7 @@
<version>2.7.5</version>
<scope>test</scope>
</dependency>

</dependencies>
</project>

</project>
5 changes: 5 additions & 0 deletions src/main/java/com/plivo/api/PlivoAPIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -280,6 +282,9 @@ Call<ResponseBody> recordingDelete(@Path("authId") String authId,
Call<EndpointCreateResponse> endpointCreate(@Path("authId") String authId,
@Body EndpointCreator endpointCreator);

@POST("Account/{authId}/JWT/Token/")
Call<TokenCreateResponse> tokenCreate(@Path("authId") String authId,
@Body TokenCreator tokenCreator);
@GET("Account/{authId}/Endpoint/")
Call<ListResponse<Endpoint>> endpointList(@Path("authId") String authId,
@QueryMap Map<String, Object> params);
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/com/plivo/api/models/token/Token.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.plivo.api.models.token;

import com.plivo.api.models.base.BaseResource;
import com.plivo.api.util.Utils;
import org.json.simple.JSONObject;
import retrofit2.Call;

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;
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 String getId() {
return null;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/plivo/api/models/token/TokenCreateResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.plivo.api.models.token;

import com.plivo.api.models.base.BaseResponse;

public class TokenCreateResponse extends BaseResponse {
private String api_id;
private String token;
public String getApi_id() {
return api_id;
}

public String getToken() {
return token;
}

}
93 changes: 93 additions & 0 deletions src/main/java/com/plivo/api/models/token/TokenCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.plivo.api.models.token;

import com.plivo.api.models.base.VoiceCreator;
import retrofit2.Call;
import org.json.simple.* ;


public class TokenCreator extends VoiceCreator<TokenCreateResponse> {

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<TokenCreateResponse> obtainCall() {
return client().getVoiceApiService().tokenCreate(client().getAuthId(),this);
}
@Override
protected Call<TokenCreateResponse> obtainFallback1Call() {
return client().getVoiceFallback1Service().tokenCreate(client().getAuthId(),this);
}
@Override
protected Call<TokenCreateResponse> obtainFallback2Call() {
return client().getVoiceFallback2Service().tokenCreate(client().getAuthId(),this);
}


}
2 changes: 1 addition & 1 deletion src/main/resources/com/plivo/api/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.11.0
5.12.0
34 changes: 34 additions & 0 deletions src/test/java/com/plivo/api/TokenTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.plivo.api;

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 tokenCreateWithClientShouldWork() throws Exception {
expectResponse("tokenCreateResponse.json", 201);

Token.creator("MA123456789012345678")
.client(client)
.create();

assertRequest("POST", "JWT/Token/");
}

@Test(expected = IllegalArgumentException.class)
public void tokenCreateShouldFailWithoutAllParams() throws Exception {
Token.creator(null)
.create();
}
}
4 changes: 4 additions & 0 deletions src/test/resources/com/plivo/api/tokenCreateResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"api_id": "a9acb782-11e9-11ed-96c8-0242ac110002",
"token":"eyJhbGciOiJIUzI1NiIsImN0eSI6InBsaXZvO3Y9MSIsInR5cCI6IkpXVCJ9.eyJhcHAiOiIiLCJleHAiOjE2NTk0Nzk0NzksImlzcyI6Ik1BTURWTFpKWTJaR1k1TVdVMVpKIiwibmJmIjoxNjU5MzkzMDc5LCJwZXIiOnsidm9pY2UiOnsiaW5jb21pbmdfYWxsb3ciOmZhbHNlLCJvdXRnb2luZ19hbGxvdyI6ZmFsc2V9fSwic3ViIjoia293c2hpayJ9.dzmLy1JZb6Z9i7MzomCCh3cxaqyA_78O87E8ASkjk6M"
}