From 221776242367600b440c26d189902235ecb9a653 Mon Sep 17 00:00:00 2001 From: exsersewo Date: Tue, 14 Aug 2018 20:00:47 +0100 Subject: [PATCH] Updated for breaking api change --- SysEx.Net/Client.cs | 4 ++-- SysEx.Net/SysEx.Net.csproj | 2 +- SysEx.Net/WebRequest.cs | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/SysEx.Net/Client.cs b/SysEx.Net/Client.cs index 616b609..bfad523 100644 --- a/SysEx.Net/Client.cs +++ b/SysEx.Net/Client.cs @@ -71,8 +71,8 @@ namespace SysEx.Net public async Task GetWeebActionGifAsync(GifType type) { - var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/actions/?action=" + type.ToString().ToLowerInvariant())); - return resp; + var resp = await WebRequest.GetRedirectUriAsync(new Uri("https://api.systemexit.co.uk/actions/?action=" + type.ToString().ToLowerInvariant())); + return resp.OriginalString; } public async Task GetWeebReactionGifAsync() diff --git a/SysEx.Net/SysEx.Net.csproj b/SysEx.Net/SysEx.Net.csproj index e096dad..fb0c64b 100644 --- a/SysEx.Net/SysEx.Net.csproj +++ b/SysEx.Net/SysEx.Net.csproj @@ -15,7 +15,7 @@ en-GB Library https://github.com/exsersewo/SysEx.Net/blob/master/LICENSE - 1.0.3 + 1.0.4 diff --git a/SysEx.Net/WebRequest.cs b/SysEx.Net/WebRequest.cs index 8b33801..40a4e5c 100644 --- a/SysEx.Net/WebRequest.cs +++ b/SysEx.Net/WebRequest.cs @@ -45,5 +45,28 @@ namespace SysEx.Net return null; } } + public static async Task GetRedirectUriAsync(Uri url) + { + try + { + var client = CreateWebRequest(url); + + var resp = (HttpWebResponse)(await client.GetResponseAsync()); + if (resp.StatusCode == (HttpStatusCode.OK | HttpStatusCode.Redirect)) + { + var uri = resp.ResponseUri; + resp.Dispose(); + client.Abort(); + return uri; + } + resp.Dispose(); + client.Abort(); + return null; + } + catch + { + return null; + } + } } }