public static async Task <UserProfile> GetCurrentProfileAsync() { try { var userId = AuthenticationService.GetCurrentUserId(); if (userId == 0) { var file = Device.IO.File("Session.txt"); if (file.Exists()) { var data = file.ReadAllText(); userId = Convert.ToInt32(data); } else { return(null); } } var uri = $"{GlobalSettings.AuthenticationEndpoint}api/Profiles/{userId}"; var result = await BaseApi.Get <UserProfile>(uri, errorAction : OnError.Ignore); if (result != null) { // result.Result.PhotoUrl = string.IsNullOrEmpty(result.Result.PhotoUrl) ? "Images/profile_placeholder.png" : result.Result.PhotoUrl; result.PhotoUrl = "Images/profile_placeholder.png"; Settings.UserProfile = result; Settings.UserId = userId; } return(result); } catch { return(null); } }
public static async Task <WeatherInfo> GetWeatherInfoAsync() { var location = await Device.Location.GetCurrentPosition(); if (location != null) { var latitude = location.Latitude; var longitude = location.Longitude; var builder = new UriBuilder($"{GlobalSettings.OpenWeatherMapEndpoint}data/2.5/weather") { Query = $"lat={latitude}&lon={longitude}&units=imperial&appid={GlobalSettings.OpenWeatherMapAPIKey}" }; var uri = builder.ToString(); var response = await BaseApi.Get <OpenWeatherMapResponse>(uri); if (response?.cod == OkResponseCode) { var weatherInfo = new WeatherInfo { LocationName = response.name, Temp = response.main.temp, TempUnit = TempUnit.Fahrenheit }; return(weatherInfo); } Debug.WriteLine("OpenWeatherMap API answered with: " + ((response != null) ? $"Error code = {response.cod}." : "Invalid response.")); } // Default data for demo return(new WeatherInfo { LocationName = GlobalSettings.City, Temp = GlobalSettings.Temp, TempUnit = TempUnit.Fahrenheit }); }
public static async Task <Event[]> GetEvents() { var uri = $"{GlobalSettings.EventsEndpoint}api/Events/"; return(await BaseApi.Get <Event[]>(uri)); }
public static async Task <Event[]> GetEvents(Func <Event[], Task> refresher) { var uri = $"{GlobalSettings.EventsEndpoint}api/Events/"; return(await BaseApi.Get <Event[]>(uri, cacheChoice : ApiResponseCache.PreferThenUpdate, refresher : refresher)); }
public void Read(string userId) { BaseApi.Get(playerCollection, userId).completed += ReadUserCallback; }