Example #1
0
        private IEnumerator GetAccountRewardCall(OnAccounRewardSuccessDelegate OnSucess, OnAccountRewardFailedDelegate OnFailed, bool isRetry = false)
        {
            bool   areAccountsDone      = false;
            string accountsLoadingError = "";

            if (CurrentUser == null || CurrentUser.accounts.Count == 0)
            {
                Quarters.Instance.GetAccounts(delegate(List <User.Account> accounts) {
                    //accounts loaded
                    areAccountsDone = true;
                }, delegate(string getAccountsError) {
                    OnFailed("Getting user accounts failed: " + getAccountsError);
                    areAccountsDone      = true;
                    accountsLoadingError = getAccountsError;
                });

                while (!areAccountsDone)
                {
                    yield return(new WaitForEndOfFrame());
                }

                //error occured, break out of coroutine
                if (!string.IsNullOrEmpty(accountsLoadingError))
                {
                    yield break;
                }
            }

            if (CurrentUser.accounts.Count < 1)
            {
                OnFailed("User account not loaded");
                yield break;
            }

            User.Account account = CurrentUser.accounts[0];

            string url = API_URL + "/accounts/" + account.address + "/rewards";

            WWW www = new WWW(url, null, AuthorizationHeader);

            yield return(www);

            while (!www.isDone)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (!string.IsNullOrEmpty(www.error))
            {
                if (!isRetry)
                {
                    //refresh access code and retry this call in case access code expired
                    StartCoroutine(GetAccessToken(delegate {
                        StartCoroutine(GetAccountRewardCall(OnSucess, OnFailed, true));
                    }, delegate(string error) {
                        OnFailed(www.error);
                    }));
                }
                else
                {
                    Debug.LogError(www.error);
                    OnFailed(www.error);
                }
            }
            else
            {
                Debug.Log(www.text);
                account.reward = JsonConvert.DeserializeObject <User.Account.Reward>(www.text);
                OnSucess(account.reward);
            }
        }
Example #2
0
 public void GetAccountReward(OnAccounRewardSuccessDelegate OnSuccessDelegate, OnAccountRewardFailedDelegate OnFailedDelegate)
 {
     StartCoroutine(GetAccountRewardCall(OnSuccessDelegate, OnFailedDelegate));
 }