Panagiotis Triantafyllou

new internal version

...@@ -15,6 +15,7 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver; ...@@ -15,6 +15,7 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver;
15 import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver; 15 import ly.warp.sdk.io.callbacks.SimpleCallbackReceiver;
16 import ly.warp.sdk.io.callbacks.WarplyReadyCallback; 16 import ly.warp.sdk.io.callbacks.WarplyReadyCallback;
17 import ly.warp.sdk.io.request.WarplyConsumerRequest; 17 import ly.warp.sdk.io.request.WarplyConsumerRequest;
18 +import ly.warp.sdk.io.request.WarplyCosmoteUserRequest;
18 import ly.warp.sdk.io.request.WarplyLoginRequest; 19 import ly.warp.sdk.io.request.WarplyLoginRequest;
19 import ly.warp.sdk.io.request.WarplyVerifyTicketRequest; 20 import ly.warp.sdk.io.request.WarplyVerifyTicketRequest;
20 import ly.warp.sdk.utils.WarplyInitializer; 21 import ly.warp.sdk.utils.WarplyInitializer;
...@@ -34,11 +35,15 @@ public class SplashActivity extends BaseActivity { ...@@ -34,11 +35,15 @@ public class SplashActivity extends BaseActivity {
34 @Override 35 @Override
35 public void onWarplyReady() { 36 public void onWarplyReady() {
36 if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) { 37 if (!WarplyDBHelper.getInstance(SplashActivity.this).isTableNotEmpty("auth")) {
37 - WarplyManager.login(new WarplyLoginRequest() 38 +// WarplyManager.login(new WarplyLoginRequest()
38 - .setId("6981234567") 39 +// .setId("6981234567")
39 - .setPassword("123456"), 40 +// .setPassword("123456"),
40 - mLoginReceiver 41 +// mLoginReceiver
41 - ); 42 +// );
43 +
44 + WarplyManager.getCosmoteUser(new WarplyCosmoteUserRequest()
45 + .setGuid("6012049321"),
46 + mLoginReceiver);
42 47
43 // WarplyManager.verifyTicket(new WarplyVerifyTicketRequest() 48 // WarplyManager.verifyTicket(new WarplyVerifyTicketRequest()
44 // .setGuid("6012139059") 49 // .setGuid("6012139059")
......
...@@ -2,7 +2,7 @@ apply plugin: 'com.android.library' ...@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
2 2
3 ext { 3 ext {
4 PUBLISH_GROUP_ID = 'ly.warp' 4 PUBLISH_GROUP_ID = 'ly.warp'
5 - PUBLISH_VERSION = '4.5.4-cosbeta27' 5 + PUBLISH_VERSION = '4.5.4-cosbeta27a'
6 PUBLISH_ARTIFACT_ID = 'warply-android-sdk' 6 PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
7 } 7 }
8 8
......
...@@ -339,7 +339,12 @@ public enum Warply { ...@@ -339,7 +339,12 @@ public enum Warply {
339 return; 339 return;
340 } 340 }
341 341
342 - postToServerInternal(hasAuthHeaders, path, jObj, receiver, null); 342 + String tag = null;
343 + if (path.equals("cosuser")) {
344 + tag = "cosuser";
345 + }
346 +
347 + postToServerInternal(hasAuthHeaders, path, jObj, receiver, tag);
343 } 348 }
344 349
345 private void postReceiveMicroappDataInternal(String microappName, boolean hasAuthHeaders, String path, 350 private void postReceiveMicroappDataInternal(String microappName, boolean hasAuthHeaders, String path,
...@@ -1489,12 +1494,17 @@ public enum Warply { ...@@ -1489,12 +1494,17 @@ public enum Warply {
1489 sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_API); 1494 sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_API);
1490 else if (warplyPath.equals("verify")) 1495 else if (warplyPath.equals("verify"))
1491 sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarplyProperty.getVerifyUrl(mContext.get())); 1496 sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarplyProperty.getVerifyUrl(mContext.get()));
1497 + else if (warplyPath.equals("cosuser"))
1498 + sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + "/partners/oauth/" + WarplyProperty.getAppUuid(mContext.get()) + "/token");
1492 else 1499 else
1493 sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_AUTH); 1500 sb = new StringBuilder(WarplyProperty.getBaseUrl(mContext.get()) + WarpConstants.BASE_URL_AUTH);
1494 } 1501 }
1495 1502
1496 if (warplyPath != null) { 1503 if (warplyPath != null) {
1497 if (!warplyPath.equals("verify")) { 1504 if (!warplyPath.equals("verify")) {
1505 + if (warplyPath.equals("cosuser")) {
1506 + return sb.toString();
1507 + }
1498 sb.append(WarplyProperty.getAppUuid(mContext.get())).append("/"); 1508 sb.append(WarplyProperty.getAppUuid(mContext.get())).append("/");
1499 if (warplyPath.equals("generate")) { 1509 if (warplyPath.equals("generate")) {
1500 sb.append(WarpConstants.BASE_URL_OTP); 1510 sb.append(WarpConstants.BASE_URL_OTP);
......
1 +package ly.warp.sdk.io.request;
2 +
3 +import android.util.Base64;
4 +
5 +import org.json.JSONException;
6 +import org.json.JSONObject;
7 +
8 +import java.io.UnsupportedEncodingException;
9 +import java.security.MessageDigest;
10 +import java.security.NoSuchAlgorithmException;
11 +import java.util.HashMap;
12 +
13 +import ly.warp.sdk.Warply;
14 +import ly.warp.sdk.utils.WarplyProperty;
15 +import ly.warp.sdk.utils.constants.WarpConstants;
16 +
17 +/**
18 + * Created by Panagiotis Triantafyllou on 07-July-22.
19 + */
20 +
21 +public class WarplyCosmoteUserRequest {
22 +
23 + // ===========================================================
24 + // Constants
25 + // ===========================================================
26 +
27 + private final String KEY_USER_ID = "user_identifier";
28 +
29 + // ===========================================================
30 + // Fields
31 + // ===========================================================
32 +
33 + private HashMap<String, String> mFilters;
34 + private long mCacheUpdateInterval = 0;
35 + private String mGuid = "";
36 +
37 + // ===========================================================
38 + // Constructor
39 + // ===========================================================
40 +
41 + /**
42 + * Default constructor of WarplyCosmoteUserRequest, initializes an empty filters HashMap
43 + */
44 + public WarplyCosmoteUserRequest() {
45 + mFilters = new HashMap<>();
46 + }
47 +
48 + public WarplyCosmoteUserRequest(WarplyCosmoteUserRequest copy) {
49 + if (copy != null) {
50 + this.mFilters = copy.mFilters;
51 + this.mCacheUpdateInterval = copy.mCacheUpdateInterval;
52 + }
53 + }
54 +
55 + // ===========================================================
56 + // Methods for/from SuperClass/Interfaces
57 + // ===========================================================
58 +
59 + @Override
60 + public boolean equals(Object object) {
61 + if (object instanceof WarplyCosmoteUserRequest) {
62 + WarplyCosmoteUserRequest other = (WarplyCosmoteUserRequest) object;
63 + return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters)));
64 + }
65 + return false;
66 + }
67 +
68 + @Override
69 + public int hashCode() {
70 + return mFilters.hashCode();
71 + }
72 +
73 + // ===========================================================
74 + // Methods
75 + // ===========================================================
76 +
77 + // ===========================================================
78 + // Getter & Setter
79 + // ===========================================================
80 +
81 + public WarplyCosmoteUserRequest setGuid(String guid) {
82 + mGuid = guid;
83 + return this;
84 + }
85 +
86 + /**
87 + * Call this to get how often the cached data will be updated.
88 + *
89 + * @return mCacheUpdateInterval
90 + */
91 + public long getCacheUpdateInterval() {
92 + return mCacheUpdateInterval;
93 + }
94 +
95 + /**
96 + * Call this to set how often the cached data will be updated.
97 + *
98 + * @param updateInterval The time that data will be cached
99 + * @return WarplyCosmoteUserRequest
100 + */
101 + public WarplyCosmoteUserRequest setCacheUpdateInterval(long updateInterval) {
102 +
103 + this.mCacheUpdateInterval = updateInterval;
104 + if (mCacheUpdateInterval < 0) {
105 + mCacheUpdateInterval = 0;
106 + }
107 + return this;
108 + }
109 +
110 + /**
111 + * Call this to check if the Application uses Cache
112 + *
113 + * @return <p>true - the Application is using Cache</p>
114 + * <p>false - the Application is not using Cache</p>
115 + */
116 + public boolean isUseCache() {
117 + return mCacheUpdateInterval > 0;
118 + }
119 +
120 + /**
121 + * Call this to check whether the cached data need to be updated
122 + *
123 + * @param useCache <p>true - the Application is using Cache</p>
124 + * <p>false - the Application is not using Cache</p>
125 + * @return WarplyCosmoteUserRequest
126 + */
127 + public WarplyCosmoteUserRequest setUseCache(boolean useCache) {
128 +
129 + if (useCache) {
130 + mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval
131 + : WarpConstants.INBOX_UPDATE_INTERVAL;
132 + } else {
133 + mCacheUpdateInterval = 0;
134 + }
135 + return this;
136 + }
137 +
138 + /**
139 + * Call this to build the offers Json object
140 + *
141 + * @return bodyJsonObject
142 + */
143 + public JSONObject toJson() {
144 + JSONObject bodyJsonObject = new JSONObject();
145 + try {
146 + bodyJsonObject.putOpt(KEY_USER_ID, mGuid);
147 + } catch (JSONException e) {
148 + if (WarpConstants.DEBUG)
149 + e.printStackTrace();
150 + }
151 + return bodyJsonObject;
152 + }
153 +
154 + public String getSignature() {
155 + String signature = mFilters != null && mFilters.size() > 0 ? String.valueOf(mFilters.hashCode()) : "default_cosmote_user_request";
156 + try {
157 + byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8"));
158 + signature = Base64.encodeToString(hash, Base64.NO_WRAP);
159 + } catch (NullPointerException | NoSuchAlgorithmException
160 + | UnsupportedEncodingException e) {
161 + e.printStackTrace();
162 + }
163 + return signature;
164 + }
165 +}
...@@ -151,6 +151,9 @@ public class HttpClientStack implements HttpStack { ...@@ -151,6 +151,9 @@ public class HttpClientStack implements HttpStack {
151 if (request.getTag() != null && request.getTag().equals("true")) { 151 if (request.getTag() != null && request.getTag().equals("true")) {
152 headers.add(new BasicHeader(WarpConstants.HEADER_AUTHORIZATION, 152 headers.add(new BasicHeader(WarpConstants.HEADER_AUTHORIZATION,
153 "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token"))); 153 "Bearer " + WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token")));
154 + } else if (request.getTag() != null && request.getTag().equals("cosuser")) {
155 + headers.add(new BasicHeader(WarpConstants.HEADER_AUTHORIZATION,
156 + "Basic MWlTM0EyNjcxT2Q0a1B5QkIydEs1ZU5uRENhR0NWQjQ6MjI4MjA4ZTliMTQzNGQ2MmIxNGI3ZDAzYjM2ZjUwMzg="));
154 } 157 }
155 httpPost.setHeaders(headers.toArray(new Header[headers.size()])); 158 httpPost.setHeaders(headers.toArray(new Header[headers.size()]));
156 byte[] body = request.getBody(); 159 byte[] body = request.getBody();
......
...@@ -76,6 +76,7 @@ import ly.warp.sdk.io.request.WarplyChangePasswordRequest; ...@@ -76,6 +76,7 @@ import ly.warp.sdk.io.request.WarplyChangePasswordRequest;
76 import ly.warp.sdk.io.request.WarplyConsumerRequest; 76 import ly.warp.sdk.io.request.WarplyConsumerRequest;
77 import ly.warp.sdk.io.request.WarplyContactRequest; 77 import ly.warp.sdk.io.request.WarplyContactRequest;
78 import ly.warp.sdk.io.request.WarplyContentRequest; 78 import ly.warp.sdk.io.request.WarplyContentRequest;
79 +import ly.warp.sdk.io.request.WarplyCosmoteUserRequest;
79 import ly.warp.sdk.io.request.WarplyDeleteAddressRequest; 80 import ly.warp.sdk.io.request.WarplyDeleteAddressRequest;
80 import ly.warp.sdk.io.request.WarplyDeleteCardRequest; 81 import ly.warp.sdk.io.request.WarplyDeleteCardRequest;
81 import ly.warp.sdk.io.request.WarplyEditAddressRequest; 82 import ly.warp.sdk.io.request.WarplyEditAddressRequest;
...@@ -1585,4 +1586,48 @@ public class WarplyManager { ...@@ -1585,4 +1586,48 @@ public class WarplyManager {
1585 } 1586 }
1586 }); 1587 });
1587 } 1588 }
1589 +
1590 + public static void getCosmoteUser(WarplyCosmoteUserRequest request, final CallbackReceiver<JSONObject> receiver) {
1591 + WarpUtils.log("************* WARPLY Cosmote User Request ********************");
1592 + WarpUtils.log("[WARP Trace] WARPLY Cosmote User Request is active");
1593 + WarpUtils.log("**************************************************");
1594 +
1595 + Warply.postReceiveMicroappData(false, "cosuser", request.toJson(), new CallbackReceiver<JSONObject>() {
1596 + @Override
1597 + public void onSuccess(JSONObject result) {
1598 + int status = result.optInt("status", 2);
1599 + if (status == 1) {
1600 + JSONObject tokens = result.optJSONObject("result");
1601 + if (tokens != null) {
1602 + WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveClientAccess(
1603 + tokens.optString("client_id", ""),
1604 + tokens.optString("client_secret", "")
1605 + );
1606 +
1607 + WarplyDBHelper.getInstance(Warply.getWarplyContext()).saveAuthAccess(
1608 + tokens.optString("access_token", ""),
1609 + tokens.optString("refresh_token", "")
1610 + );
1611 +
1612 + JSONObject newResult = new JSONObject();
1613 + try {
1614 + newResult.putOpt("status", 1);
1615 + newResult.putOpt("message", "Success");
1616 + receiver.onSuccess(newResult);
1617 + } catch (JSONException e) {
1618 + e.printStackTrace();
1619 + receiver.onFailure(2);
1620 + }
1621 + } else
1622 + receiver.onFailure(2);
1623 + } else
1624 + receiver.onFailure(status);
1625 + }
1626 +
1627 + @Override
1628 + public void onFailure(int errorCode) {
1629 + receiver.onFailure(errorCode);
1630 + }
1631 + });
1632 + }
1588 } 1633 }
......