From 615b99585e7f9261a794d3593646a67cf66672cb Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 24 Oct 2018 13:59:02 +0530 Subject: [PATCH] licence body update, refactor. --- .../java/com/vocabimate/protocol/ILicenceTo.java | 8 +++++--- .../java/com/vocabimate/protocol/KeyHelper.java | 3 +-- .../java/com/vocabimate/protocol/LicenceBody.java | 15 ++++++++++----- .../protocol/VocabimateHttpUrlConnection.java | 10 ++++++---- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/protocol/src/main/java/com/vocabimate/protocol/ILicenceTo.java b/protocol/src/main/java/com/vocabimate/protocol/ILicenceTo.java index 73097678f5c..28953055a2f 100644 --- a/protocol/src/main/java/com/vocabimate/protocol/ILicenceTo.java +++ b/protocol/src/main/java/com/vocabimate/protocol/ILicenceTo.java @@ -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(); } diff --git a/protocol/src/main/java/com/vocabimate/protocol/KeyHelper.java b/protocol/src/main/java/com/vocabimate/protocol/KeyHelper.java index 81b2d0e78f4..17653ddd514 100644 --- a/protocol/src/main/java/com/vocabimate/protocol/KeyHelper.java +++ b/protocol/src/main/java/com/vocabimate/protocol/KeyHelper.java @@ -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; @@ -31,7 +31,6 @@ public String getLicenceUrl() { return licenceUrl; } - @Override public String getM3U8Path() { return m3u8Path; } diff --git a/protocol/src/main/java/com/vocabimate/protocol/LicenceBody.java b/protocol/src/main/java/com/vocabimate/protocol/LicenceBody.java index c0cdc5a05f0..21cf805532c 100644 --- a/protocol/src/main/java/com/vocabimate/protocol/LicenceBody.java +++ b/protocol/src/main/java/com/vocabimate/protocol/LicenceBody.java @@ -2,7 +2,6 @@ import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; -import com.vocabimate.protocol.KeyHelper; import java.io.Serializable; @@ -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; @@ -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; diff --git a/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java b/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java index 49a11c986f9..850ebc7cc39 100644 --- a/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java +++ b/protocol/src/main/java/com/vocabimate/protocol/VocabimateHttpUrlConnection.java @@ -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(); }