Exemplo n.º 1
0
        /// <summary>
        /// Send an arbitrary string to the user's sandbox
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private IEnumerator SetUserSandboxDataCor(string data)
        {
            var requestData = RewardMobWebRequestFactory.CreateSendSandboxDataRequest(data);

            WWW postUserDataRequest = new WWW(RewardMobEndpoints.GetSendUserDataEndpoint(), requestData.Payload, requestData.Headers);

            yield return(postUserDataRequest);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the user data stored in the user's sandbox
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        private IEnumerator GetUserSandboxDataCor(Action <string> callback)
        {
            var requestData = RewardMobWebRequestFactory.CreateGetSandboxDataRequest();

            WWW postUserDataRequest = new WWW(RewardMobEndpoints.GetSendUserDataEndpoint(), requestData.Payload, requestData.Headers);

            yield return(postUserDataRequest);

            callback(postUserDataRequest.text);
        }
        //REFACTOR
        public IEnumerator UpdateSeconds()
        {
            var gameID     = Resources.LoadAll <RewardMobData>("")[0].GameId;
            var webRequest = new WWW(RewardMobEndpoints.GetTournamentTimeRemainingEndpoint() + gameID);

            //halt execution until request returns
            yield return(webRequest);

            float.TryParse(webRequest.text, out secondsRemaining);
        }
Exemplo n.º 4
0
    /// <summary>
    /// Method to perform the reauthentication step once a user bearer token has become expired.
    /// </summary>
    public void PerformReauthentication()
    {
        if (ConnectivityTester.HasInternetConnection())
        {
            PlayerPrefs.DeleteKey("RewardMobAuthenticationTokenExpirationDate");

            isReauthenticating = true;

            //go through the reauthentication steps
            Application.OpenURL(RewardMobEndpoints.GetAuthenticationURL());
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Attached to the button's clicked event.
        /// </summary>
        public void OnClick()
        {
#if !UNITY_EDITOR
            //if it's not visible, either load the logged in flow, or login screen based on the token's presence
            if (!SampleWebView.webViewObject.GetVisibility())
            {
                RewardMob.instance.ToggleLoadingScreen(true);
                SampleWebView.Init();

                SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL());
            }
#endif
        }
        private IEnumerator GetTimeLeftAndUpdate()
        {
            //grab game id, and prepare web request
            var gameID     = Resources.LoadAll <RewardMobData>("")[0].GameId;
            var webRequest = new WWW(RewardMobEndpoints.GetTournamentTimeRemainingEndpoint() + gameID);

            //halt execution until request returns
            yield return(webRequest);

            float.TryParse(webRequest.text, out secondsRemaining);

            //invoke time update
            InvokeRepeating("UpdateTime", 0f, 1.0f);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Send off POST request for cached rewards
        /// </summary>
        private IEnumerator PostCachedRewards(List <Reward> backupContainer = null)
        {
            //create the headers/payload
            var requestData = RewardMobWebRequestFactory.CreateCachedRewardsRequest(cachedRewards.ToArray());

            WWW bulkPostRewards = new WWW(RewardMobEndpoints.GetMultiRewardEndpoint(), requestData.Payload, requestData.Headers);

            //halt for request to finish
            yield return(bulkPostRewards);

            //check if succeeded or not
            if (!string.IsNullOrEmpty(bulkPostRewards.error) && backupContainer != null)
            {
                cachedRewards = backupContainer;
            }
        }
Exemplo n.º 8
0
    /// <summary>
    /// Method used for communication from iOS/Android -> Unity for passing a valid authentication token
    ///
    /// NOT INTENDED TO BE MANUALLY CALLED WITHIN UNITY
    /// </summary>
    /// <param name="tokenFragment">The token</param>
    public void OnAccessToken(string tokenFragment)
    {
        string[] keyValues = tokenFragment.Split('&');

        foreach (string keyValuePair in keyValues)
        {
            string[] keyValue = keyValuePair.Split('=');

            //invalid KVP
            if (keyValue.Length != 2)
            {
                continue;
            }

            string key   = keyValue[0];
            string value = keyValue[1];

            switch (key)
            {
            case "access_token":
                RewardMob.instance.Token = value;
                break;

            case "expires_in":
                double expirationInSeconds = (double)long.Parse(value);
                RewardMob.instance.TokenExpiration = DateTime.UtcNow.AddSeconds(expirationInSeconds - reauthenticationOffsetInSeconds).ToString();
                break;

            default:
                break;
            }
        }
        //if this isn't part of the reauth process, open the WebView
        if (!isReauthenticating)
        {
            SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL());
        }

                #if UNITY_IOS
        // Tell iOS to Close the SafariViewController.
        _CloseSafari();
                #endif

        isReauthenticating = false;
        RewardMob.instance.TotalRewardCount = 0;
    }
Exemplo n.º 9
0
        /// <summary>
        /// Checks to see whether user is from a valid country, or the contrary
        /// </summary>
        /// <param name="onSuccess">Callback</param>
        /// <returns>Cor</returns>
        public IEnumerator GetRewardMobSupportedCountry(Action <bool> onSuccess)
        {
            //build request
            var webRequest = new WWW(RewardMobEndpoints.GetRewardMobSupportedCountryEndpoint());

            //send request
            yield return(webRequest);

            //handle request
            try
            {
                onSuccess(JsonUtility.FromJson <RewardMobResponseRoot>(webRequest.text).status.success);
            }
            catch
            {
                onSuccess(false);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Asynchronous method to send Reward off to API
        ///
        /// TODO: Should be split into more defined methods.
        /// </summary>
        /// <param name="rewardAmount">The amount of rewards to send.</param>
        /// <param name="rewardMessage">A short description explaining why the rewards were earned.</param>
        /// <returns>Cor</returns>
        private IEnumerator SendRewardCor(int rewardAmount, string rewardMessage, Action <Reward> onSuccess, Action <string> onFailed)
        {
            //check time remaining
            var webRequest = new WWW(RewardMobEndpoints.GetTournamentTimeRemainingEndpoint() + RewardMob.instance.gameID);

            //halt execution until request returns
            yield return(webRequest);

            float secondsRemaining;

            float.TryParse(webRequest.text, out secondsRemaining);

            //if there's no time remaining, don't bother
            if (secondsRemaining <= 0)
            {
                yield break;
            }

            //check if the reward is "cacheworthy"
            if (ShouldCache())
            {
                Cache(new Reward(RewardMob.instance.platformID, rewardAmount, rewardMessage, System.DateTime.UtcNow.ToString()));

                //update the user
                onSuccess(new Reward(RewardMob.instance.platformID, rewardAmount, rewardMessage));
                yield break;
            }

            //prepare the request
            var requestData = RewardMobWebRequestFactory.CreateRewardRequest(rewardAmount, rewardMessage);

            WWW postRewardRequest = new WWW(RewardMobEndpoints.GetSingleRewardEndpoint(), requestData.Payload, requestData.Headers);

            yield return(postRewardRequest);

            HandleRewardRequestClientsideUpdate(postRewardRequest, new Reward(RewardMob.instance.platformID, rewardAmount, rewardMessage), onSuccess, onFailed);

            //if we got an authorization error, cache it!
            if (!string.IsNullOrEmpty(postRewardRequest.error))
            {
                Cache(new Reward(RewardMob.instance.platformID, rewardAmount, rewardMessage, System.DateTime.UtcNow.ToString()));
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Pop open a WebView for when an unauthorized user earns a Reward for the first time (Onboarding)
        /// </summary>
        private void ShowFirstTimeEarnedRewardScreen()
        {
#if !UNITY_EDITOR
            if ((earnedState == RewardMobAuthorizedState.NOT_EARNED_FIRST_REWARD) && (Token == null))
            {
                ToggleLoadingScreen(true);

                SampleWebView.Init();
                try
                {
                    SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL(useLogicalRewards: true));

                    earnedState = RewardMobAuthorizedState.EARNED_FIRST_REWARD;
                }
                catch
                {
                    Debug.LogError("Fill out the Game ID section inside of the RewardMobData object at RewardMobSDK/Resources.");
                }
            }
#endif
        }
Exemplo n.º 12
0
    /// <summary>
    /// Method used for communication from iOS/Android -> Unity for passing an environment mode
    ///
    /// This method is called by native iOS/Android calls.
    /// </summary>
    /// <param name="environment">Environment to use</param>
    public void SetEnvironment(string environment)
    {
        //token between dev and production are assigned differently
        //token stored wont work when passed to WebView will show "No tournament found"
        if (RewardMobEndpoints.CurrentModeToString() != environment)
        {
            RewardMob.instance.Token = null;
        }

        switch (environment)
        {
        case ("dev"):
            RewardMobEndpoints.CurrentMode = RewardMobEndpoints.SDKMode.DEV;
            break;

        case ("prod"):
        default:
            RewardMobEndpoints.CurrentMode = RewardMobEndpoints.SDKMode.PROD;
            break;
        }
    }
Exemplo n.º 13
0
 public void RefreshWebview()
 {
     SampleWebView.webViewObject.LoadURL(RewardMobEndpoints.GetWebViewURL());
 }
Exemplo n.º 14
0
    /// <summary>
    /// Register
    /// </summary>
    /// <param name="message"></param>
    private static void RegisterWebviewSuccessCallbacks(string message)
    {
        //check to see if we're loading a URL from the callback
        if (message.StartsWith("url="))
        {
            // Strip url= from string, leaving just the URL.
            string url = message.Substring(4);

            // Perform iOS Specific check.
#if UNITY_IOS
            if (url.Contains("oauth/authorize") || url.Contains("auth/logout"))
            {
                // Logging in or out.
                // If iOS, call native code to load in SafariViewController.
                _OpenSafari(url);
                return;
            }
#endif

            if (url.Contains("oauth/authorize"))
            {
                RewardMob.instance.isLoggingIn = true;
            }

            //Load in default browser if not IOS
            Application.OpenURL(url);
            return;
        }

        //handle different callback cases
        switch (message)
        {
        //bring user through authentication flow
        case ("authenticateUser"):
            Application.OpenURL(RewardMobEndpoints.GetAuthenticationURL());
            break;

        //log the user out
        case ("logoutUser"):
                                #if UNITY_IOS
            // If iOS, hit the Logout page in SafariViewController.
            _LogoutUser(RewardMobEndpoints.CurrentModeToString());
                                #endif

            RewardMob.instance.ClearPersistentData();

            SampleWebView.webViewObject.SetVisibility(false);
            RewardMob.instance.OnClosedWebView();
            RewardMob.instance.TotalRewardCount = 0;
            break;

        //hide the webview
        case ("hideWebView"):
            SampleWebView.webViewObject.SetVisibility(false);
            RewardMob.instance.OnClosedWebView();
            break;

        //let client know that the page is done loading
        case ("pageDoneLoading"):
            RewardMob.instance.ToggleLoadingScreen(false);
            webViewObject.SetVisibility(true);
            break;

        default:
            break;
        }
    }