public async Task <Result <Location> > GetLocation(IATA iata) { var cacheResult = await _cachedFetcher.GetLocation(iata); if (cacheResult.IsSuccess) { return(cacheResult); } var teleportResult = await GetLocationFromCTeleport(iata); if (teleportResult.IsSuccess) { await _cachedFetcher.SetLocation(iata, teleportResult.Value); } return(teleportResult); }
private async Task <Result <Location> > GetLocationFromCTeleport(IATA iata) { try { var response = await _client.GetAsync(iata.Code); if (response.StatusCode != HttpStatusCode.OK) { return(Result.Fail <Location>(response.StatusCode.ToString())); } var data = await response.Content.ReadAsStringAsync(); var ctResponse = JsonConvert.DeserializeObject <CTResponse>(data); return(ctResponse.location.ToLocation()); } catch (Exception e) { return(Result.Fail <Location>(e.Message)); } }