Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_android_sdk_maven_plugin
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Panagiotis Triantafyllou
2024-02-28 20:20:48 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f37ddd9de300d2500e3a19df5b3540146b3676b7
f37ddd9d
1 parent
9593c4f7
added campaigns availability request
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
14 deletions
warply_android_sdk/src/main/java/ly/warp/sdk/io/volley/ApiService.java
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
warply_android_sdk/src/main/java/ly/warp/sdk/io/volley/ApiService.java
View file @
f37ddd9
...
...
@@ -100,6 +100,17 @@ public interface ApiService {
@Header
(
WarpConstants
.
HEADER_SIGNATURE
)
String
signature
);
@Headers
(
"Content-Type: application/json"
)
@POST
(
"/api/mobile/v2/{appUuid}/context/"
)
Call
<
ResponseBody
>
getCampaignsAvailability
(
@Path
(
"appUuid"
)
String
appUuid
,
@Body
RequestBody
request
,
@Header
(
WarpConstants
.
HEADER_DATE
)
String
timeStamp
,
@Header
(
WarpConstants
.
HEADER_LOYALTY_BUNDLE_ID
)
String
bundleId
,
@Header
(
WarpConstants
.
HEADER_UNIQUE_DEVICE_ID
)
String
deviceId
,
@Header
(
WarpConstants
.
HEADER_CHANNEL
)
String
channel
,
@Header
(
WarpConstants
.
HEADER_WEB_ID
)
String
webId
,
@Header
(
WarpConstants
.
HEADER_SIGNATURE
)
String
signature
);
@Headers
(
"Content-Type: application/json"
)
@POST
(
"/oauth/{appUuid}/context"
)
Call
<
ResponseBody
>
getCampaignsPersonalized
(
@Path
(
"appUuid"
)
String
appUuid
,
@Body
RequestBody
request
,
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
View file @
f37ddd9
...
...
@@ -1565,7 +1565,7 @@ public class WarplyManager {
request
.
getSignature
()));
}
private
static
ArrayList
<
Campaign
>
mergeCampaignResults
(
ArrayList
<
Campaign
>
resultCampaigns
,
ArrayList
<
Campaign
>
resultPersonalizedCampaigns
)
{
private
static
ArrayList
<
Campaign
>
mergeCampaignResults
(
ArrayList
<
Campaign
>
resultCampaigns
,
ArrayList
<
Campaign
>
resultPersonalizedCampaigns
,
JSONObject
resultCampaignsAvailability
)
{
ArrayList
<
Campaign
>
newCampaignList
=
new
ArrayList
<
Campaign
>();
ArrayList
<
Campaign
>
campaignLoyaltyList
=
new
ArrayList
<>();
newCampaignList
.
clear
();
...
...
@@ -1619,14 +1619,16 @@ public class WarplyManager {
ListenableFuture
<
ArrayList
<
Campaign
>>
futureCampaigns
=
getCampaignsRetro
(
service
);
ListenableFuture
<
ArrayList
<
Campaign
>>
futurePersonalizedCampaigns
=
getCampaignsPersonalizedRetro
(
service
);
ListenableFuture
<
JSONObject
>
futureCampaignAvailability
=
getCampaignAvailability
(
service
);
ListenableFuture
<
List
<
ArrayList
<
Campaign
>>>
allResultsFuture
=
Futures
.
allAsList
(
futureCampaigns
,
futurePersonalizedCampaigns
);
ListenableFuture
<
List
<
Object
>>
allResultsFuture
=
Futures
.
allAsList
(
futureCampaigns
,
futurePersonalizedCampaigns
,
futureCampaignAvailability
);
ListenableFuture
<
ArrayList
<
Campaign
>>
mergedResultFuture
=
Futures
.
transformAsync
(
allResultsFuture
,
results
->
{
ArrayList
<
Campaign
>
resultCampaigns
=
results
.
get
(
0
);
ArrayList
<
Campaign
>
resultPersonalizedCampaigns
=
results
.
get
(
1
);
return
executorService
.
submit
(()
->
mergeCampaignResults
(
resultCampaigns
,
resultPersonalizedCampaigns
));
ArrayList
<
Campaign
>
resultCampaigns
=
(
ArrayList
<
Campaign
>)
results
.
get
(
0
);
ArrayList
<
Campaign
>
resultPersonalizedCampaigns
=
(
ArrayList
<
Campaign
>)
results
.
get
(
1
);
JSONObject
resultCampaignsAvailability
=
(
JSONObject
)
results
.
get
(
2
);
return
executorService
.
submit
(()
->
mergeCampaignResults
(
resultCampaigns
,
resultPersonalizedCampaigns
,
resultCampaignsAvailability
));
},
executorService
);
...
...
@@ -1650,8 +1652,8 @@ public class WarplyManager {
// getCampaignsPersonalizedRetro(service, new CallbackReceiver<ArrayList<Campaign>>() {
// @Override
// public void onSuccess(ArrayList<Campaign> resultPersonalized) {
// final ExecutorService executor
Shop
s = Executors.newFixedThreadPool(1);
// executor
Shop
s.submit(() -> {
// final ExecutorService executor
Campaign
s = Executors.newFixedThreadPool(1);
// executor
Campaign
s.submit(() -> {
// ArrayList<Campaign> newCampaignList = new ArrayList<Campaign>();
// newCampaignList.clear();
// newCampaignList.addAll(result);
...
...
@@ -1686,7 +1688,7 @@ public class WarplyManager {
// Set<Campaign> set = new LinkedHashSet<>(campaignLoyaltyList);
// campaignLoyaltyList.clear();
// campaignLoyaltyList.addAll(set);
// executor
Shop
s.shutdownNow();
// executor
Campaign
s.shutdownNow();
// new Handler(Looper.getMainLooper()).post(() -> receiver.onSuccess(campaignLoyaltyList));//resultPersonalized
// });
// }
...
...
@@ -1759,9 +1761,9 @@ public class WarplyManager {
ArrayList
<
NewCampaign
>
tempCampaigns
=
new
ArrayList
<>();
ArrayList
<
Campaign
>
mCampaignsList
=
new
ArrayList
<>();
final
ExecutorService
executor
Shop
s
=
Executors
.
newFixedThreadPool
(
1
);
final
ExecutorService
executor
Campaign
s
=
Executors
.
newFixedThreadPool
(
1
);
JSONArray
finalCampaignsJBody
=
jCampaignsBody
;
executor
Shop
s
.
submit
(()
->
{
executor
Campaign
s
.
submit
(()
->
{
for
(
int
i
=
0
;
i
<
finalCampaignsJBody
.
length
();
++
i
)
{
tempCampaigns
.
add
(
new
NewCampaign
(
finalCampaignsJBody
.
optJSONObject
(
i
)));
}
...
...
@@ -1809,7 +1811,7 @@ public class WarplyManager {
mCampaignsList
.
add
(
camp
);
}
executor
Shop
s
.
shutdownNow
();
executor
Campaign
s
.
shutdownNow
();
// receiver.onSuccess(mCampaignsList);
future
.
set
(
mCampaignsList
);
});
...
...
@@ -1853,6 +1855,7 @@ public class WarplyManager {
Map
<
String
,
Object
>
jsonParamsCampaigns
=
new
ArrayMap
<>();
Map
<
String
,
Object
>
jsonParams
=
new
ArrayMap
<>();
jsonParams
.
put
(
"action"
,
"retrieve"
);
jsonParams
.
put
(
"filters"
,
new
JSONObject
());
jsonParams
.
put
(
"language"
,
WarplyProperty
.
getLanguage
(
Warply
.
getWarplyContext
()));
jsonParamsCampaigns
.
put
(
"campaigns"
,
jsonParams
);
...
...
@@ -1897,9 +1900,9 @@ public class WarplyManager {
ArrayList
<
NewCampaign
>
tempCampaigns
=
new
ArrayList
<>();
ArrayList
<
Campaign
>
mCampaignsList
=
new
ArrayList
<>();
final
ExecutorService
executor
Shop
s
=
Executors
.
newFixedThreadPool
(
1
);
final
ExecutorService
executor
PersonalizedCampaign
s
=
Executors
.
newFixedThreadPool
(
1
);
JSONArray
finalCampaignsJBody
=
jCampaignsBody
;
executor
Shop
s
.
submit
(()
->
{
executor
PersonalizedCampaign
s
.
submit
(()
->
{
for
(
int
i
=
0
;
i
<
finalCampaignsJBody
.
length
();
++
i
)
{
tempCampaigns
.
add
(
new
NewCampaign
(
finalCampaignsJBody
.
optJSONObject
(
i
)));
}
...
...
@@ -1947,7 +1950,7 @@ public class WarplyManager {
mCampaignsList
.
add
(
camp
);
}
executor
Shop
s
.
shutdownNow
();
executor
PersonalizedCampaign
s
.
shutdownNow
();
// receiver.onSuccess(mCampaignsList);
future
.
set
(
mCampaignsList
);
});
...
...
@@ -2000,6 +2003,93 @@ public class WarplyManager {
return
future
;
}
private
static
ListenableFuture
<
JSONObject
>
getCampaignAvailability
(
ApiService
service
)
{
SettableFuture
<
JSONObject
>
future
=
SettableFuture
.
create
();
String
timeStamp
=
DateFormat
.
format
(
"yyyy-MM-dd hh:mm:ss"
,
System
.
currentTimeMillis
()).
toString
();
String
apiKey
=
WarpUtils
.
getApiKey
(
Warply
.
getWarplyContext
());
String
webId
=
WarpUtils
.
getWebId
(
Warply
.
getWarplyContext
());
Map
<
String
,
Object
>
jsonParamsCampaignsAvailability
=
new
ArrayMap
<>();
Map
<
String
,
Object
>
jsonParams
=
new
ArrayMap
<>();
jsonParams
.
put
(
"action"
,
"availability"
);
Map
<
String
,
Object
>
jsonParamsFilters
=
new
ArrayMap
<>();
jsonParams
.
put
(
"uuids"
,
null
);
jsonParams
.
put
(
"availability_enabled"
,
true
);
jsonParams
.
put
(
"filters"
,
jsonParamsFilters
);
jsonParams
.
put
(
"language"
,
WarplyProperty
.
getLanguage
(
Warply
.
getWarplyContext
()));
jsonParamsCampaignsAvailability
.
put
(
"coupon"
,
jsonParams
);
RequestBody
campaignsAvailabilityRequest
=
RequestBody
.
create
(
MediaType
.
get
(
"application/json; charset=utf-8"
),
(
new
JSONObject
(
jsonParamsCampaignsAvailability
)).
toString
());
Call
<
ResponseBody
>
campaignsAvailabilityCall
=
service
.
getCampaignsAvailability
(
WarplyProperty
.
getAppUuid
(
Warply
.
getWarplyContext
()),
campaignsAvailabilityRequest
,
timeStamp
,
"android:"
+
Warply
.
getWarplyContext
().
getPackageName
(),
new
WarplyDeviceInfoCollector
(
Warply
.
getWarplyContext
()).
getUniqueDeviceId
(),
"mobile"
,
webId
,
WarpUtils
.
produceSignature
(
apiKey
+
timeStamp
)
);
campaignsAvailabilityCall
.
enqueue
(
new
Callback
<
ResponseBody
>()
{
@Override
public
void
onResponse
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Response
<
ResponseBody
>
response
)
{
if
(
response
.
code
()
==
200
&&
response
.
body
()
!=
null
)
{
JSONObject
jobjCampaignsAvailabilityResponse
=
null
;
try
{
jobjCampaignsAvailabilityResponse
=
new
JSONObject
(
response
.
body
().
string
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jobjCampaignsAvailabilityResponse
!=
null
&&
jobjCampaignsAvailabilityResponse
.
has
(
"status"
)
&&
jobjCampaignsAvailabilityResponse
.
optString
(
"status"
,
"2"
).
equals
(
"1"
))
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_success_available_coupons"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
final
ExecutorService
executorCampaignsAvailability
=
Executors
.
newFixedThreadPool
(
1
);
final
JSONObject
finalJobjCampaignsAvailabilityResponse
=
jobjCampaignsAvailabilityResponse
;
executorCampaignsAvailability
.
submit
(()
->
{
JSONObject
jCampaignsAvailabilityBody
=
null
;
try
{
jCampaignsAvailabilityBody
=
finalJobjCampaignsAvailabilityResponse
.
optJSONObject
(
"context"
).
optJSONObject
(
"MAPP_COUPON"
).
optJSONObject
(
"availability"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
jCampaignsAvailabilityBody
!=
null
)
{
executorCampaignsAvailability
.
shutdownNow
();
future
.
set
(
jCampaignsAvailabilityBody
);
}
});
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_available_coupons"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
JSONObject
());
}
}
else
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_available_coupons"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
JSONObject
());
}
}
@Override
public
void
onFailure
(
@NonNull
Call
<
ResponseBody
>
call
,
@NonNull
Throwable
t
)
{
LoyaltySDKDynatraceEventModel
dynatraceEvent
=
new
LoyaltySDKDynatraceEventModel
();
dynatraceEvent
.
setEventName
(
"custom_error_available_coupons"
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
dynatraceEvent
));
future
.
set
(
new
JSONObject
());
}
});
return
future
;
}
public
static
void
getCampaignsPersonalized
(
WarplyGetCampaignsRequest
request
,
final
CallbackReceiver
<
ArrayList
<
Campaign
>>
receiver
)
{
WarpUtils
.
log
(
"************* WARPLY Get Campaigns Request ********************"
);
WarpUtils
.
log
(
"[WARP Trace] WARPLY Get Campaigns Request is active"
);
...
...
Please
register
or
login
to post a comment