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
2023-04-05 14:19:44 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f3047ebd10d981eed9186c2878f2a27e696d5c16
f3047ebd
1 parent
38e7cff8
add getUnifiedCouponsAsync request
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
239 additions
and
0 deletions
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.h
View file @
f3047eb
...
...
@@ -80,6 +80,7 @@
-
(
NSDictionary
*
)
validateCouponWithCoupon
:(
NSString
*
)
coupon
;
-
(
NSDictionary
*
)
loginCosmoteWithGuid
:(
NSString
*
)
guid
andAppUuid
:(
NSString
*
)
appUuid
andTicket
:(
NSString
*
)
ticket
;
-
(
void
)
getCouponsWithSuccessBlock
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getUnifiedCouponsAsync
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getCouponsetsAsync
:(
NSNumber
*
)
active
andVisible
:
(
NSNumber
*
)
visible
andUuids
:
(
NSArray
*
)
uuids
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getInboxAsync
:(
void
(
^
)(
NSArray
*
list
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
verifyTicketAsync
:(
NSString
*
)
guid
:
(
NSString
*
)
ticket
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
View file @
f3047eb
...
...
@@ -1450,6 +1450,20 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
-
(
void
)
getUnifiedCouponsAsync
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[[
Warply
sharedService
]
getUnifiedCouponsWithSuccessBlock
:
^
(
NSDictionary
*
response
)
{
if
(
success
)
{
success
(
response
);
}
}
failureBlock
:
^
(
NSError
*
error
)
{
if
(
failure
)
{
failure
(
error
);
}
}];
}
-
(
void
)
getCouponsetsAsync
:
(
NSNumber
*
)
active
andVisible
:
(
NSNumber
*
)
visible
andUuids
:
(
NSArray
*
)
uuids
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[[
Warply
sharedService
]
getCouponSetsWithSuccessBlock
:
active
andVisible
:
visible
andUuids
:
uuids
:^
(
NSDictionary
*
response
)
{
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
View file @
f3047eb
...
...
@@ -369,6 +369,8 @@ WL_VERSION_INTERFACE()
-
(
void
)
getCouponsWithSuccessBlock
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getUnifiedCouponsWithSuccessBlock
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getTransactionHistoryWithSuccessBlock
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getPointsHistoryWithSuccessBlock
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
View file @
f3047eb
...
...
@@ -2566,6 +2566,64 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
-
(
void
)
getUnifiedCouponsWithSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
NSMutableDictionary
*
data
=
[[
NSMutableDictionary
alloc
]
init
];
[
data
setValue
:
@"retrieve_unified_coupons"
forKey
:
@"action"
];
[
data
setValue
:
LANG
forKey
:
@"language"
];
NSMutableDictionary
*
postDictionary
=
[[
NSMutableDictionary
alloc
]
init
];
[
postDictionary
setValue
:
data
forKey
:
@"coupon"
];
// NSDictionary *postDictionary = @{@"coupon":@{@"action": @"get_user_coupons", @"fetch_data": @[@"transaction",@"communication"]}};
NSData
*
jsonData
=
[
NSJSONSerialization
dataWithJSONObject
:
postDictionary
options
:
0
error
:
NULL
];
[
self
sendContext8
:
jsonData
successBlock
:
^
(
NSDictionary
*
contextResponse
)
{
if
(
success
)
{
success
(
contextResponse
);
}
NSLog
(
@"**************** WARPLY Response *****************"
);
NSLog
(
@"%@"
,
contextResponse
);
}
failureBlock
:^
(
NSError
*
error
)
{
if
(
failure
)
{
NSDictionary
*
dict
=
[
NSDictionary
alloc
];
dict
=
[
error
userInfo
];
NSString
*
errorCode
=
[
dict
objectForKey
:
@"NSLocalizedDescription"
];
if
([
errorCode
isEqual
:
@"Request failed: unauthorized (401)"
])
{
// NSString* errorDomain = [error domain];
// NSError *errorToken = [NSError errorWithDomain:errorDomain code:401 userInfo:dict];
//
// if (failure) {
// failure(errorToken);
// }
[
self
refreshToken
:
^
(
NSDictionary
*
response
)
{
[
self
sendContext8
:
jsonData
successBlock
:
^
(
NSDictionary
*
contextResponse
)
{
if
(
success
)
{
success
(
contextResponse
);
}
NSLog
(
@"**************** WARPLY Response *****************"
);
NSLog
(
@"%@"
,
contextResponse
);
}
failureBlock
:^
(
NSError
*
error
)
{
if
(
failure
)
{
failure
(
error
);
}
}];
}
failureBlock
:
^
(
NSError
*
error
)
{
if
(
failure
)
{
// [_db executeUpdate:@"DROP TABLE requestVariables"];
failure
(
error
);
}
NSLog
(
@"Error at token %@"
,
error
);
}];
}
else
{
NSLog
(
@"Error at get unified coupons %@"
,
error
);
failure
(
error
);
}
}
}];
}
-
(
void
)
getTransactionHistoryWithSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
NSDictionary
*
postDictionary
=
@{
@"consumer_data"
:
@{
@"action"
:
@"get_transaction_history"
,
@"product_detail"
:
@"minimal"
}};
...
...
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
f3047eb
...
...
@@ -17,6 +17,7 @@ public struct GlobalVariables {
static
var
couponList
:
Array
<
swiftApi
.
CouponItemModel
>
=
[]
static
var
oldCouponList
:
Array
<
swiftApi
.
CouponItemModel
>
=
[]
static
var
couponSetList
:
Array
<
swiftApi
.
CouponSetItemModel
>
=
[]
static
var
unifiedCouponList
:
Array
<
swiftApi
.
UnifiedCouponModel
>
=
[]
static
var
loyaltyBadge
:
swiftApi
.
LoyaltyBadgeModel
=
swiftApi
.
LoyaltyBadgeModel
()
static
var
consumer
:
swiftApi
.
ProfileModel
?
static
var
consumerInternal
:
swiftApi
.
ProfileModel
?
...
...
@@ -142,6 +143,16 @@ public class swiftApi {
}
public
func
setUnifiedCouponList
(
_
unifiedCoupons
:
Array
<
UnifiedCouponModel
>
)
{
GlobalVariables
.
unifiedCouponList
=
unifiedCoupons
}
public
func
getUnifiedCouponList
()
->
Array
<
UnifiedCouponModel
>
{
return
GlobalVariables
.
unifiedCouponList
}
public
func
startTrackingSteps
(
_
getStepsCallback
:
@escaping
(
_
steps
:
Int
)
->
Void
)
->
Void
{
if
(
GlobalVariables
.
trackingStepsEnabled
==
false
)
{
...
...
@@ -6751,5 +6762,158 @@ public class swiftApi {
}
}
public
class
UnifiedCouponModel
{
private
var
barcode
:
String
?
private
var
code
:
Int
?
private
var
coupons
:
Array
<
CouponItemModel
>
?
private
var
created
:
String
?
public
init
()
{
self
.
barcode
=
""
self
.
code
=
0
self
.
coupons
=
[]
self
.
created
=
""
}
public
init
(
dictionary
:
[
String
:
Any
])
{
self
.
barcode
=
dictionary
[
"barcode"
]
as?
String
?
??
""
self
.
code
=
dictionary
[
"code"
]
as?
Int
?
??
0
if
let
couponsData
=
dictionary
[
"coupons"
]
as?
[[
String
:
Any
]?]
{
var
couponsArray
:
Array
<
CouponItemModel
>
=
[]
for
item
in
couponsData
{
if
let
itemDictionary
=
item
{
let
tempCoupon
=
CouponItemModel
(
dictionary
:
itemDictionary
)
couponsArray
.
append
(
tempCoupon
)
}
}
self
.
coupons
=
couponsArray
}
else
{
self
.
coupons
=
[]
}
// Example "created":"Mon, 03 Apr 2023 15:05:14 GMT"
let
dateString
=
dictionary
[
"created"
]
as?
String
?
??
""
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
locale
=
Locale
(
identifier
:
"en_US_POSSIX"
)
dateFormatter
.
dateFormat
=
"E, MMM dd yyyy HH:mm:ss"
if
let
date
=
dateFormatter
.
date
(
from
:
dateString
??
""
)
{
dateFormatter
.
dateFormat
=
"dd/MM/yyyy"
let
resultString
=
dateFormatter
.
string
(
from
:
date
)
self
.
created
=
resultString
}
else
{
self
.
created
=
""
}
}
public
var
_barcode
:
String
{
get
{
// getter
return
self
.
barcode
??
""
}
set
(
newValue
)
{
//setter
self
.
barcode
=
newValue
}
}
public
var
_code
:
Int
{
get
{
// getter
return
self
.
code
??
0
}
set
(
newValue
)
{
//setter
self
.
code
=
newValue
}
}
public
var
_coupons
:
Array
<
CouponItemModel
>
{
get
{
// getter
return
self
.
coupons
??
[]
}
set
(
newValue
)
{
//setter
self
.
coupons
=
newValue
}
}
public
var
_created
:
String
{
get
{
// getter
return
self
.
created
??
""
}
set
(
newValue
)
{
//setter
self
.
created
=
newValue
}
}
}
public
func
getUnifiedCouponsAsync
(
_
successCallback
:
@escaping
(
_
responseData
:
Array
<
UnifiedCouponModel
>
?)
->
Void
,
failureCallback
:
@escaping
(
_
errorCode
:
Int
)
->
Void
)
->
Void
{
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
getUnifiedCouponsAsync
(
getUnifiedCallback
,
failureBlock
:
getUnifiedFailureCallback
)
func
getUnifiedCallback
(
_
responseData
:
[
AnyHashable
:
Any
]?)
->
Void
{
var
unifiedCouponsArray
:
Array
<
UnifiedCouponModel
>
=
[]
if
let
responseDataDictionary
=
responseData
as?
[
String
:
AnyObject
]
{
if
(
responseDataDictionary
[
"status"
]
as?
Int
==
1
)
{
// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
// dynatraceEvent._eventName = "custom_success_campaigns_loyalty"
// dynatraceEvent._parameters = nil
// SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
if
let
responseDataResult
=
responseDataDictionary
[
"result"
]
as?
[
String
:
Any
]
{
if
let
responseDataCoupons
=
responseDataResult
[
"coupons"
]
as?
[[
String
:
Any
]?]
{
for
item
in
responseDataCoupons
{
if
let
itemDictionary
=
item
{
if
let
itemDictionaryStauts
=
itemDictionary
[
"status"
]
as?
String
{
if
(
itemDictionaryStauts
==
"active"
)
{
let
tempCampaign
=
UnifiedCouponModel
(
dictionary
:
itemDictionary
)
unifiedCouponsArray
.
append
(
tempCampaign
)
}
}
}
}
swiftApi
()
.
setUnifiedCouponList
(
unifiedCouponsArray
)
successCallback
(
unifiedCouponsArray
)
}
}
else
{
successCallback
(
nil
)
}
}
else
{
// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
// dynatraceEvent._eventName = "custom_error_campaigns_loyalty"
// dynatraceEvent._parameters = nil
// SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
successCallback
(
nil
)
}
}
else
{
// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
// dynatraceEvent._eventName = "custom_error_campaigns_loyalty"
// dynatraceEvent._parameters = nil
// SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
successCallback
(
nil
)
}
}
func
getUnifiedFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"getUnifiedCouponsAsync error: "
)
print
(
error
)
print
(
"===================="
)
// let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel()
// dynatraceEvent._eventName = "custom_error_campaigns_loyalty"
// dynatraceEvent._parameters = nil
// SwiftEventBus.post("dynatrace", sender: dynatraceEvent)
successCallback
(
nil
)
}
}
}
...
...
Please
register
or
login
to post a comment