Ejemplo n.º 1
0
        public async Task <List <NetatmoCurrentViewModel> > GetCurrentDataAsync()
        {
            try
            {
                var token = await m_Credentials.GetNetatmoOAuthAsync();

                if (string.IsNullOrEmpty(token.AccessToken) || string.IsNullOrEmpty(token.RefreshToken) || string.IsNullOrEmpty(Options.Value?.Netatmo?.DeviceId))
                {
                    Log.Error($"Failed to get current data from Netatmo API with accesstoken: '{token?.AccessToken}' and deviceid: '{Options.Value?.Netatmo?.DeviceId}'");
                    return(null);
                }

                var response = await m_HttpWrapper.GetAsync(
                    UrlBuilder.Netatmo.BuildStationUrl(token.AccessToken, Options.Value.Netatmo.DeviceId));

                var currentData = JsonConvert.DeserializeObject <NetatmoCurrentData>(response);

                return(NetatmoDtoMapper.MapToCurrent(currentData));
            }
            catch (Exception exception)
            {
                Log.Error(exception, $"Failed to get current data from Netatmo: '{exception.Message}'");
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(int page)
        {
            var houses = await httpWrapper.GetAsync <List <House> >(RelativePaths.HousesEndpoint, page);

            var navigationControls = LinkParser.Parse(houses.LinkHeader);

            ViewBag.controls = new NavigationControls(navigationControls);

            return(View(houses.HttpResponse));
        }
Ejemplo n.º 3
0
        public async Task <List <WunderlistViewModel> > GetDataAsync()
        {
            try
            {
                var(accessToken, clientId) = m_Credentials.GetWunderlistCredentials();

                if (!Options.Value.Wunderlist.Lists.Any())
                {
                    Log.Error("No lists specified for Wunderlist API. Update your env variable 'Wunderlist__Lists'.");
                    return(null);
                }

                var response = await m_HttpWrapper.GetAsync(
                    UrlBuilder.Wunderlist.BuildListsUrl(accessToken, clientId));

                var wunderlistItems = new List <WunderlistViewModel>();

                var tasks = new List <Task>();

                foreach (var data in FilterData(response))
                {
                    tasks.Add(Task.Run(async() =>
                    {
                        var foundTasks = await GetTaskItemsForListAsync(data.Id);
                        wunderlistItems.Add(WunderlistDtoMapper.MapToList(data.Name, foundTasks));
                    }));
                }

                await Task.WhenAll(tasks);

                return(wunderlistItems);
            }
            catch (Exception exception)
            {
                Log.Error(exception, $"Failed to get lists from Wunderlist: '{exception.Message}'");
                throw;
            }
        }