Skip to content

Commit

Permalink
Merge pull request kaltura#185 from kaltura/feature/session-provider-…
Browse files Browse the repository at this point in the history
…listener

Feature/session provider listener
  • Loading branch information
AntonAFA authored Mar 21, 2017
2 parents be5457c + efb7e28 commit f58ebca
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void onComplete(PrimitiveResult response) {
}


@Test
@Test
public void testOttAnonymousSession() {
final OttSessionProvider ottSessionProvider = new OttSessionProvider(PnxBaseUrl, PnxPartnerId);

Expand Down Expand Up @@ -235,6 +235,14 @@ public void onComplete(ResultElement<PKMediaEntry> response) {
wait(1);
}

@Test
public void testOttSwitchUser(){

}




@Test
public void testOvpSessionProviderBaseFlow() {
ovpSessionProvider = new OvpSessionProvider(OvpBaseUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

public class PrimitiveResult extends BaseResult {
private String result;
private String result = null;

public PrimitiveResult(String result) {
super();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kaltura.playkit.backend.phoenix.data;

import com.kaltura.playkit.backend.BaseResult;
import com.kaltura.playkit.connect.ErrorElement;

/**
* @hide
Expand All @@ -11,6 +12,13 @@ public class KalturaLoginResponse extends BaseResult {
private KalturaLoginSession loginSession;
private KalturaOTTUser user;

public KalturaLoginResponse(ErrorElement error) {
super(error);
}

public KalturaLoginResponse() {
super();
}

public KalturaLoginSession getLoginSession() {
return loginSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.kaltura.playkit.PKLog;
import com.kaltura.playkit.backend.BaseResult;
import com.kaltura.playkit.connect.ErrorElement;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;

/**
Expand All @@ -32,9 +35,32 @@ public BaseResult deserialize(JsonElement json, Type typeOfT, JsonDeserializatio
BaseResult baseResult = null;

if(result != null && result.has("error")){
baseResult = new BaseResult(new Gson().fromJson(result.get("error"), ErrorElement.class));

ErrorElement error = new Gson().fromJson(result.get("error"), ErrorElement.class);

// trying to find constructor that excepts ErrorElement in order to return an object of type "typeOfT" even on error.
try {
Constructor<? extends Type> constructor = typeOfT.getClass().getConstructor(ErrorElement.class);

if (constructor != null) {
baseResult = (BaseResult) constructor.newInstance(error);
}
} catch (NoSuchMethodException e) {
// do nothing
} catch (IllegalAccessException e) {
// do nothing
} catch (InstantiationException e) {
// do nothing
} catch (InvocationTargetException e) {
// do nothing - next code section will handle this
}

if (baseResult == null) {
baseResult = new BaseResult(error);
}

} else if(result != null && result.has("objectType")){

String objectType= result.getAsJsonPrimitive("objectType").getAsString();
if(objectType.equals("KalturaAPIException")) {
baseResult = new BaseResult(new Gson().fromJson(result, ErrorElement.class));
Expand All @@ -44,6 +70,7 @@ public BaseResult deserialize(JsonElement json, Type typeOfT, JsonDeserializatio
Class clz = Class.forName(clzName);
baseResult = (BaseResult) new Gson().fromJson(result, clz);
} catch (ClassNotFoundException e) {
PKLog.e("OttResultAdapter","can't find class "+objectType+ " in the provided package\n ");
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kaltura.playkit.backend.phoenix.services;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;

Expand Down Expand Up @@ -83,4 +84,31 @@ public static PhoenixRequestBuilder logout(String baseUrl, String ks, @Nullable
.params(params);
}

public static PhoenixRequestBuilder socialLogin(@NonNull String baseUrl, int partnerId, @NonNull String token, String socialNetwork, @Nullable String udid) {
JsonObject params = new JsonObject();
params.addProperty("token", token);
params.addProperty("partnerId", partnerId);
params.addProperty("type", socialNetwork);
if(udid != null) {
params.addProperty("udid", udid);
}

return new PhoenixRequestBuilder()
.service("social")
.action("login")
.method("POST")
.url(baseUrl)
.tag("social-login")
.params(params);
}

public enum KalturaSocialNetwork{
FACEBOOK("facebook");

public String value;

KalturaSocialNetwork(String value){
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ public static PhoenixRequestBuilder get(String baseUrl, String ks){
.tag("session-get")
.params(params);
}

public static PhoenixRequestBuilder switchUser(String baseUrl, String ks, String userIdToSwitch){
JsonObject params = new JsonObject();
params.addProperty("ks", ks);
params.addProperty("userIdToSwitch", userIdToSwitch);

return new PhoenixRequestBuilder()
.service("session")
.action("switchUser")
.method("POST")
.url(baseUrl)
.tag("session-switchUser")
.params(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ PKMediaSource getPreferredSource() {
}

List<PKDrmParams> drmParams = source.getDrmData();
if (drmParams != null) {
if (drmParams != null && !drmParams.isEmpty()) {
for (PKDrmParams params : drmParams) {
if (params.isSchemeSupported()) {
return source;
Expand Down

0 comments on commit f58ebca

Please sign in to comment.