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-07-01 18:36:06 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e3414d9b2f96b3d3108b4f20795a7108b1babfcc
e3414d9b
1 parent
8c5bdaa3
add handleSharing, cosmoteSharingAsync
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
277 additions
and
21 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 @
e3414d9
...
...
@@ -84,6 +84,7 @@
-
(
void
)
consumerIntegrationAsync
:(
NSNumber
*
)
nonTelco
:
(
NSNumber
*
)
acceptedConsent
:
(
NSArray
*
)
msisdnList
:
(
NSString
*
)
guid
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
redeemCouponSetAsync
:(
NSString
*
)
uuid
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
getPacingDetailsAsync
:(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
cosmoteSharingAsync
:(
NSString
*
)
sharingId
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
;
@end
#endif
/* MyApi_h */
...
...
SwiftWarplyFramework/SwiftWarplyFramework/MyApi.m
View file @
e3414d9
...
...
@@ -1392,4 +1392,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
-
(
void
)
cosmoteSharingAsync
:
(
NSString
*
)
sharingId
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
[[
Warply
sharedService
]
cosmoteSharingWithSuccessBlock
:
sharingId
:
^
(
NSDictionary
*
response
)
{
if
(
success
)
{
success
(
response
);
}
}
failureBlock
:^
(
NSError
*
error
)
{
if
(
failure
)
{
failure
(
error
);
}
}];
}
@end
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.h
View file @
e3414d9
...
...
@@ -374,6 +374,8 @@ WL_VERSION_INTERFACE()
-
(
void
)
redeemCouponSetsWithSuccessBlock
:(
NSString
*
)
uuid
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
cosmoteSharingWithSuccessBlock
:(
NSString
*
)
sharingId
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
validateCouponWithSuccessBlock
:(
NSString
*
)
coupon
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:(
void
(
^
)(
NSError
*
error
))
failure
;
-
(
void
)
loginCosmoteWithSuccessBlock
:(
NSString
*
)
guid
andAppUuid
:(
NSString
*
)
appUuid
andTicket
:(
NSString
*
)
ticket
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
;
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Warply/Warply.m
View file @
e3414d9
...
...
@@ -1368,7 +1368,7 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
-
(
void
)
getCouponsWithSuccessBlock
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
NSDictionary
*
postDictionary
=
@{
@"coupon"
:
@{
@"action"
:
@"get_user_coupons"
,
@"fetch_data"
:
@[
@"transaction"
]}};
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
)
{
...
...
@@ -1917,6 +1917,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION)
}];
}
-
(
void
)
cosmoteSharingWithSuccessBlock
:
(
NSString
*
)
sharingId
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
NSDictionary
*
postDictionary
=
@{
@"wallet"
:
@{
@"action"
:
@"sharing_info"
,
@"sharing_id"
:
sharingId
}};
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)"
])
{
[
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
);
}];
}
NSLog
(
@"Error at get cosmote sharing %@"
,
error
);
}
}];
}
-
(
void
)
validateCouponWithSuccessBlock
:
(
NSString
*
)
coupon
:
(
void
(
^
)(
NSDictionary
*
response
))
success
failureBlock
:
(
void
(
^
)(
NSError
*
error
))
failure
{
NSDictionary
*
postDictionary
=
@{
@"coupon"
:
@{
@"action"
:
@"validate"
,
@"coupon"
:
coupon
}};
...
...
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
e3414d9
...
...
@@ -1601,27 +1601,159 @@ public class swiftApi {
return
finalUrl
}
public
func
constructCampaignUrlForShare
(
_
sessionUuid
:
String
,
_
sharingId
:
String
)
->
String
{
for
item
in
GlobalVariables
.
campaigns
{
if
(
item
.
session_uuid
==
sessionUuid
)
{
let
instanceOfMyApi
=
MyApi
()
let
campaignInfo
=
instanceOfMyApi
.
provideInfoForCampaign
()
let
finalUrl
=
(
item
.
index_url
??
""
)
+
"?web_id="
+
(
campaignInfo
?[
"web_id"
]
as!
String
)
+
"&app_uuid="
+
(
campaignInfo
?[
"app_uuid"
]
as!
String
)
+
"&api_key="
+
(
campaignInfo
?[
"api_key"
]
as!
String
)
+
"&session_uuid="
+
(
item
.
session_uuid
??
""
)
+
"&access_token="
+
(
campaignInfo
?[
"access_token"
]
as!
String
)
+
"&refresh_token="
+
(
campaignInfo
?[
"refresh_token"
]
as!
String
)
+
"&client_id="
+
(
campaignInfo
?[
"client_id"
]
as!
String
)
+
"&client_secret="
+
(
campaignInfo
?[
"client_secret"
]
as!
String
)
+
"&sharing_id="
+
sharingId
;
return
finalUrl
break
;
public
func
handleSharing
(
_
controller
:
UIViewController
,
_
sharingId
:
String
)
->
Void
{
self
.
cosmoteSharingAsync
(
sharingId
:
sharingId
,
sharingCallback
)
func
sharingCallback
(
_
sharingData
:
SharingResponseModel
?)
->
Void
{
if
(
sharingData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
print
(
"========= DispatchQueue sharingCallback SUCCESSSS ========="
)
print
(
sharingData
)
print
(
sharingData
?
.
_modal_text
)
print
(
sharingData
?
.
_status
)
if
(
sharingData
?
.
_status
!=
nil
&&
sharingData
?
.
_status
!=
""
&&
sharingData
?
.
_status
==
"pending"
)
{
self
.
initialSharingDialog
(
controller
,
sharingData
?
.
_modal_text
??
""
,
sharingId
)
}
else
if
(
sharingData
?
.
_status
!=
nil
&&
sharingData
?
.
_status
!=
""
&&
sharingData
?
.
_status
==
"reject"
)
{
self
.
returnSharingDialog
(
controller
,
sharingData
?
.
_modal_text
??
""
)
}
}
}
else
{
// status != 1
errorSharingDialog
(
controller
)
}
}
return
""
// initialSharingDialog(controller, alertTitle, "")
// acceptSharingDialog(controller)
// rejectSharingDialog(controller, "")
// returnSharingDialog(controller, alertTitle)
// errorSharingDialog(controller)
}
func
initialSharingDialog
(
_
controller
:
UIViewController
,
_
alertTitle
:
String
,
_
sharingId
:
String
)
->
Void
{
let
alert
=
UIAlertController
(
title
:
"Συγχαρητήρια!"
,
message
:
alertTitle
,
preferredStyle
:
.
alert
)
alert
.
addAction
(
UIAlertAction
(
title
:
"Ενεργοποίηση"
,
style
:
.
default
,
handler
:
{
action
in
switch
action
.
style
{
case
.
default
:
// TODO: add cosmoteRetrieveSharing request
print
(
"default 1"
)
case
.
cancel
:
print
(
"cancel 1"
)
case
.
destructive
:
print
(
"destructive 1"
)
}
}))
alert
.
addAction
(
UIAlertAction
(
title
:
"Απόρριψη"
,
style
:
.
default
,
handler
:
{
action
in
switch
action
.
style
{
case
.
default
:
rejectSharingDialog
(
controller
,
""
)
print
(
"default 2"
)
case
.
cancel
:
print
(
"cancel 2"
)
case
.
destructive
:
print
(
"destructive 2"
)
}
}))
controller
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
func
acceptSharingDialog
(
_
controller
:
UIViewController
)
->
Void
{
let
alert
=
UIAlertController
(
title
:
"Συγχαρητήρια!"
,
message
:
"Μόλις έλαβες το δώρο σου!"
,
preferredStyle
:
.
alert
)
alert
.
addAction
(
UIAlertAction
(
title
:
"OK"
,
style
:
.
default
,
handler
:
{
action
in
switch
action
.
style
{
case
.
default
:
print
(
"default 1"
)
case
.
cancel
:
print
(
"cancel 1"
)
case
.
destructive
:
print
(
"destructive 1"
)
}
}))
controller
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
func
rejectSharingDialog
(
_
controller
:
UIViewController
,
_
sharingId
:
String
)
->
Void
{
let
alert
=
UIAlertController
(
title
:
"Είσαι σίγουρος;"
,
message
:
"Είσαι σίγουρος ότι θέλεις να απορρίψεις το δώρο που μόλις έλαβες;"
,
preferredStyle
:
.
alert
)
alert
.
addAction
(
UIAlertAction
(
title
:
"Απόρριψη"
,
style
:
.
default
,
handler
:
{
action
in
switch
action
.
style
{
case
.
default
:
print
(
"default 1"
)
case
.
cancel
:
print
(
"cancel 1"
)
case
.
destructive
:
print
(
"destructive 1"
)
}
}))
alert
.
addAction
(
UIAlertAction
(
title
:
"Άκυρο"
,
style
:
.
default
,
handler
:
{
action
in
switch
action
.
style
{
case
.
default
:
print
(
"default 2"
)
case
.
cancel
:
print
(
"cancel 2"
)
case
.
destructive
:
print
(
"destructive 2"
)
}
}))
controller
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
func
returnSharingDialog
(
_
controller
:
UIViewController
,
_
alertTitle
:
String
)
->
Void
{
let
alert
=
UIAlertController
(
title
:
"Επιστροφή δώρου"
,
message
:
alertTitle
,
preferredStyle
:
.
alert
)
alert
.
addAction
(
UIAlertAction
(
title
:
"OK"
,
style
:
.
default
,
handler
:
{
action
in
switch
action
.
style
{
case
.
default
:
print
(
"default 1"
)
case
.
cancel
:
print
(
"cancel 1"
)
case
.
destructive
:
print
(
"destructive 1"
)
}
}))
controller
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
func
errorSharingDialog
(
_
controller
:
UIViewController
)
->
Void
{
let
alert
=
UIAlertController
(
title
:
"Αποτυχία"
,
message
:
"Κάτι πήγε στραβά"
,
preferredStyle
:
.
alert
)
alert
.
addAction
(
UIAlertAction
(
title
:
"OK"
,
style
:
.
default
,
handler
:
{
action
in
switch
action
.
style
{
case
.
default
:
print
(
"default 1"
)
case
.
cancel
:
print
(
"cancel 1"
)
case
.
destructive
:
print
(
"destructive 1"
)
}
}))
controller
.
present
(
alert
,
animated
:
true
,
completion
:
nil
)
}
...
...
@@ -1931,7 +2063,7 @@ public class swiftApi {
}
func
requestFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"
consumerIntegration
error: "
)
print
(
"
redeemCouponSet
error: "
)
print
(
error
)
print
(
"===================="
)
redeemCouponSetCallback
(
nil
)
...
...
@@ -2406,4 +2538,71 @@ public class swiftApi {
}
}
public
class
SharingResponseModel
{
private
var
modal_text
:
String
private
var
status
:
String
init
()
{
self
.
modal_text
=
""
self
.
status
=
""
}
init
(
dictionary
:
[
String
:
Any
])
{
self
.
modal_text
=
dictionary
[
"modal_text"
]
as?
String
??
""
self
.
status
=
dictionary
[
"status"
]
as?
String
??
""
}
public
var
_modal_text
:
String
{
get
{
// getter
return
self
.
modal_text
}
set
(
newValue
)
{
//setter
self
.
modal_text
=
newValue
}
}
public
var
_status
:
String
{
get
{
// getter
return
self
.
status
}
set
(
newValue
)
{
//setter
self
.
status
=
newValue
}
}
}
public
func
cosmoteSharingAsync
(
sharingId
:
String
,
_
cosmoteSharingCallback
:
@escaping
(
_
responseData
:
SharingResponseModel
?)
->
Void
)
->
Void
{
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
cosmoteSharingAsync
(
sharingId
,
requestCallback
,
failureBlock
:
requestFailureCallback
)
func
requestCallback
(
_
responseData
:
[
AnyHashable
:
Any
]?)
->
Void
{
if
let
responseDataDictionary
=
responseData
as?
[
String
:
AnyObject
]
{
if
(
responseDataDictionary
[
"status"
]
as?
Int
==
1
)
{
let
responseDataResult
=
(
responseDataDictionary
[
"result"
]
as?
[
String
:
Any
]
??
[
String
:
Any
]())
let
tempResponse
=
SharingResponseModel
(
dictionary
:
responseDataResult
)
cosmoteSharingCallback
(
tempResponse
);
}
else
{
cosmoteSharingCallback
(
nil
)
}
}
else
{
cosmoteSharingCallback
(
nil
)
}
}
func
requestFailureCallback
(
_
error
:
Error
?)
->
Void
{
print
(
"cosmoteSharing error: "
)
print
(
error
)
print
(
"===================="
)
cosmoteSharingCallback
(
nil
)
}
}
}
...
...
Please
register
or
login
to post a comment