#pragma warning restore /// <summary> /// Gets a video url from gfycat /// </summary> /// <param name="apiUrl"></param> /// <returns></returns> private async Task <string> GetGfyCatGifUrl(string apiUrl) { // Return if we have nothing. if (apiUrl.Equals(String.Empty)) { return(String.Empty); } try { // Make the call string jsonReponse = await App.BaconMan.NetworkMan.MakeGetRequest(apiUrl); // Parse the data GfyCatDataContainer gfyData = JsonConvert.DeserializeObject <GfyCatDataContainer>(jsonReponse); // Validate the repsonse string mp4Url = gfyData.item.Mp4Url; if (String.IsNullOrWhiteSpace(mp4Url)) { throw new Exception("Gfycat response failed to parse"); } // Return the url return(mp4Url); } catch (Exception e) { App.BaconMan.MessageMan.DebugDia("failed to get image from gfycat", e); App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "FaileGfyCatApiCall", e); } return(String.Empty); }
#pragma warning restore /// <summary> /// Gets a video url from gfycat /// </summary> /// <param name="apiUrl"></param> /// <returns></returns> private async Task <string> GetGfyCatGifUrl(string apiUrl) { // Return if we have nothing. if (apiUrl.Equals(String.Empty)) { return(String.Empty); } try { // Make the call IHttpContent webResult = await App.BaconMan.NetworkMan.MakeGetRequest(apiUrl); // Get the input stream and json reader. // NOTE!! We are really careful not to use a string here so we don't have to allocate a huge string. IInputStream inputStream = await webResult.ReadAsInputStreamAsync(); using (StreamReader reader = new StreamReader(inputStream.AsStreamForRead())) using (JsonReader jsonReader = new JsonTextReader(reader)) { // Parse the Json as an object JsonSerializer serializer = new JsonSerializer(); GfyCatDataContainer gfyData = await Task.Run(() => serializer.Deserialize <GfyCatDataContainer>(jsonReader)); // Validate the response string mp4Url = gfyData.item.Mp4Url; if (String.IsNullOrWhiteSpace(mp4Url)) { throw new Exception("Gfycat response failed to parse"); } // Return the url return(mp4Url); } } catch (Exception e) { App.BaconMan.MessageMan.DebugDia("failed to get image from gfycat", e); App.BaconMan.TelemetryMan.ReportUnExpectedEvent(this, "FaileGfyCatApiCall", e); } return(String.Empty); }