Panagiotis Triantafyllou

new internal version

......@@ -15,6 +15,7 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver;
import ly.warp.sdk.io.callbacks.WarplyReadyCallback;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyCosmoteUserRequest;
import ly.warp.sdk.io.request.WarplyLoginRequest;
import ly.warp.sdk.io.request.WarplyVerifyTicketRequest;
import ly.warp.sdk.utils.WarplyInitializer;
......@@ -34,11 +35,15 @@ public class SplashActivity extends BaseActivity {
@Override
public void onWarplyReady() {
if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) {
WarplyManager.login(new WarplyLoginRequest()
.setId("6981234567")
.setPassword("123456"),
mLoginReceiver
);
// WarplyManager.login(new WarplyLoginRequest()
// .setId("6981234567")
// .setPassword("123456"),
// mLoginReceiver
// );
WarplyManager.getCosmoteUser(new WarplyCosmoteUserRequest()
.setGuid("6012049321"),
mLoginReceiver);
// WarplyManager.verifyTicket(new WarplyVerifyTicketRequest()
// .setGuid("6012139059")
......
......@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'ly.warp'
PUBLISH_VERSION = '4.5.4-cosbeta27'
PUBLISH_VERSION = '4.5.4-cosbeta27a'
PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
}
......
......@@ -339,7 +339,12 @@ public enum Warply {
return;
}
postToServerInternal(hasAuthHeaders, path, jObj, receiver, null);
String tag = null;
if (path.equals("cosuser")) {
tag = "cosuser";
}
postToServerInternal(hasAuthHeaders, path, jObj, receiver, tag);
}
private void postReceiveMicroappDataInternal(String microappName, boolean hasAuthHeaders, String path,
......@@ -1489,12 +1494,17 @@ public enum Warply {
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_API);
else if (warplyPath.equals("verify"))
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarplyProperty.getVerifyUrl(mContext.get()));
else if (warplyPath.equals("cosuser"))
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + "/partners/oauth/" + WarplyProperty.getAppUuid(mContext.get()) + "/token");
else
sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_AUTH);
}
if (warplyPath != null) {
if (!warplyPath.equals("verify")) {
if (warplyPath.equals("cosuser")) {
return sb.toString();
}
sb.append(WarplyProperty.getAppUuid(mContext.get())).append("/");
if (warplyPath.equals("generate")) {
sb.append(WarpConstants.BASE_URL_OTP);
......
package ly.warp.sdk.io.request;
import android.util.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import ly.warp.sdk.Warply;
import ly.warp.sdk.utils.WarplyProperty;
import ly.warp.sdk.utils.constants.WarpConstants;
/**
* Created by Panagiotis Triantafyllou on 07-July-22.
*/
public class WarplyCosmoteUserRequest {
// ===========================================================
// Constants
// ===========================================================
private final String KEY_USER_ID = "user_identifier";
// ===========================================================
// Fields
// ===========================================================
private HashMap<String, String> mFilters;
private long mCacheUpdateInterval = 0;
private String mGuid = "";
// ===========================================================
// Constructor
// ===========================================================
/**
* Default constructor of WarplyCosmoteUserRequest, initializes an empty filters HashMap
*/
public WarplyCosmoteUserRequest() {
mFilters = new HashMap<>();
}
public WarplyCosmoteUserRequest(WarplyCosmoteUserRequest copy) {
if (copy != null) {
this.mFilters = copy.mFilters;
this.mCacheUpdateInterval = copy.mCacheUpdateInterval;
}
}
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean equals(Object object) {
if (object instanceof WarplyCosmoteUserRequest) {
WarplyCosmoteUserRequest other = (WarplyCosmoteUserRequest) object;
return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters)));
}
return false;
}
@Override
public int hashCode() {
return mFilters.hashCode();
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
public WarplyCosmoteUserRequest setGuid(String guid) {
mGuid = guid;
return this;
}
/**
* Call this to get how often the cached data will be updated.
*
* @return mCacheUpdateInterval
*/
public long getCacheUpdateInterval() {
return mCacheUpdateInterval;
}
/**
* Call this to set how often the cached data will be updated.
*
* @param updateInterval The time that data will be cached
* @return WarplyCosmoteUserRequest
*/
public WarplyCosmoteUserRequest setCacheUpdateInterval(long updateInterval) {
this.mCacheUpdateInterval = updateInterval;
if (mCacheUpdateInterval < 0) {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to check if the Application uses Cache
*
* @return <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
*/
public boolean isUseCache() {
return mCacheUpdateInterval > 0;
}
/**
* Call this to check whether the cached data need to be updated
*
* @param useCache <p>true - the Application is using Cache</p>
* <p>false - the Application is not using Cache</p>
* @return WarplyCosmoteUserRequest
*/
public WarplyCosmoteUserRequest setUseCache(boolean useCache) {
if (useCache) {
mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval
: WarpConstants.INBOX_UPDATE_INTERVAL;
} else {
mCacheUpdateInterval = 0;
}
return this;
}
/**
* Call this to build the offers Json object
*
* @return bodyJsonObject
*/
public JSONObject toJson() {
JSONObject bodyJsonObject = new JSONObject();
try {
bodyJsonObject.putOpt(KEY_USER_ID, mGuid);
} catch (JSONException e) {
if (WarpConstants.DEBUG)
e.printStackTrace();
}
return bodyJsonObject;
}
public String getSignature() {
String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_cosmote_user_request";
try {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8"));
signature = Base64.encodeToString(hash, Base64.NO_WRAP);
} catch (NullPointerException | NoSuchAlgorithmException
| UnsupportedEncodingException e) {
e.printStackTrace();
}
return signature;
}
}
......@@ -151,6 +151,9 @@ public class HttpClientStack implements HttpStack {
if (request.getTag() != null && request.getTag().equals("true")) {
headers.add(new BasicHeader(WarpConstants.HEADER_AUTHORIZATION,
"Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")));
} else if (request.getTag() != null && request.getTag().equals("cosuser")) {
headers.add(new BasicHeader(WarpConstants.HEADER_AUTHORIZATION,
"Basic MWlTM0EyNjcxT2Q0a1B5QkIydEs1ZU5uRENhR0NWQjQ6MjI4MjA4ZTliMTQzNGQ2MmIxNGI3ZDAzYjM2ZjUwMzg="));
}
httpPost.setHeaders(headers.toArray(new Header[headers.size()]));
byte[] body = request.getBody();
......
......@@ -76,6 +76,7 @@ import ly.warp.sdk.io.request.WarplyChangePasswordRequest;
import ly.warp.sdk.io.request.WarplyConsumerRequest;
import ly.warp.sdk.io.request.WarplyContactRequest;
import ly.warp.sdk.io.request.WarplyContentRequest;
import ly.warp.sdk.io.request.WarplyCosmoteUserRequest;
import ly.warp.sdk.io.request.WarplyDeleteAddressRequest;
import ly.warp.sdk.io.request.WarplyDeleteCardRequest;
import ly.warp.sdk.io.request.WarplyEditAddressRequest;
......@@ -1585,4 +1586,48 @@ public class WarplyManager {
}
});
}
public static void getCosmoteUser(WarplyCosmoteUserRequest request, final CallbackReceiver<JSONObject> receiver) {
WarpUtils.log("************* WARPLY Cosmote User Request ********************");
WarpUtils.log("[WARP Trace] WARPLY Cosmote User Request is active");
WarpUtils.log("**************************************************");
Warply.postReceiveMicroappData(false, "cosuser", request.toJson(), new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
int status = result.optInt("status", 2);
if (status == 1) {
JSONObject tokens = result.optJSONObject("result");
if (tokens != null) {
WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess(
tokens.optString("client_id", ""),
tokens.optString("client_secret", "")
);
WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess(
tokens.optString("access_token", ""),
tokens.optString("refresh_token", "")
);
JSONObject newResult = new JSONObject();
try {
newResult.putOpt("status", 1);
newResult.putOpt("message", "Success");
receiver.onSuccess(newResult);
} catch (JSONException e) {
e.printStackTrace();
receiver.onFailure(2);
}
} else
receiver.onFailure(2);
} else
receiver.onFailure(status);
}
@Override
public void onFailure(int errorCode) {
receiver.onFailure(errorCode);
}
});
}
}
......