Example #1
0
        public static void GetTransactions(Action <BankTransaction[]> onFinish)
        {
            if (DateTimeOffset.Now.ToUnixTimeSeconds() -
                UserDataManager.Instance.UserData.monobankData.updateInfo.LastUpdateBankTransactions <
                60)
            {
                onFinish(null);
                return;
            }

            if (Instance.traansactionRequsetStatus == RequestStatus.Updating)
            {
                Utility.Invoke(() => { onFinish(null); },
                               () => Instance.traansactionRequsetStatus == RequestStatus.Updated);
                return;
            }

            Instance.traansactionRequsetStatus = RequestStatus.Updating;
            var to   = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
            var from = to - 60 * 60 * 24 * 31;
            var url  = ApiEndPoint + $"/personal/statement/0/{from}/{to}";

            Instance.SendRequest(url, result =>
            {
                UserDataManager.Instance.UserData.monobankData.updateInfo.LastUpdateBankTransactions =
                    DateTimeOffset.Now.ToUnixTimeSeconds();
                onFinish(JsonHelper.GetJsonArray <BankTransaction>(result));
                Instance.traansactionRequsetStatus = RequestStatus.Updated;
            }, header: new KeyValuePair <string, string>("X-Token", UserDataManager.Instance.UserData.monobankData.token), onError: () => { onFinish(null);
                                                                                                                                            Instance.traansactionRequsetStatus = RequestStatus.Updated; });
        }
Example #2
0
        /// <summary>
        /// Возращает курсы валют доллар, евро
        /// </summary>
        public static void GetExchangeRates(Action <CurrencyInfo[]> onSuccessful, Action onError = null)
        {
            if (DateTimeOffset.Now.ToUnixTimeSeconds() -
                UserDataManager.Instance.UserData.monobankData.updateInfo.LastUpdateCurrencyInfoTime <
                60 * 5)
            {
                onError();
                return;
            }

            if (Instance.currencyRequsetStatus == RequestStatus.Updating)
            {
                Utility.Invoke(onError,
                               () => Instance.currencyRequsetStatus == RequestStatus.Updated);
                return;
            }

            Instance.currencyRequsetStatus = RequestStatus.Updating;
            var url = ApiEndPoint + "bank/currency";

            Instance.SendRequest(url, result =>
            {
                var data = JsonHelper.GetJsonArray <CurrencyInfo>(result).ToList();
                data.RemoveAll(item =>
                               !((item.currencyCodeA == (int)CurrencyCode.EUR || item.currencyCodeA == (int)CurrencyCode.USD) && // удаляем все ненужные валюта кроме USD/UAH EUR/UAH
                                 item.currencyCodeB == (int)CurrencyCode.UAH)
                               );
                UserDataManager.Instance.UserData.monobankData.updateInfo.LastUpdateCurrencyInfoTime =
                    DateTimeOffset.Now.ToUnixTimeSeconds();
                onSuccessful(data.ToArray());
                Instance.currencyRequsetStatus = RequestStatus.Updated;
            }, () =>
            {
                Instance.currencyRequsetStatus = RequestStatus.Updated;
                onError();
            });
        }