Panagiotis Triantafyllou

new campaigns

...@@ -1487,6 +1487,8 @@ public enum Warply { ...@@ -1487,6 +1487,8 @@ public enum Warply {
1487 if (path.equals("register") || path.equals("change_password") || path.equals("password_reset") 1487 if (path.equals("register") || path.equals("change_password") || path.equals("password_reset")
1488 || path.equals("generate")) 1488 || path.equals("generate"))
1489 url = buildWarplyAuthRequestUrl(path, true); 1489 url = buildWarplyAuthRequestUrl(path, true);
1490 + else if (path.equals("campaigns"))
1491 + url = buildWarplyRequestUrl(null);
1490 else 1492 else
1491 url = buildWarplyAuthRequestUrl(path, false); 1493 url = buildWarplyAuthRequestUrl(path, false);
1492 requestToServerInternal(Method.POST, url, data, listener, tag, hasAuthHeaders); 1494 requestToServerInternal(Method.POST, url, data, listener, tag, hasAuthHeaders);
......
1 +/*
2 + * Copyright 2010-2013 Warply Ltd. All rights reserved.
3 + *
4 + * Redistribution and use in source and binary forms, without modification, are
5 + * permitted provided that the following conditions are met:
6 + *
7 + * 1. Redistributions of source code must retain the above copyright notice,
8 + * this list of conditions and the following disclaimer.
9 + *
10 + * 2. Redistributions in binary form must reproduce the above copyright notice,
11 + * this list of conditions and the following disclaimer in the documentation
12 + * and/or other materials provided with the distribution.
13 + *
14 + * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
15 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 + * EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20 + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 + */
25 +
26 +package ly.warp.sdk.io.callbacks;
27 +
28 +import org.json.JSONObject;
29 +
30 +import ly.warp.sdk.io.models.NewCampaignList;
31 +
32 +/**
33 + * Created by Panagiotis Triantafyllou on 12-May-22.
34 + */
35 +
36 +public class NewCampaignsHook implements CallbackReceiver<JSONObject> {
37 +
38 + private final CallbackReceiver<NewCampaignList> mListener;
39 + private final String mRequestSignature;
40 +
41 + public NewCampaignsHook(CallbackReceiver<NewCampaignList> listener, String requestSignature) {
42 + this.mListener = listener;
43 + this.mRequestSignature = requestSignature;
44 + }
45 +
46 + @Override
47 + public void onSuccess(JSONObject result) {
48 + if (mListener != null) {
49 + int status = result.optInt("status", 2);
50 + if (status == 1) {
51 + mListener.onSuccess(new NewCampaignList(result, mRequestSignature));
52 + } else
53 + mListener.onFailure(status);
54 + }
55 +
56 + }
57 +
58 + @Override
59 + public void onFailure(int errorCode) {
60 + if (mListener != null)
61 + mListener.onFailure(errorCode);
62 + }
63 +}
1 +/*
2 + * Copyright 2010-2013 Warply Ltd. All rights reserved.
3 + *
4 + * Redistribution and use in source and binary forms, without modification, are
5 + * permitted provided that the following conditions are met:
6 + *
7 + * 1. Redistributions of source code must retain the above copyright notice,
8 + * this list of conditions and the following disclaimer.
9 + *
10 + * 2. Redistributions in binary form must reproduce the above copyright notice,
11 + * this list of conditions and the following disclaimer in the documentation
12 + * and/or other materials provided with the distribution.
13 + *
14 + * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
15 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 + * EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20 + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 + */
25 +
26 +package ly.warp.sdk.io.models;
27 +
28 +import android.os.Parcel;
29 +import android.os.Parcelable;
30 +
31 +import org.json.JSONException;
32 +import org.json.JSONObject;
33 +
34 +import java.io.Serializable;
35 +
36 +import ly.warp.sdk.utils.WarpUtils;
37 +import ly.warp.sdk.utils.constants.WarpConstants;
38 +
39 +/**
40 + * Created by Panagiotis Triantafyllou on 12-May-22.
41 + */
42 +
43 +public class NewCampaign implements Parcelable, Serializable {
44 +
45 + private static final long serialVersionUID = -4754964462459705285L;
46 +
47 + /* Constants used to export the campaign in JSON formal and vice versa */
48 + private static final String SUBTITLE = "subtitle";
49 + private static final String TITLE = "title";
50 + private static final String COMMUNICATION_UUID = "communication_uuid";
51 + private static final String MESSAGE = "message";
52 + private static final String DESCRIPTION = "description";
53 + private static final String INDEX_URL = "index_url";
54 + private static final String LOGO_URL = "logo_url";
55 + private static final String START_DATE = "start_date";
56 + private static final String END_DATE = "end_date";
57 + private static final String SORTING = "sorting";
58 + private static final String CATEGORY = "category";
59 + private static final String COMMUNICATION_NAME = "communication_name";
60 + private static final String COMMUNICATION_CATEGORY = "communication_category";
61 + private static final String EXTRA_FIELDS = "extra_fields";
62 + private static final String WORKFLOW_SETTINGS = "workflow_settings";
63 + private static final String DISPLAY_TYPE = "display_type";
64 + private static final String DELIVERY_METHOD = "delivery_method";
65 + private static final String CAMPAIGN_TYPE = "campaign_type";
66 + private static final String SETTINGS = "settings";
67 + private static final String AUDIENCE = "audience";
68 + private static final String IS_NEW = "is_new";
69 +
70 + /* Member variables of the Campaign object */
71 + private final String campaignType;
72 + private final String settings;
73 + private final String audience;
74 + private final String deliveryMethod;
75 + private final String displayType;
76 + private final String extraFields;
77 + private final String workflowSettings;
78 + private final String category;
79 + private final int sorting;
80 + private final String indexUrl;
81 + private final String message;
82 + private final String description;
83 + private final String subtitle;
84 + private final String title;
85 + private final String communicationUUID;
86 + private final String logoUrl;
87 + private final String startDate;
88 + private final String endDate;
89 + private final String communicationName;
90 + private final String communicationCategory;
91 + private boolean isNew = false;
92 +
93 + /**
94 + * Basic constructor used to create an object from a String, representing a
95 + * JSON Object
96 + *
97 + * @param json The String, representing the JSON Object
98 + * @throws JSONException Thrown if the String cannot be converted to JSON
99 + */
100 + public NewCampaign(String json) throws JSONException {
101 + this(new JSONObject(json));
102 + }
103 +
104 + /**
105 + * Constructor used to create an Object from a given JSON Object
106 + *
107 + * @param json JSON Object used to create the Campaign
108 + */
109 + public NewCampaign(JSONObject json) {
110 + this.indexUrl = json.optString(INDEX_URL);
111 + this.logoUrl = json.optString(LOGO_URL);
112 + this.communicationUUID = json.optString(COMMUNICATION_UUID);
113 + this.subtitle = json.optString(SUBTITLE);
114 + this.message = json.optString(MESSAGE);
115 + this.category = json.optString(CATEGORY);
116 + this.title = json.optString(TITLE);
117 + this.sorting = json.optInt(SORTING);
118 + this.extraFields = json.optString(EXTRA_FIELDS);
119 + this.campaignType = json.optString(CAMPAIGN_TYPE);
120 + this.deliveryMethod = json.optString(DELIVERY_METHOD);
121 + this.displayType = json.optString(DISPLAY_TYPE);
122 + this.settings = json.optString(SETTINGS);
123 + this.audience = json.optString(AUDIENCE);
124 + this.workflowSettings = json.optString(WORKFLOW_SETTINGS);
125 + this.description = json.optString(DESCRIPTION);
126 + this.startDate = json.optString(START_DATE);
127 + this.endDate = json.optString(END_DATE);
128 + this.communicationName = json.optString(COMMUNICATION_NAME);
129 + this.communicationCategory = json.optString(COMMUNICATION_CATEGORY);
130 + this.isNew = json.optBoolean(IS_NEW);
131 +
132 + }
133 +
134 + public NewCampaign(Parcel source) {
135 + this.indexUrl = source.readString();
136 + this.message = source.readString();
137 + this.communicationUUID = source.readString();
138 + this.subtitle = source.readString();
139 + this.title = source.readString();
140 + this.sorting = source.readInt();
141 + this.isNew = source.readByte() != 0;
142 + this.logoUrl = source.readString();
143 + this.extraFields = source.readString();
144 + this.deliveryMethod = source.readString();
145 + this.displayType = source.readString();
146 + this.settings = source.readString();
147 + this.audience = source.readString();
148 + this.workflowSettings = source.readString();
149 + this.description = source.readString();
150 + this.startDate = source.readString();
151 + this.endDate = source.readString();
152 + this.communicationName = source.readString();
153 + this.communicationCategory = source.readString();
154 + this.category = source.readString();
155 + this.campaignType = source.readString();
156 + }
157 +
158 + @Override
159 + public void writeToParcel(Parcel dest, int flags) {
160 + dest.writeString(this.indexUrl);
161 + dest.writeString(this.message);
162 + dest.writeString(this.subtitle);
163 + dest.writeString(this.title);
164 + dest.writeInt(this.sorting);
165 + dest.writeInt(this.isNew ? 1 : 0);
166 + dest.writeString(this.logoUrl);
167 + dest.writeString(extraFields);
168 + dest.writeString(deliveryMethod);
169 + dest.writeString(displayType);
170 + dest.writeString(this.settings);
171 + dest.writeString(this.audience);
172 + dest.writeString(this.workflowSettings);
173 + dest.writeString(this.description);
174 + dest.writeString(this.startDate);
175 + dest.writeString(this.endDate);
176 + dest.writeString(this.communicationName);
177 + dest.writeString(this.communicationCategory);
178 + dest.writeString(this.category);
179 + dest.writeString(this.campaignType);
180 + dest.writeString(this.communicationUUID);
181 + }
182 +
183 + /**
184 + * Converts the Campaign into a JSON Object
185 + *
186 + * @return The JSON Object created from this campaign
187 + */
188 + public JSONObject toJSONObject() {
189 + JSONObject jObj = new JSONObject();
190 + try {
191 + jObj.putOpt(INDEX_URL, this.indexUrl);
192 + jObj.putOpt(LOGO_URL, this.logoUrl);
193 + jObj.putOpt(MESSAGE, this.message);
194 + jObj.putOpt(COMMUNICATION_UUID, this.communicationUUID);
195 + jObj.putOpt(SUBTITLE, this.subtitle);
196 + jObj.putOpt(TITLE, this.title);
197 + jObj.putOpt(SORTING, this.sorting);
198 + jObj.putOpt(IS_NEW, this.isNew);
199 + jObj.putOpt(EXTRA_FIELDS, this.extraFields);
200 + jObj.putOpt(DELIVERY_METHOD, this.deliveryMethod);
201 + jObj.putOpt(DISPLAY_TYPE, this.displayType);
202 + jObj.putOpt(SETTINGS, this.settings);
203 + jObj.putOpt(AUDIENCE, this.audience);
204 + jObj.putOpt(WORKFLOW_SETTINGS, this.workflowSettings);
205 + jObj.putOpt(DESCRIPTION, this.description);
206 + jObj.putOpt(START_DATE, this.startDate);
207 + jObj.putOpt(END_DATE, this.endDate);
208 + jObj.putOpt(COMMUNICATION_NAME, this.communicationName);
209 + jObj.putOpt(COMMUNICATION_CATEGORY, this.communicationCategory);
210 + jObj.putOpt(CATEGORY, this.category);
211 + jObj.putOpt(CAMPAIGN_TYPE, this.campaignType);
212 + } catch (JSONException e) {
213 + if (WarpConstants.DEBUG) {
214 + e.printStackTrace();
215 + }
216 + }
217 + return jObj;
218 + }
219 +
220 + /**
221 + * String representation of the Campaign, as a JSON object
222 + *
223 + * @return A String representation of JSON object
224 + */
225 + public String toString() {
226 + if (toJSONObject() != null)
227 + return toJSONObject().toString();
228 + return null;
229 + }
230 +
231 + /**
232 + * String representation of the Campaign, as a human readable JSON object
233 + *
234 + * @return A human readable String representation of JSON object
235 + */
236 + public String toHumanReadableString() {
237 + String humanReadableString = null;
238 + try {
239 + humanReadableString = toJSONObject().toString(2);
240 + } catch (JSONException e) {
241 + WarpUtils.warn("Failed converting Campaign JSON object to String",
242 + e);
243 + }
244 + return humanReadableString;
245 + }
246 +
247 + // ================================================================================
248 + // Getters
249 + // ================================================================================
250 +
251 + /**
252 + * @return The message of the campaign
253 + */
254 + public String getMessage() {
255 + return message;
256 + }
257 +
258 + /**
259 + * @return The subtitle of the campaign
260 + */
261 + public String getSubtitle() {
262 + return subtitle;
263 + }
264 +
265 + /**
266 + * @return The title of the campaign
267 + */
268 + public String getTitle() {
269 + return title;
270 + }
271 +
272 + /**
273 + * @return An int that is used for sorting. This should be used as the
274 + * default sorting value
275 + */
276 + public int getSorting() {
277 + return sorting;
278 + }
279 +
280 + /**
281 + * Method used to get if the campaign is a new one
282 + *
283 + * @return <code>true</code> if the campaign is new; <code>false</code>
284 + * otherwise
285 + */
286 + public boolean getIsNew() {
287 + return isNew;
288 + }
289 +
290 + public String getLogoUrl() {
291 + return logoUrl;
292 + }
293 +
294 + public String getIndexUrl() {
295 + return indexUrl;
296 + }
297 +
298 + public String getExtraFields() {
299 + return extraFields;
300 + }
301 +
302 + public String getDeliveryMethod() {
303 + return deliveryMethod;
304 + }
305 +
306 + public String getDisplayType() {
307 + return displayType;
308 + }
309 +
310 + public String getCampaignType() {
311 + return campaignType;
312 + }
313 +
314 + public String getSettings() {
315 + return settings;
316 + }
317 +
318 + public String getAudience() {
319 + return audience;
320 + }
321 +
322 + public String getWorkflowSettings() {
323 + return workflowSettings;
324 + }
325 +
326 + public String getCategory() {
327 + return category;
328 + }
329 +
330 + public String getDescription() {
331 + return description;
332 + }
333 +
334 + public String getCommunicationUUID() {
335 + return communicationUUID;
336 + }
337 +
338 + public String getStartDate() {
339 + return startDate;
340 + }
341 +
342 + public String getEndDate() {
343 + return endDate;
344 + }
345 +
346 + public String getCommunicationName() {
347 + return communicationName;
348 + }
349 +
350 + public String getCommunicationCategory() {
351 + return communicationCategory;
352 + }
353 +
354 + public boolean isNew() {
355 + return isNew;
356 + }
357 +
358 + @Override
359 + public int describeContents() {
360 + return 0;
361 + }
362 +
363 + public static final Creator<NewCampaign> CREATOR = new Creator<NewCampaign>() {
364 + public NewCampaign createFromParcel(Parcel source) {
365 + return new NewCampaign(source);
366 + }
367 +
368 + public NewCampaign[] newArray(int size) {
369 + return new NewCampaign[size];
370 + }
371 + };
372 +}
1 +/*
2 + * Copyright 2010-2013 Warply Ltd. All rights reserved.
3 + *
4 + * Redistribution and use in source and binary forms, without modification, are
5 + * permitted provided that the following conditions are met:
6 + *
7 + * 1. Redistributions of source code must retain the above copyright notice,
8 + * this list of conditions and the following disclaimer.
9 + *
10 + * 2. Redistributions in binary form must reproduce the above copyright notice,
11 + * this list of conditions and the following disclaimer in the documentation
12 + * and/or other materials provided with the distribution.
13 + *
14 + * THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
15 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
17 + * EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20 + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 + */
25 +
26 +package ly.warp.sdk.io.models;
27 +
28 +import androidx.annotation.NonNull;
29 +
30 +import org.json.JSONArray;
31 +import org.json.JSONObject;
32 +
33 +import java.util.ArrayList;
34 +
35 +/**
36 + * Created by Panagiotis Triantafyllou on 12-May-22.
37 + */
38 +
39 +public class NewCampaignList extends ArrayList<NewCampaign> {
40 +
41 + /**
42 + * Generated for serialized class
43 + */
44 + private static final long serialVersionUID = -188843583823948267L;
45 +
46 + private static final String JSON_KEY_MAPP = "MAPP_CAMPAIGNING";
47 + private static final String JSON_KEY_MAPP_VALUE = "campaigns";
48 + private static final String JSON_KEY_CONTEXT = "context";
49 +
50 + private String mRequestSignature = "";
51 +
52 + private NewCampaignList(String requestSignature) {
53 + this.mRequestSignature = requestSignature;
54 + }
55 +
56 + public NewCampaignList() {
57 + super();
58 + }
59 +
60 + /**
61 + * Constructor used to create the CampaignList from a JSON Object.
62 + *
63 + * @param campaignListJSONObject The JSON Object, used to create the CampaignList
64 + */
65 + public NewCampaignList(JSONObject campaignListJSONObject, String requestSignature) {
66 + this(requestSignature);
67 +
68 + campaignListJSONObject = campaignListJSONObject.optJSONObject(JSON_KEY_CONTEXT);
69 + if (campaignListJSONObject == null)
70 + return;
71 + JSONObject jsonObject = campaignListJSONObject.optJSONObject(JSON_KEY_MAPP);
72 + if(jsonObject == null)
73 + return;;
74 + JSONArray jArray = jsonObject.optJSONArray(JSON_KEY_MAPP_VALUE);
75 + if (jArray != null) {
76 + for (int i = 0, lim = jArray.length(); i < lim; ++i) {
77 + add(new NewCampaign(jArray.optJSONObject(i)));
78 + }
79 + }
80 + }
81 +
82 + @NonNull
83 + public String getRequestSignature() {
84 + return mRequestSignature;
85 + }
86 +}
...@@ -13,6 +13,8 @@ import java.security.NoSuchAlgorithmException; ...@@ -13,6 +13,8 @@ import java.security.NoSuchAlgorithmException;
13 import java.util.ArrayList; 13 import java.util.ArrayList;
14 import java.util.HashMap; 14 import java.util.HashMap;
15 15
16 +import ly.warp.sdk.Warply;
17 +import ly.warp.sdk.utils.WarplyProperty;
16 import ly.warp.sdk.utils.constants.WarpConstants; 18 import ly.warp.sdk.utils.constants.WarpConstants;
17 19
18 /** 20 /**
...@@ -40,7 +42,7 @@ public class WarplyContentRequest { ...@@ -40,7 +42,7 @@ public class WarplyContentRequest {
40 private long mCacheUpdateInterval = 0; 42 private long mCacheUpdateInterval = 0;
41 private String mContentCategory = ""; 43 private String mContentCategory = "";
42 private ArrayList<String> mTags = new ArrayList<>(); 44 private ArrayList<String> mTags = new ArrayList<>();
43 - private String mLanguage = ""; 45 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
44 46
45 // =========================================================== 47 // ===========================================================
46 // Constructor 48 // Constructor
......
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 +
12 +import ly.warp.sdk.Warply;
13 +import ly.warp.sdk.utils.WarplyProperty;
14 +import ly.warp.sdk.utils.constants.WarpConstants;
15 +
16 +/**
17 + * Created by Panagiotis Triantafyllou on 12-May-22.
18 + */
19 +
20 +public class WarplyGetCampaignsRequest {
21 +
22 + // ===========================================================
23 + // Constants
24 + // ===========================================================
25 +
26 + private final String KEY_ACTION = "action";
27 + private final String KEY_ACTION_VALUE = "retrieve";
28 + private final String KEY_LANGUAGE = "language";
29 + private final String KEY_FILTERS = "filters";
30 +
31 + // ===========================================================
32 + // Fields
33 + // ===========================================================
34 +
35 + private JSONObject mFilters = new JSONObject();
36 + private long mCacheUpdateInterval = 0;
37 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
38 +
39 + // ===========================================================
40 + // Constructor
41 + // ===========================================================
42 +
43 + /**
44 + * Default constructor of WarplyGetCampaignsRequest, initializes an empty filters HashMap
45 + */
46 + public WarplyGetCampaignsRequest() {
47 + mFilters = new JSONObject();
48 + }
49 +
50 + public WarplyGetCampaignsRequest(WarplyGetCampaignsRequest copy) {
51 + if (copy != null) {
52 + this.mFilters = copy.mFilters;
53 + this.mCacheUpdateInterval = copy.mCacheUpdateInterval;
54 + }
55 + }
56 +
57 + // ===========================================================
58 + // Methods for/from SuperClass/Interfaces
59 + // ===========================================================
60 +
61 + @Override
62 + public boolean equals(Object object) {
63 + if (object instanceof WarplyGetCampaignsRequest) {
64 + WarplyGetCampaignsRequest other = (WarplyGetCampaignsRequest) object;
65 + return other == this || (this.mFilters == other.mFilters || (this.mFilters != null && this.mFilters.equals(other.mFilters)));
66 + }
67 + return false;
68 + }
69 +
70 + @Override
71 + public int hashCode() {
72 + return mFilters.hashCode();
73 + }
74 +
75 + // ===========================================================
76 + // Methods
77 + // ===========================================================
78 +
79 + // ===========================================================
80 + // Getter & Setter
81 + // ===========================================================
82 +
83 + public WarplyGetCampaignsRequest setLanguage(String language) {
84 + mLanguage = language;
85 + return this;
86 + }
87 +
88 + public WarplyGetCampaignsRequest setFilters(JSONObject filters) {
89 + mFilters = filters;
90 + return this;
91 + }
92 +
93 + /**
94 + * Call this to get how often the cached data will be updated.
95 + *
96 + * @return mCacheUpdateInterval
97 + */
98 + public long getCacheUpdateInterval() {
99 + return mCacheUpdateInterval;
100 + }
101 +
102 + /**
103 + * Call this to set how often the cached data will be updated.
104 + *
105 + * @param updateInterval The time that data will be cached
106 + * @return WarplyGetCampaignsRequest
107 + */
108 + public WarplyGetCampaignsRequest setCacheUpdateInterval(long updateInterval) {
109 +
110 + this.mCacheUpdateInterval = updateInterval;
111 + if (mCacheUpdateInterval < 0) {
112 + mCacheUpdateInterval = 0;
113 + }
114 + return this;
115 + }
116 +
117 + /**
118 + * Call this to check if the Application uses Cache
119 + *
120 + * @return <p>true - the Application is using Cache</p>
121 + * <p>false - the Application is not using Cache</p>
122 + */
123 + public boolean isUseCache() {
124 + return mCacheUpdateInterval > 0;
125 + }
126 +
127 + /**
128 + * Call this to check whether the cached data need to be updated
129 + *
130 + * @param useCache <p>true - the Application is using Cache</p>
131 + * <p>false - the Application is not using Cache</p>
132 + * @return WarplyGetCampaignsRequest
133 + */
134 + public WarplyGetCampaignsRequest setUseCache(boolean useCache) {
135 +
136 + if (useCache) {
137 + mCacheUpdateInterval = mCacheUpdateInterval > 0 ? mCacheUpdateInterval
138 + : WarpConstants.INBOX_UPDATE_INTERVAL;
139 + } else {
140 + mCacheUpdateInterval = 0;
141 + }
142 + return this;
143 + }
144 +
145 + /**
146 + * Call this to build the campaigns Json object
147 + *
148 + * @return bodyJsonObject
149 + */
150 + public JSONObject toJson() {
151 + JSONObject bodyJsonObject = new JSONObject();
152 + try {
153 + bodyJsonObject.putOpt(KEY_ACTION, KEY_ACTION_VALUE);
154 + bodyJsonObject.putOpt(KEY_LANGUAGE, mLanguage);
155 + if (mFilters != null && mFilters.length() > 0)
156 + bodyJsonObject.putOpt(KEY_FILTERS, mFilters);
157 + else
158 + bodyJsonObject.putOpt(KEY_FILTERS, new JSONObject());
159 + } catch (JSONException e) {
160 + if (WarpConstants.DEBUG)
161 + e.printStackTrace();
162 + }
163 + return bodyJsonObject;
164 + }
165 +
166 + public String getSignature() {
167 + String signature = mFilters != null && mFilters.length() > 0 ? String.valueOf(mFilters.hashCode()) : "default_get_campaigns_request";
168 + try {
169 + byte[] hash = MessageDigest.getInstance("SHA-256").digest(signature.getBytes("UTF-8"));
170 + signature = Base64.encodeToString(hash, Base64.NO_WRAP);
171 + } catch (NullPointerException | NoSuchAlgorithmException
172 + | UnsupportedEncodingException e) {
173 + e.printStackTrace();
174 + }
175 + return signature;
176 + }
177 +}
...@@ -12,6 +12,8 @@ import java.security.NoSuchAlgorithmException; ...@@ -12,6 +12,8 @@ import java.security.NoSuchAlgorithmException;
12 import java.util.ArrayList; 12 import java.util.ArrayList;
13 import java.util.HashMap; 13 import java.util.HashMap;
14 14
15 +import ly.warp.sdk.Warply;
16 +import ly.warp.sdk.utils.WarplyProperty;
15 import ly.warp.sdk.utils.constants.WarpConstants; 17 import ly.warp.sdk.utils.constants.WarpConstants;
16 18
17 /** 19 /**
...@@ -40,7 +42,7 @@ public class WarplyGetCouponsetsRequest { ...@@ -40,7 +42,7 @@ public class WarplyGetCouponsetsRequest {
40 private boolean mActive = true; 42 private boolean mActive = true;
41 private boolean mVisible = true; 43 private boolean mVisible = true;
42 private ArrayList<String> mUuids = new ArrayList<>(); 44 private ArrayList<String> mUuids = new ArrayList<>();
43 - private String mLanguage = ""; 45 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
44 46
45 // =========================================================== 47 // ===========================================================
46 // Constructor 48 // Constructor
......
...@@ -10,6 +10,8 @@ import java.security.MessageDigest; ...@@ -10,6 +10,8 @@ import java.security.MessageDigest;
10 import java.security.NoSuchAlgorithmException; 10 import java.security.NoSuchAlgorithmException;
11 import java.util.HashMap; 11 import java.util.HashMap;
12 12
13 +import ly.warp.sdk.Warply;
14 +import ly.warp.sdk.utils.WarplyProperty;
13 import ly.warp.sdk.utils.constants.WarpConstants; 15 import ly.warp.sdk.utils.constants.WarpConstants;
14 16
15 /** 17 /**
...@@ -32,7 +34,7 @@ public class WarplyMerchantCategoriesRequest { ...@@ -32,7 +34,7 @@ public class WarplyMerchantCategoriesRequest {
32 34
33 private HashMap<String, String> mFilters; 35 private HashMap<String, String> mFilters;
34 private long mCacheUpdateInterval = 0; 36 private long mCacheUpdateInterval = 0;
35 - private String mLanguage = ""; 37 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
36 38
37 // =========================================================== 39 // ===========================================================
38 // Constructor 40 // Constructor
......
...@@ -13,6 +13,8 @@ import java.security.NoSuchAlgorithmException; ...@@ -13,6 +13,8 @@ import java.security.NoSuchAlgorithmException;
13 import java.util.ArrayList; 13 import java.util.ArrayList;
14 import java.util.HashMap; 14 import java.util.HashMap;
15 15
16 +import ly.warp.sdk.Warply;
17 +import ly.warp.sdk.utils.WarplyProperty;
16 import ly.warp.sdk.utils.constants.WarpConstants; 18 import ly.warp.sdk.utils.constants.WarpConstants;
17 19
18 /** 20 /**
...@@ -51,7 +53,7 @@ public class WarplyMerchantsRequest { ...@@ -51,7 +53,7 @@ public class WarplyMerchantsRequest {
51 private String mUuid = ""; 53 private String mUuid = "";
52 private int mDistance = 0; 54 private int mDistance = 0;
53 private ArrayList<Double> mCenter = new ArrayList<>(); 55 private ArrayList<Double> mCenter = new ArrayList<>();
54 - private String mLanguage = ""; 56 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
55 57
56 // =========================================================== 58 // ===========================================================
57 // Constructor 59 // Constructor
......
...@@ -39,7 +39,7 @@ public class WarplyProductsRequest { ...@@ -39,7 +39,7 @@ public class WarplyProductsRequest {
39 private HashMap<String, String> mFilters; 39 private HashMap<String, String> mFilters;
40 private long mCacheUpdateInterval = 0; 40 private long mCacheUpdateInterval = 0;
41 private String mProductsCategory = ""; 41 private String mProductsCategory = "";
42 - private String mLanguage = ""; 42 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
43 43
44 // =========================================================== 44 // ===========================================================
45 // Constructor 45 // Constructor
......
...@@ -10,6 +10,8 @@ import java.security.MessageDigest; ...@@ -10,6 +10,8 @@ import java.security.MessageDigest;
10 import java.security.NoSuchAlgorithmException; 10 import java.security.NoSuchAlgorithmException;
11 import java.util.HashMap; 11 import java.util.HashMap;
12 12
13 +import ly.warp.sdk.Warply;
14 +import ly.warp.sdk.utils.WarplyProperty;
13 import ly.warp.sdk.utils.constants.WarpConstants; 15 import ly.warp.sdk.utils.constants.WarpConstants;
14 16
15 /** 17 /**
...@@ -33,7 +35,7 @@ public class WarplyTagsCategoriesRequest { ...@@ -33,7 +35,7 @@ public class WarplyTagsCategoriesRequest {
33 35
34 private HashMap<String, String> mFilters; 36 private HashMap<String, String> mFilters;
35 private long mCacheUpdateInterval = 0; 37 private long mCacheUpdateInterval = 0;
36 - private String mLanguage = ""; 38 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
37 39
38 // =========================================================== 40 // ===========================================================
39 // Constructor 41 // Constructor
......
...@@ -10,6 +10,8 @@ import java.security.MessageDigest; ...@@ -10,6 +10,8 @@ import java.security.MessageDigest;
10 import java.security.NoSuchAlgorithmException; 10 import java.security.NoSuchAlgorithmException;
11 import java.util.HashMap; 11 import java.util.HashMap;
12 12
13 +import ly.warp.sdk.Warply;
14 +import ly.warp.sdk.utils.WarplyProperty;
13 import ly.warp.sdk.utils.constants.WarpConstants; 15 import ly.warp.sdk.utils.constants.WarpConstants;
14 16
15 /** 17 /**
...@@ -33,7 +35,7 @@ public class WarplyTagsRequest { ...@@ -33,7 +35,7 @@ public class WarplyTagsRequest {
33 35
34 private HashMap<String, String> mFilters; 36 private HashMap<String, String> mFilters;
35 private long mCacheUpdateInterval = 0; 37 private long mCacheUpdateInterval = 0;
36 - private String mLanguage = ""; 38 + private String mLanguage = WarplyProperty.getLanguage(Warply.getWarplyContext());
37 39
38 // =========================================================== 40 // ===========================================================
39 // Constructor 41 // Constructor
......
...@@ -30,7 +30,7 @@ public class WarpConstants { ...@@ -30,7 +30,7 @@ public class WarpConstants {
30 /** 30 /**
31 * The version of the SDK installed in the device 31 * The version of the SDK installed in the device
32 */ 32 */
33 - public static final String SDK_VERSION = "4.5.4.2"; 33 + public static final String SDK_VERSION = "4.5.4.3";
34 34
35 /** 35 /**
36 * The URL of the server where it should ping 36 * The URL of the server where it should ping
...@@ -126,6 +126,7 @@ public class WarpConstants { ...@@ -126,6 +126,7 @@ public class WarpConstants {
126 public static final String MICROAPP_CONTACT = "contact"; 126 public static final String MICROAPP_CONTACT = "contact";
127 public static final String MICROAPP_CARDS = "cards"; 127 public static final String MICROAPP_CARDS = "cards";
128 public static final String MICROAPP_COUPONS = "coupon"; 128 public static final String MICROAPP_COUPONS = "coupon";
129 + public static final String MICROAPP_NEW_CAMPAIGNS = "campaigns";
129 public static final String MICROAPP_TRANSACTIONS = "transactions"; 130 public static final String MICROAPP_TRANSACTIONS = "transactions";
130 public static final String MICROAPP_CONTENT = "content"; 131 public static final String MICROAPP_CONTENT = "content";
131 public static final String MICROAPP_APPLICATION_DATA = "application_data"; 132 public static final String MICROAPP_APPLICATION_DATA = "application_data";
......
...@@ -39,6 +39,7 @@ import ly.warp.sdk.io.callbacks.CouponsHook; ...@@ -39,6 +39,7 @@ import ly.warp.sdk.io.callbacks.CouponsHook;
39 import ly.warp.sdk.io.callbacks.CouponsetsHook; 39 import ly.warp.sdk.io.callbacks.CouponsetsHook;
40 import ly.warp.sdk.io.callbacks.MerchantCategoriesHook; 40 import ly.warp.sdk.io.callbacks.MerchantCategoriesHook;
41 import ly.warp.sdk.io.callbacks.MerchantsHook; 41 import ly.warp.sdk.io.callbacks.MerchantsHook;
42 +import ly.warp.sdk.io.callbacks.NewCampaignsHook;
42 import ly.warp.sdk.io.callbacks.PointsHook; 43 import ly.warp.sdk.io.callbacks.PointsHook;
43 import ly.warp.sdk.io.callbacks.ProductsHook; 44 import ly.warp.sdk.io.callbacks.ProductsHook;
44 import ly.warp.sdk.io.callbacks.TagsCategoriesHook; 45 import ly.warp.sdk.io.callbacks.TagsCategoriesHook;
...@@ -53,6 +54,7 @@ import ly.warp.sdk.io.models.CouponList; ...@@ -53,6 +54,7 @@ import ly.warp.sdk.io.models.CouponList;
53 import ly.warp.sdk.io.models.CouponsetsList; 54 import ly.warp.sdk.io.models.CouponsetsList;
54 import ly.warp.sdk.io.models.MerchantCategoriesList; 55 import ly.warp.sdk.io.models.MerchantCategoriesList;
55 import ly.warp.sdk.io.models.MerchantList; 56 import ly.warp.sdk.io.models.MerchantList;
57 +import ly.warp.sdk.io.models.NewCampaignList;
56 import ly.warp.sdk.io.models.PointsList; 58 import ly.warp.sdk.io.models.PointsList;
57 import ly.warp.sdk.io.models.ProductList; 59 import ly.warp.sdk.io.models.ProductList;
58 import ly.warp.sdk.io.models.TagsCategoriesList; 60 import ly.warp.sdk.io.models.TagsCategoriesList;
...@@ -71,6 +73,7 @@ import ly.warp.sdk.io.request.WarplyEditAddressRequest; ...@@ -71,6 +73,7 @@ import ly.warp.sdk.io.request.WarplyEditAddressRequest;
71 import ly.warp.sdk.io.request.WarplyEditConsumerRequest; 73 import ly.warp.sdk.io.request.WarplyEditConsumerRequest;
72 import ly.warp.sdk.io.request.WarplyForgotPasswordRequest; 74 import ly.warp.sdk.io.request.WarplyForgotPasswordRequest;
73 import ly.warp.sdk.io.request.WarplyGetAddressRequest; 75 import ly.warp.sdk.io.request.WarplyGetAddressRequest;
76 +import ly.warp.sdk.io.request.WarplyGetCampaignsRequest;
74 import ly.warp.sdk.io.request.WarplyGetCardsRequest; 77 import ly.warp.sdk.io.request.WarplyGetCardsRequest;
75 import ly.warp.sdk.io.request.WarplyGetCouponsetsRequest; 78 import ly.warp.sdk.io.request.WarplyGetCouponsetsRequest;
76 import ly.warp.sdk.io.request.WarplyLoginRequest; 79 import ly.warp.sdk.io.request.WarplyLoginRequest;
...@@ -1267,4 +1270,43 @@ public class WarplyManager { ...@@ -1267,4 +1270,43 @@ public class WarplyManager {
1267 } 1270 }
1268 }); 1271 });
1269 } 1272 }
1273 +
1274 + public static void getCampaigns(WarplyGetCampaignsRequest request, boolean auth, final CallbackReceiver<NewCampaignList> receiver) {
1275 + WarpUtils.log("************* WARPLY Get Campaigns Request ********************");
1276 + WarpUtils.log("[WARP Trace] WARPLY Get Campaigns Request is active");
1277 + WarpUtils.log("**************************************************");
1278 +
1279 + Warply.postReceiveMicroappData(WarpConstants.MICROAPP_NEW_CAMPAIGNS, auth, "campaigns", request.toJson(), new NewCampaignsHook(new CallbackReceiver<NewCampaignList>() {
1280 + @Override
1281 + public void onSuccess(NewCampaignList result) {
1282 + receiver.onSuccess(result);
1283 + }
1284 +
1285 + @Override
1286 + public void onFailure(int errorCode) {
1287 + if (auth) {
1288 + if (errorCode == 401) {
1289 + refreshToken(new WarplyRefreshTokenRequest(), new CallbackReceiver<JSONObject>() {
1290 + @Override
1291 + public void onSuccess(JSONObject result) {
1292 + int status = result.optInt("status", 2);
1293 + if (status == 1)
1294 + getCampaigns(request, auth, receiver);
1295 + else
1296 + receiver.onFailure(status);
1297 + }
1298 +
1299 + @Override
1300 + public void onFailure(int errorCode) {
1301 + receiver.onFailure(errorCode);
1302 + }
1303 + });
1304 + } else
1305 + receiver.onFailure(errorCode);
1306 + } else
1307 + receiver.onFailure(errorCode);
1308 + }
1309 + },
1310 + request.getSignature()));
1311 + }
1270 } 1312 }
......