Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2025-07-17 12:34:49 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dd6c3007b10cc2e2fc46eab30eb7419a206051c1
dd6c3007
1 parent
78d0e795
optional language parameter added to requests, fixed getCouponSets, getCouponsUniversal
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
19 deletions
NETWORK_TESTING_AUTHORIZATION.md
SwiftWarplyFramework/SwiftWarplyFramework/Core/WarplySDK.swift
SwiftWarplyFramework/SwiftWarplyFramework/Network/Endpoints.swift
NETWORK_TESTING_AUTHORIZATION.md
View file @
dd6c300
This diff is collapsed. Click to expand it.
SwiftWarplyFramework/SwiftWarplyFramework/Core/WarplySDK.swift
View file @
dd6c300
...
...
@@ -1582,10 +1582,13 @@ public final class WarplySDK {
// MARK: - Campaigns
/// Get campaigns with filters
public
func
getCampaigns
(
language
:
String
,
filters
:
[
String
:
Any
]
=
[:],
completion
:
@escaping
([
CampaignItemModel
]?)
->
Void
,
failureCallback
:
@escaping
(
Int
)
->
Void
)
{
public
func
getCampaigns
(
language
:
String
?
=
nil
,
filters
:
[
String
:
Any
]
=
[:],
completion
:
@escaping
([
CampaignItemModel
]?)
->
Void
,
failureCallback
:
@escaping
(
Int
)
->
Void
)
{
// Handle language default inside the method
let
finalLanguage
=
language
??
self
.
applicationLocale
Task
{
do
{
let
endpoint
=
Endpoint
.
getCampaigns
(
language
:
l
anguage
,
filters
:
filters
)
let
endpoint
=
Endpoint
.
getCampaigns
(
language
:
finalL
anguage
,
filters
:
filters
)
let
response
=
try
await
networkService
.
requestRaw
(
endpoint
)
var
campaignsArray
:
[
CampaignItemModel
]
=
[]
...
...
@@ -1687,10 +1690,13 @@ public final class WarplySDK {
}
/// Get personalized campaigns
public
func
getCampaignsPersonalized
(
language
:
String
,
filters
:
[
String
:
Any
]
=
[:],
completion
:
@escaping
([
CampaignItemModel
]?)
->
Void
,
failureCallback
:
@escaping
(
Int
)
->
Void
)
{
public
func
getCampaignsPersonalized
(
language
:
String
?
=
nil
,
filters
:
[
String
:
Any
]
=
[:],
completion
:
@escaping
([
CampaignItemModel
]?)
->
Void
,
failureCallback
:
@escaping
(
Int
)
->
Void
)
{
// Handle language default inside the method
let
finalLanguage
=
language
??
self
.
applicationLocale
Task
{
do
{
let
endpoint
=
Endpoint
.
getCampaignsPersonalized
(
language
:
l
anguage
,
filters
:
filters
)
let
endpoint
=
Endpoint
.
getCampaignsPersonalized
(
language
:
finalL
anguage
,
filters
:
filters
)
let
response
=
try
await
networkService
.
requestRaw
(
endpoint
)
var
campaignsArray
:
[
CampaignItemModel
]
=
[]
...
...
@@ -1913,7 +1919,9 @@ public final class WarplySDK {
// MARK: - Coupons
/// Get coupons
public
func
getCoupons
(
language
:
String
,
completion
:
@escaping
([
CouponItemModel
]?)
->
Void
,
failureCallback
:
@escaping
(
Int
)
->
Void
)
{
public
func
getCoupons
(
language
:
String
?
=
nil
,
completion
:
@escaping
([
CouponItemModel
]?)
->
Void
,
failureCallback
:
@escaping
(
Int
)
->
Void
)
{
// Handle language default inside the method
let
finalLanguage
=
language
??
self
.
applicationLocale
// First get merchants
// getMultilingualMerchants(categories: [], defaultShown: false, center: 0.0, tags: [], uuid: "", distance: 0, parentUuids: []) { merchantsData in
// if let merchantsData = merchantsData {
...
...
@@ -1963,12 +1971,17 @@ public final class WarplySDK {
self
.
setAllOldCouponList
(
couponsArray
)
// Filter out supermarket coupons
let
noSMCoupons
=
couponsArray
.
filter
{
$0
.
couponset_data
?
.
couponset_type
!=
"supermarket"
}
// let noSMCoupons = couponsArray.filter { $0.couponset_data?.couponset_type != "supermarket" }
// self.setCouponList(noSMCoupons)
// self.setOldCouponList(noSMCoupons)
// var activeCoupons = noSMCoupons.filter { $0.status == 1 }
self
.
setCouponList
(
noSMCoupons
)
self
.
setOldCouponList
(
noSMCoupons
)
self
.
setCouponList
(
couponsArray
)
self
.
setOldCouponList
(
couponsArray
)
var
activeCoupons
=
noSMCoupons
.
filter
{
$0
.
status
==
1
}
var
activeCoupons
=
couponsArray
.
filter
{
$0
.
status
==
1
}
// Sort active coupons by expiration date
let
dateFormatter
=
DateFormatter
()
...
...
@@ -2013,10 +2026,17 @@ public final class WarplySDK {
}
/// Get coupon sets
public
func
getCouponSets
(
completion
:
@escaping
([
CouponSetItemModel
]?)
->
Void
)
{
public
func
getCouponSets
(
language
:
String
?
=
nil
,
completion
:
@escaping
([
CouponSetItemModel
]?)
->
Void
,
failureCallback
:
@escaping
(
Int
)
->
Void
)
{
// Handle language default inside the method
let
finalLanguage
=
language
??
self
.
applicationLocale
Task
{
do
{
let
endpoint
=
Endpoint
.
getCouponSets
(
active
:
true
,
visible
:
true
,
uuids
:
nil
)
let
endpoint
=
Endpoint
.
getCouponSets
(
language
:
finalLanguage
,
active
:
true
,
visible
:
true
,
uuids
:
nil
)
let
response
=
try
await
networkService
.
requestRaw
(
endpoint
)
var
couponSetsArray
:
[
CouponSetItemModel
]
=
[]
...
...
@@ -2044,9 +2064,13 @@ public final class WarplySDK {
let
dynatraceEvent
=
LoyaltySDKDynatraceEventModel
()
dynatraceEvent
.
_eventName
=
"custom_error_couponset_loyalty"
dynatraceEvent
.
_parameters
=
nil
SwiftEventBus
.
pos
t
(
"dynatrace"
,
sender
:
dynatraceEvent
)
self
.
postFrameworkEven
t
(
"dynatrace"
,
sender
:
dynatraceEvent
)
completion
(
nil
)
if
let
networkError
=
error
as?
NetworkError
{
failureCallback
(
networkError
.
code
)
}
else
{
failureCallback
(
-
1
)
}
}
}
}
...
...
@@ -2116,17 +2140,20 @@ public final class WarplySDK {
}
/// Get coupon sets (async/await variant)
/// - Parameter language: Language code for localized content (optional, defaults to applicationLocale)
/// - Returns: Array of coupon set models
/// - Throws: WarplyError if the request fails
public
func
getCouponSets
()
async
throws
->
[
CouponSetItemModel
]
{
public
func
getCouponSets
(
language
:
String
?
=
nil
)
async
throws
->
[
CouponSetItemModel
]
{
return
try
await
withCheckedThrowingContinuation
{
continuation
in
getCouponSets
{
couponSets
in
getCouponSets
(
language
:
language
,
completion
:
{
couponSets
in
if
let
couponSets
=
couponSets
{
continuation
.
resume
(
returning
:
couponSets
)
}
else
{
continuation
.
resume
(
throwing
:
WarplyError
.
networkError
)
}
}
},
failureCallback
:
{
errorCode
in
continuation
.
resume
(
throwing
:
WarplyError
.
unknownError
(
errorCode
))
})
}
}
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Network/Endpoints.swift
View file @
dd6c300
...
...
@@ -65,7 +65,7 @@ public enum Endpoint {
// Coupons
case
getCoupons
(
language
:
String
,
couponsetType
:
String
)
case
getCouponSets
(
active
:
Bool
,
visible
:
Bool
,
uuids
:
[
String
]?)
case
getCouponSets
(
language
:
String
,
active
:
Bool
,
visible
:
Bool
,
uuids
:
[
String
]?)
case
getAvailableCoupons
// Market & Merchants
...
...
@@ -255,12 +255,12 @@ public enum Endpoint {
]
]
case
.
getCouponSets
(
let
active
,
let
visible
,
let
uuids
):
case
.
getCouponSets
(
let
language
,
let
active
,
let
visible
,
let
uuids
):
var
couponParams
:
[
String
:
Any
]
=
[
"action"
:
"retrieve_multilingual"
,
"active"
:
active
,
"visible"
:
visible
,
"language"
:
"LANG"
,
// TODO: Make this configurable
"language"
:
language
,
"exclude"
:
[
[
"field"
:
"couponset_type"
,
...
...
Please
register
or
login
to post a comment