public static NasaNeoSet ProcessNeoFromJson(string json, DateTime date) { //went with dynamic here instead of JObject because I like the syntax better dynamic nasaNeoDynamic = JsonConvert.DeserializeObject(json); var result = new NasaNeoSet(); result.ElementCount = nasaNeoDynamic.element_count.Value; result.Links = new NasaNeoLinks() { Next = nasaNeoDynamic.links.next.Value, Prev = nasaNeoDynamic.links.prev.Value, Self = nasaNeoDynamic.links.self.Value }; result.ItemsByDate = new List <NasaNeoItemsForDate>(); var dateItems = nasaNeoDynamic.near_earth_objects.Children(); foreach (var item in dateItems) { DateTime itemDate = DateTime.Parse(item.Name); if (itemDate == date) { var allNeosForDate = item.Value; result.ItemsByDate.Add(GetNasaNeoFromJson(DateTime.Parse(item.Name), allNeosForDate)); // we only want the first item because we're only supporting one date for now break; } } return(result); }
public async Task <NasaNeoSet> GetNeoForDateAsync(DateTime neoDate) { var result = new NasaNeoSet(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Accept.Clear(); var stringTask = httpClient.GetStringAsync( nasaNeoUrl .Replace("{start-date}", neoDate.ToString("yyyy-MM-dd")) .Replace("{end-date}", neoDate.ToString("yyyy-MM-dd")) .Replace("{key}", nasaApiKey)); var json = await stringTask; return(NasaApiHelper.ProcessNeoFromJson(json, neoDate)); }
private SkillResponse NeoResponseDetail(NasaNeoSet neoForDate) { var textResult = new StringBuilder(10000); var ssmlResult = new StringBuilder(10000); var numResultsToReturn = Math.Min(ResultsPageSize, neoForDate.ElementCount); textResult.Append($"There are {neoForDate.ElementCount} threats to earth today."); if (numResultsToReturn < neoForDate.ElementCount) { textResult.Append($" Here are the top {ResultsPageSize}."); } ssmlResult.Append($"<speak>{_util.GetRandomMessage(Globals.SSML.RedAlert)}{textResult.ToString()}"); for (int i = 0; i < numResultsToReturn; i++) { // right now we're only supporting one item per date. Should change this to not be a list until we support more dates textResult.Append(GetTextResponseForNeo(neoForDate.ItemsByDate[0].NeoItems[i])); ssmlResult.Append(GetSSMLResponseForNeo(neoForDate.ItemsByDate[0].NeoItems[i])); } ssmlResult.Append("</speak>"); return(BuildResponse($"Threats for {neoForDate.ItemsByDate[0].Date.ToString("MM/dd/yyyy")}", textResult.ToString(), ssmlResult.ToString())); }