Skip to content

Commit

Permalink
licence body update, refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamMuneer committed Oct 24, 2018
1 parent b496aa7 commit 615b995
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
*/
public interface ILicenceTo extends Serializable {
String jsonBody();
String getType();
/**
* @return Retrun request type, GET, POST etc.
*/
String getRequestType();
String getToken();
String getLicenceUrl();
String getM3U8Path();
String getUniqueKeyPathForVCB(); // Every Key must have a unique path, otherwise keys may get replaced or 2nd key with same path dont download
String getUniqueKeyPathForVCB(); // Every Key must have a unique path, otherwise keys may get replaced or 2nd key with same path may not download
String getLocalEncryptionKey();
String getLocalEncryptionIV();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by Hisham on 18/Oct/2018 - 15:18
*/
public abstract class KeyHelper implements Serializable, ILicenceTo{
public abstract class KeyHelper implements Serializable, ILicenceTo {

private String m3u8Path;
private String token;
Expand All @@ -31,7 +31,6 @@ public String getLicenceUrl() {
return licenceUrl;
}

@Override
public String getM3U8Path() {
return m3u8Path;
}
Expand Down
15 changes: 10 additions & 5 deletions protocol/src/main/java/com/vocabimate/protocol/LicenceBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.vocabimate.protocol.KeyHelper;

import java.io.Serializable;

Expand All @@ -25,20 +24,26 @@ public String jsonBody() {
}

@Override
public String getType() {
public String getRequestType() {
return "POST";
}

public int getVideoId() {
return licenceBodyInternal.videoId;
}

public int getUserId() {
return licenceBodyInternal.userId;
}

/**
* @return Unique key path for every video ex: vcb://{videoId} - vcb://18 or vcb://360p.m3u8/18
* @return Unique key path to append for every video ex: vcb://{videoId} that will become- vcb://18 or vcb://360p.m3u8/18, just it should be unique
*/
@Override
public String getUniqueKeyPathForVCB() {
return String.valueOf(licenceBodyInternal.videoId);
}


private class LicenceBodyInternal implements Serializable {
@SerializedName("userId")
int userId;
Expand All @@ -47,7 +52,7 @@ private class LicenceBodyInternal implements Serializable {
@SerializedName("delInd")
String delInd;

public LicenceBodyInternal(int userId, int videoId, String delInd) {
/* package */ LicenceBodyInternal(int userId, int videoId, String delInd) {
this.userId = userId;
this.videoId = videoId;
this.delInd = delInd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ public void connect() throws IOException {
// }
URL url = new URL(licence_url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if(licence.getType() == null) {
String requestType = licence.getRequestType();
if(requestType == null) {
connection.setRequestMethod("POST"); // default
} else {
connection.setRequestMethod(licence.getType());
connection.setRequestMethod(requestType);
}
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("access_token", token);
connection.setRequestProperty("Content-Type", "application/json");

if(licence.jsonBody() != null) {
String requestBody = licence.jsonBody();
if(requestBody != null) {
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(licence.jsonBody());
wr.write(requestBody);
wr.flush();
}

Expand Down

0 comments on commit 615b995

Please sign in to comment.