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
2022-05-06 17:54:28 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
736b800cb627fec837e09e1f59a5240e2fa8bd11
736b800c
1 parent
01e9f5f7
add getCoupons async Request
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
46 deletions
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/MyApi.h
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/MyApi.m
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/swiftApi.swift
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
View file @
736b800
No preview for this file type
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/MyApi.h
View file @
736b800
...
...
@@ -75,6 +75,8 @@
-
(
NSDictionary
*
)
redeemCouponWithCoupon
:(
NSString
*
)
coupon
;
-
(
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
)
getCouponsetsAsync
:(
NSNumber
*
)
active
andVisible
:
(
NSNumber
*
)
visible
andUuids
:
(
NSArray
*
)
uuids
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
@end
#endif
/* MyApi_h */
...
...
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/MyApi.m
View file @
736b800
...
...
@@ -1257,4 +1257,31 @@ CMPedometer *pedometer;
}
return
resp
;
}
-
(
void
)
getCouponsWithSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[[
Warply
sharedService
]
getCouponsWithSuccessBlock
:
^
(
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
)
{
if
(
success
)
{
success
(
response
);
}
}
failureBlock
:^
(
NSError
*
error
)
{
if
(
failure
)
{
failure
(
error
);
}
}];
}
@end
...
...
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/swiftApi.swift
View file @
736b800
...
...
@@ -220,54 +220,9 @@ public class swiftApi {
var
data
:
Array
<
CouponItemModel
>
=
[]
init
()
{
//initializer method
let
instanceOfMyApi
=
MyApi
()
let
coupons
=
instanceOfMyApi
.
getCoupons
()
let
couponSets
=
instanceOfMyApi
.
getCouponSets
(
withActive
:
true
,
andVisible
:
true
,
andUuids
:
nil
)
var
couponsArray
:
Array
<
CouponItemModel
>
=
[]
if
let
myCouponsSetsDictionary
=
couponSets
as?
[
String
:
AnyObject
]
{
let
couponSetsData
=
(
myCouponsSetsDictionary
[
"MAPP_COUPON"
]
as!
Array
<
NSMutableDictionary
>
)
if
let
myCouponsDictionary
=
coupons
as?
[
String
:
AnyObject
]
{
let
couponsData
=
(
myCouponsDictionary
[
"result"
]
as!
Array
<
NSMutableDictionary
>
)
if
let
sets
=
couponSetsData
as?
NSArray
{
for
set
in
sets
{
let
s
=
set
as!
NSDictionary
if
let
cpns
=
couponsData
as?
NSArray
{
for
coupon
in
cpns
{
var
c
=
coupon
as!
NSDictionary
// var temp = NSMutableDictionary(dictionary: s);
if
c
[
"couponset_uuid"
]
as!
String
==
s
[
"uuid"
]
as!
String
{
let
temp
=
NSMutableDictionary
(
dictionary
:
c
);
temp
.
setValue
(
s
as!
[
AnyHashable
:
Any
],
forKey
:
"couponset_data"
)
let
tempCoupon
=
CouponItemModel
(
dictionary
:
temp
as!
[
String
:
Any
])
couponsArray
.
append
(
tempCoupon
)
}
}
}
}
}
}
}
// if let myCouponsDictionary = coupons as? [String : AnyObject] {
// let couponsData = (myCouponsDictionary["result"] as! NSArray)
//
//
// for coupon in couponsData {
// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any])
// couponsArray.append(tempCoupon)
// }
//
// }
self
.
data
=
couponsArray
}
var
getData
:
Array
<
CouponItemModel
>
{
get
{
// getter
return
data
.
filter
({
...
...
@@ -285,6 +240,105 @@ public class swiftApi {
}
}
func
getCouponsData
(
_
getCouponsCallback
:
@escaping
(
_
couponsData
:
Array
<
CouponItemModel
>
?)
->
Void
)
->
Void
{
var
coupons
:
[
AnyHashable
:
Any
]?
var
couponSets
:
[
AnyHashable
:
Any
]?
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
getCouponsWithSuccessBlock
(
couponsCallback
,
failureBlock
:
(
couponsFailureCallback
))
func
couponsCallback
(
_
couponsData
:
[
AnyHashable
:
Any
]?)
->
Void
{
coupons
=
couponsData
??
[
""
:
""
]
// On Coupons request success, make CouponSets request
instanceOfMyApi
.
getCouponsetsAsync
(
true
,
andVisible
:
true
,
andUuids
:
nil
,
couponSetsCallback
,
failureBlock
:
couponSetsFailureCallback
)
}
func
couponsFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"getCoupons error: "
)
getCouponsCallback
(
nil
)
}
func
couponSetsCallback
(
_
couponSetsData
:
[
AnyHashable
:
Any
]?)
->
Void
{
couponSets
=
couponSetsData
??
[
""
:
""
]
// On CouponSets request Success, match coupons with couponsets
let
tempCoupons
=
matchCoupons
()
getCouponsCallback
(
tempCoupons
)
}
func
couponSetsFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"getCouponSets error: "
)
getCouponsCallback
(
nil
)
}
func
matchCoupons
()
->
Array
<
CouponItemModel
>
{
var
couponsArray
:
Array
<
CouponItemModel
>
=
[]
if
let
myCouponsSetsDictionary
=
couponSets
as?
[
String
:
AnyObject
]
{
let
couponSetsData
=
(
myCouponsSetsDictionary
[
"MAPP_COUPON"
]
as!
Array
<
NSMutableDictionary
>
)
if
let
myCouponsDictionary
=
coupons
as?
[
String
:
AnyObject
]
{
let
couponsData
=
(
myCouponsDictionary
[
"result"
]
as!
Array
<
NSMutableDictionary
>
)
if
let
sets
=
couponSetsData
as?
NSArray
{
for
set
in
sets
{
let
s
=
set
as!
NSDictionary
if
let
cpns
=
couponsData
as?
NSArray
{
for
coupon
in
cpns
{
var
c
=
coupon
as!
NSDictionary
// var temp = NSMutableDictionary(dictionary: s);
if
c
[
"couponset_uuid"
]
as!
String
==
s
[
"uuid"
]
as!
String
{
let
temp
=
NSMutableDictionary
(
dictionary
:
c
);
temp
.
setValue
(
s
as!
[
AnyHashable
:
Any
],
forKey
:
"couponset_data"
)
let
tempCoupon
=
CouponItemModel
(
dictionary
:
temp
as!
[
String
:
Any
])
couponsArray
.
append
(
tempCoupon
)
}
}
}
}
}
}
}
// if let myCouponsDictionary = coupons as? [String : AnyObject] {
// let couponsData = (myCouponsDictionary["result"] as! NSArray)
//
//
// for coupon in couponsData {
// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any])
// couponsArray.append(tempCoupon)
// }
//
// }
return
couponsArray
}
}
}
public
func
filterActiveCoupons
(
_
coupons
:
Array
<
CouponItemModel
>
)
->
Array
<
CouponItemModel
>
{
return
coupons
.
filter
({
return
$0
.
status
==
1
})
}
public
func
filterOldCoupons
(
_
coupons
:
Array
<
CouponItemModel
>
)
->
Array
<
CouponItemModel
>
{
return
coupons
.
filter
({
return
$0
.
status
!=
1
})
}
public
func
getCouponsAsync
(
_
getCouponsCallback
:
@escaping
(
_
couponsData
:
Array
<
CouponItemModel
>
?)
->
Void
)
->
Void
{
CouponsDataModel
()
.
getCouponsData
(
getCouponsCallback
)
}
public
func
getCoupons
()
->
Array
<
CouponItemModel
>
{
...
...
Please
register
or
login
to post a comment