Added Status Code to models

This commit is contained in:
Jonas Dellinger 2017-05-31 18:17:07 +02:00
parent 3184d5569b
commit 1c6f317dda
3 changed files with 14 additions and 6 deletions

View File

@ -9,14 +9,16 @@ namespace SpotifyAPI.Web.Models
[JsonProperty("error")]
public Error Error { get; set; }
private WebHeaderCollection _headers;
private ResponseInfo _info;
public bool HasError() => Error != null;
internal void AddResponseInfo(ResponseInfo info) => _headers = info.Headers;
internal void AddResponseInfo(ResponseInfo info) => _info = info;
public string Header(string key) => _headers?.Get(key);
public string Header(string key) => _info.Headers?.Get(key);
public WebHeaderCollection Headers() => _headers;
public WebHeaderCollection Headers() => _info.Headers;
public HttpStatusCode StatusCode() => _info.StatusCode;
}
}

View File

@ -6,6 +6,8 @@ namespace SpotifyAPI.Web.Models
{
public WebHeaderCollection Headers { get; set; }
public HttpStatusCode StatusCode { get; set; }
public static readonly ResponseInfo Empty = new ResponseInfo();
}
}

View File

@ -43,8 +43,9 @@ namespace SpotifyAPI.Web
}
using (HttpResponseMessage response = Task.Run(() => client.GetAsync(url)).Result)
{
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo()
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
{
StatusCode = response.StatusCode,
Headers = ConvertHeaders(response.Headers)
}, Task.Run(() => response.Content.ReadAsByteArrayAsync()).Result);
}
@ -64,8 +65,9 @@ namespace SpotifyAPI.Web
}
using (HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false))
{
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo()
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
{
StatusCode = response.StatusCode,
Headers = ConvertHeaders(response.Headers)
}, await response.Content.ReadAsByteArrayAsync());
}
@ -116,6 +118,7 @@ namespace SpotifyAPI.Web
{
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
{
StatusCode = response.StatusCode,
Headers = ConvertHeaders(response.Headers)
}, Task.Run(() => response.Content.ReadAsByteArrayAsync()).Result);
}
@ -142,6 +145,7 @@ namespace SpotifyAPI.Web
{
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
{
StatusCode = response.StatusCode,
Headers = ConvertHeaders(response.Headers)
}, await response.Content.ReadAsByteArrayAsync());
}