diff --git a/source/itbl-sdk/components/ItblSDK.brs b/source/itbl-sdk/components/ItblSDK.brs index 91b1cac..cf16e76 100644 --- a/source/itbl-sdk/components/ItblSDK.brs +++ b/source/itbl-sdk/components/ItblSDK.brs @@ -64,13 +64,15 @@ function ItblSetUserInfo(userInfo as object) else m.jwtToken = invalid end if - if (userInfo.email = invalid and userInfo.userId = invalid) + if ((userInfo.email = invalid and userInfo.userId = invalid) or (userInfo.email = invalid and userInfo.userId = "") or (userInfo.email = "" and userInfo.userId = invalid) ) m.RegistryManager.ClearUserInfo() status = { "status": "failed", "count": 0, message: "Call ItblSetEmailOrUserId with either of email or userId with proper value."} + m.top.updateUserStatus = status m.top.messageStatus = status else if (userInfo.email <> invalid and userInfo.email <> "" and userInfo.userId <> invalid and userInfo.userId <> "") m.RegistryManager.ClearUserInfo() status = { "status": "failed", "count": 0, message: "Call ItblSetEmailOrUserId to set either email or userId with proper value."} + m.top.updateUserStatus = status m.top.messageStatus = status else if ((userInfo.email <> invalid and userInfo.email <> "") or (userInfo.userId <> invalid and userInfo.userId <> "")) CallItblUpdateUser(userInfo) @@ -221,10 +223,10 @@ function CallItblApi(requestData as object, functionName as string, callBack as return itblApiTask end function -function SetErrorMessage(messageStatus, result) +function SetErrorMessage(field, messageStatus, result) if result.error <> invalid and result.error <> "" then messageStatus["message"] = result.error if result.code <> invalid and result.code <> 0 then messageStatus["code"] = result.code - m.top.messageStatus = messageStatus + m.top.setField(field,messageStatus) end function sub OnItblUpdateUserAPIResponse(msg as Object) @@ -234,11 +236,13 @@ sub OnItblUpdateUserAPIResponse(msg as Object) userInfo = getUserInfo(task.requestData) setUserInfo(userInfo) CallItblGetPriorityMessage(userInfo) + m.top.updateUserStatus = { "status": "success", message: "" } m.top.messageStatus = { "status": "loading", "count": 0, message: "" } else m.RegistryManager.ClearUserInfo() messageStatus = { "status": "failed", "count": 0, message: "Failed to update user email/userId."} - SetErrorMessage(messageStatus, result) + SetErrorMessage("updateUserStatus", messageStatus, result) + SetErrorMessage("messageStatus", messageStatus, result) end if end sub @@ -259,7 +263,7 @@ sub OnItblGetPriorityMessageAPIResponse(msg as Object) end if else messageStatus = { "status": "failed", "count": 0, message: "Api failed to get meessage." } - SetErrorMessage(messageStatus, result) + SetErrorMessage("messageStatus", messageStatus, result) end if m.itblGetmessage = invalid end sub diff --git a/source/itbl-sdk/components/ItblSDK.xml b/source/itbl-sdk/components/ItblSDK.xml index e0bdb64..6520732 100644 --- a/source/itbl-sdk/components/ItblSDK.xml +++ b/source/itbl-sdk/components/ItblSDK.xml @@ -5,6 +5,7 @@ + diff --git a/source/itbl-sdk/source/itblApi/ItblBaseRequests.brs b/source/itbl-sdk/source/itblApi/ItblBaseRequests.brs index 8ef2441..1bd2304 100644 --- a/source/itbl-sdk/source/itblApi/ItblBaseRequests.brs +++ b/source/itbl-sdk/source/itblApi/ItblBaseRequests.brs @@ -159,20 +159,20 @@ function getErrorReason(response as dynamic) as string else if (response.code = 422 or response.code = 403 or response.code = 404 or response.code = 401) data = ParseJSON(response.reason) - if data = invalid 'If, this is not json - if response.message <> invalid - return response.message - else - return response.reason - end if - end if - - msg = "" - if data.message <> invalid - msg = data.message - else if data.detail <> invalid - msg = data.detail - end if + if data = invalid 'If, this is not json + if response.message <> invalid + return response.message + else + return response.reason + end if + end if + + msg = "" + if data.message <> invalid + msg = data.message + else if data.detail <> invalid + msg = data.detail + end if return msg else diff --git a/test-app/components/scene/MainScene.brs b/test-app/components/scene/MainScene.brs index 99b62ec..9fc4c71 100644 --- a/test-app/components/scene/MainScene.brs +++ b/test-app/components/scene/MainScene.brs @@ -2,7 +2,6 @@ sub init() setLocals() SetControls() setTheme() - SetObservers() SetDefaultFocus() Initialize() end sub @@ -10,7 +9,6 @@ end sub sub setLocals() m.exitCalled = false m.exitPopUpOpened = false - end sub sub SetControls() @@ -34,8 +32,6 @@ sub SetControls() m.lMoreDetails = m.top.findNode("lMoreDetails") - m.timer = m.top.findNode("Timer") - m.openSansbold56 = CreateObject("roSGNode", "Font") m.openSansbold56.uri = "pkg:/source/fonts/OpenSans-Bold.ttf" m.openSansbold56.size = 56 @@ -76,10 +72,6 @@ sub setTheme() m.bsPreloader.poster.height = "160" end sub -sub SetObservers() - m.timer.observeField("fire", "OnTimerFire") -end sub - sub SetDefaultFocus() m.pMoredetails.opacity = 0.5 m.pWatchnow.opacity = 1 @@ -95,18 +87,37 @@ sub Initialize() 'With JWT jwtToken = "YOUR_JWT_HERE" status = ItblSetEmailOrUserId({"email":"roku@test.com", "token": jwtToken}) - m.timer.control = "START" end sub -function OnTimerFire() - 'STEP 3 : Show the in-app message' - applicationLoadStatus = ItblOnApplicationLoaded() +' TO do any action based on Update User response either success or failed result will be come in userUpdateStaus.' +function OnItblUpdateUserEvent(event as dynamic) + userUpdateStaus = event.getData() + if userUpdateStaus <> invalid + ' Perform any relevant action required on Update User if needed. + print "ItblSetEmailOrUserId Status : "userUpdateStaus + end if +end function + - if not applicationLoadStatus.success - m.lDeepLinkLabel.text = "Library Status : " +' TO do any action based on Update User response either success or failed result will be come in userUpdateStaus.' +function OnItblMessageUpdateEvent(event as dynamic) + messageStatus = event.getData() + if messageStatus <> invalid + ' Perform any relevant action required on Update User if needed. + print "OnItblMessageUpdateEvent : "messageStatus + if messageStatus <> invalid and messageStatus.status <> "loading" + ' here you can add additional check as well messageStatus.status = 'loaded' and messageStatus.count > 0 + ' Which will only call in success scenario. I have put this as sample to just display on Screen Library status with 0 message receieve. + applicationLoadStatus = ItblOnApplicationLoaded() + print "ItblOnApplicationLoaded Status "applicationLoadStatus + + if not applicationLoadStatus.success + m.lDeepLinkLabel.text = "Library Status : " + end if + m.lDeepLinkValue.text = applicationLoadStatus.message + end if end if - m.lDeepLinkValue.text = applicationLoadStatus.message end function ' TO do any action based on click event.' diff --git a/test-app/components/scene/MainScene.xml b/test-app/components/scene/MainScene.xml index 55f5a5f..0b63ae2 100644 --- a/test-app/components/scene/MainScene.xml +++ b/test-app/components/scene/MainScene.xml @@ -9,6 +9,10 @@ + + + + @@ -110,11 +114,6 @@ - - diff --git a/test-app/source/itblHelper.brs b/test-app/source/itblHelper.brs index 37072e1..f195cbb 100644 --- a/test-app/source/itblHelper.brs +++ b/test-app/source/itblHelper.brs @@ -15,12 +15,12 @@ end function function ItblSetEmailOrUserId(userInfo = invalid as object) if userInfo = invalid then userInfo = {} if m.itblDialog <> invalid + m.top.ItblUpdateUser = invalid status = m.itblDialog.callFunc("ItblSetUserInfo", userInfo) else - status = {"status": "waiting", "message": "Library is not yet loaded."} + m.top.ItblUpdateUser = {"status": "waiting", "message": "Library is not yet loaded."} end if m.setUserInfoEmail = userInfo - return status end function function ItblOnApplicationLoaded() @@ -62,6 +62,7 @@ function ItblOnApplicationLoaded() status : m.messageStatus.status success : false, message : m.messageStatus.message + code: m.messageStatus.code } else if m.messageStatus.status = "displayed" response = { @@ -76,6 +77,7 @@ function ItblOnApplicationLoaded() status : m.messageStatus.status success : false, message : m.messageStatus.message + code: m.messageStatus.code } else ShowDialog() @@ -128,9 +130,11 @@ sub SetupItblDialog() m.itblDialog = CreateObject("roSGNode", "ItblSDK:ItblSDK") m.itblDialog.config = m.itblConfig m.itblDialog.observeField("messageStatus", "OnMessageStatus") + m.itblDialog.observeField("updateUserStatus", "OnUpdateUserStatus") m.itblDialog.observeField("closeDialog", "OnCloseDialog") m.itblDialog.observeField("clickEvent", "OnClickEvent") if m.setUserInfoEmail <> invalid then + m.top.ItblUpdateUser = invalid m.itblDialog.callFunc("ItblSetUserInfo", m.setUserInfoEmail) m.setUserInfoEmail = invalid else @@ -157,7 +161,17 @@ end function sub OnMessageStatus(event as dynamic) messageStatus = event.getData() if messageStatus <> invalid - m.messageStatus = messageStatus + m.messageStatus = messageStatus + if m.top.ItblUpdateUser <> invalid and m.top.ItblUpdateUser.status = "success" + m.top.ItblMessageUpdate = messageStatus + end if + end if +end sub + +sub OnUpdateUserStatus(event as dynamic) + userUpdateStatus = event.getData() + if userUpdateStatus <> invalid + m.top.ItblUpdateUser = userUpdateStatus end if end sub @@ -182,6 +196,7 @@ end sub sub CloseItblSDKDialog(IsClickEvent as boolean) m.itblDialog.unObserveField("messageStatus") + m.itblDialog.unObserveField("updateUserStatus") m.itblDialog.unObserveField("closeDialog") m.itblDialog.unObserveField("clickEvent") m.top.removeChild(m.itblDialog)