Skip to content

Commit 15d8fd8

Browse files
committedJul 7, 2016
Merged headers branch
1 parent 8bde064 commit 15d8fd8

File tree

8 files changed

+294
-116
lines changed

8 files changed

+294
-116
lines changed
 

‎SpotifyAPI.Example/WebControl.cs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using SpotifyAPI.Web.Models;
55
using System;
66
using System.Collections.Generic;
7-
using System.Diagnostics;
87
using System.IO;
98
using System.Linq;
109
using System.Net;

‎SpotifyAPI.Tests/TestClass.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void ShouldGetPrivateProfile_WithoutAuth()
5050
public void ShouldGetPrivateProfile_WithAuth()
5151
{
5252
PrivateProfile profile = GetFixture<PrivateProfile>("private-user.json");
53-
_mock.Setup(client => client.DownloadJson<PrivateProfile>(It.IsAny<string>())).Returns(profile);
53+
_mock.Setup(client => client.DownloadJson<PrivateProfile>(It.IsAny<string>())).Returns(new Tuple<ResponseInfo, PrivateProfile>(null, profile));
5454

5555
_spotify.UseAuth = true;
5656
Assert.AreEqual(profile, _spotify.GetPrivateProfile());
@@ -61,7 +61,7 @@ public void ShouldGetPrivateProfile_WithAuth()
6161
public void ShouldGetPublicProfile()
6262
{
6363
PublicProfile profile = GetFixture<PublicProfile>("public-user.json");
64-
_mock.Setup(client => client.DownloadJson<PublicProfile>(It.IsAny<string>())).Returns(profile);
64+
_mock.Setup(client => client.DownloadJson<PublicProfile>(It.IsAny<string>())).Returns(new Tuple<ResponseInfo, PublicProfile>(null, profile));
6565

6666
Assert.AreEqual(profile, _spotify.GetPublicProfile("wizzler"));
6767
_mock.Verify(client => client.DownloadJson<PublicProfile>(It.Is<string>(str => ContainsValues(str, "/users/wizzler"))), Times.Exactly(1));

‎SpotifyAPI/SpotifyAPI.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="Web\Models\Recommendations.cs" />
9393
<Compile Include="Web\Models\RecommendationSeed .cs" />
9494
<Compile Include="Web\Models\RecommendationSeedGenres.cs" />
95+
<Compile Include="Web\Models\ResponseInfo.cs" />
9596
<Compile Include="Web\Models\SearchItem.cs" />
9697
<Compile Include="Web\Models\PrivateProfile.cs" />
9798
<Compile Include="Web\Models\GeneralModels.cs" />

‎SpotifyAPI/Web/IClient.cs

+13-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Threading.Tasks;
5+
using SpotifyAPI.Web.Models;
56

67
namespace SpotifyAPI.Web
78
{
@@ -14,44 +15,44 @@ public interface IClient : IDisposable
1415
/// </summary>
1516
/// <param name="url">An URL</param>
1617
/// <returns></returns>
17-
string Download(string url);
18+
Tuple<ResponseInfo, string> Download(string url);
1819

1920
/// <summary>
2021
/// Downloads data async from an URL and returns it
2122
/// </summary>
2223
/// <param name="url"></param>
2324
/// <returns></returns>
24-
Task<string> DownloadAsync(string url);
25+
Task<Tuple<ResponseInfo, string>> DownloadAsync(string url);
2526

2627
/// <summary>
2728
/// Downloads data from an URL and returns it
2829
/// </summary>
2930
/// <param name="url">An URL</param>
3031
/// <returns></returns>
31-
byte[] DownloadRaw(string url);
32+
Tuple<ResponseInfo, byte[]> DownloadRaw(string url);
3233

3334
/// <summary>
3435
/// Downloads data async from an URL and returns it
3536
/// </summary>
3637
/// <param name="url"></param>
3738
/// <returns></returns>
38-
Task<byte[]> DownloadRawAsync(string url);
39+
Task<Tuple<ResponseInfo, byte[]>> DownloadRawAsync(string url);
3940

4041
/// <summary>
4142
/// Downloads data from an URL and converts it to an object
4243
/// </summary>
4344
/// <typeparam name="T">The Type which the object gets converted to</typeparam>
4445
/// <param name="url">An URL</param>
4546
/// <returns></returns>
46-
T DownloadJson<T>(string url);
47+
Tuple<ResponseInfo, T> DownloadJson<T>(string url);
4748

4849
/// <summary>
4950
/// Downloads data async from an URL and converts it to an object
5051
/// </summary>
5152
/// <typeparam name="T">The Type which the object gets converted to</typeparam>
5253
/// <param name="url">An URL</param>
5354
/// <returns></returns>
54-
Task<T> DownloadJsonAsync<T>(string url);
55+
Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url);
5556

5657
/// <summary>
5758
/// Uploads data from an URL and returns the response
@@ -60,7 +61,7 @@ public interface IClient : IDisposable
6061
/// <param name="body">The Body-Data (most likely a JSON String)</param>
6162
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
6263
/// <returns></returns>
63-
string Upload(string url, string body, string method);
64+
Tuple<ResponseInfo, string> Upload(string url, string body, string method);
6465

6566
/// <summary>
6667
/// Uploads data async from an URL and returns the response
@@ -69,7 +70,7 @@ public interface IClient : IDisposable
6970
/// <param name="body">The Body-Data (most likely a JSON String)</param>
7071
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
7172
/// <returns></returns>
72-
Task<string> UploadAsync(string url, string body, string method);
73+
Task<Tuple<ResponseInfo, string>> UploadAsync(string url, string body, string method);
7374

7475
/// <summary>
7576
/// Uploads data from an URL and returns the response
@@ -78,7 +79,7 @@ public interface IClient : IDisposable
7879
/// <param name="body">The Body-Data (most likely a JSON String)</param>
7980
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
8081
/// <returns></returns>
81-
byte[] UploadRaw(string url, string body, string method);
82+
Tuple<ResponseInfo, byte[]> UploadRaw(string url, string body, string method);
8283

8384
/// <summary>
8485
/// Uploads data async from an URL and returns the response
@@ -87,7 +88,7 @@ public interface IClient : IDisposable
8788
/// <param name="body">The Body-Data (most likely a JSON String)</param>
8889
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
8990
/// <returns></returns>
90-
Task<byte[]> UploadRawAsync(string url, string body, string method);
91+
Task<Tuple<ResponseInfo, byte[]>> UploadRawAsync(string url, string body, string method);
9192

9293
/// <summary>
9394
/// Uploads data from an URL and converts the response to an object
@@ -97,7 +98,7 @@ public interface IClient : IDisposable
9798
/// <param name="body">The Body-Data (most likely a JSON String)</param>
9899
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
99100
/// <returns></returns>
100-
T UploadJson<T>(string url, string body, string method);
101+
Tuple<ResponseInfo, T> UploadJson<T>(string url, string body, string method);
101102

102103
/// <summary>
103104
/// Uploads data async from an URL and converts the response to an object
@@ -107,7 +108,7 @@ public interface IClient : IDisposable
107108
/// <param name="body">The Body-Data (most likely a JSON String)</param>
108109
/// <param name="method">The Upload-method (POST,DELETE,PUT)</param>
109110
/// <returns></returns>
110-
Task<T> UploadJsonAsync<T>(string url, string body, string method);
111+
Task<Tuple<ResponseInfo, T>> UploadJsonAsync<T>(string url, string body, string method);
111112

112113
/// <summary>
113114
/// Sets a specific Header

‎SpotifyAPI/Web/Models/BasicModel.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Newtonsoft.Json;
22
using System;
3+
using System.Net;
34

45
namespace SpotifyAPI.Web.Models
56
{
@@ -8,9 +9,14 @@ public abstract class BasicModel
89
[JsonProperty("error")]
910
public Error Error { get; set; }
1011

11-
public Boolean HasError()
12-
{
13-
return Error != null;
14-
}
12+
private WebHeaderCollection _headers;
13+
14+
public bool HasError() => Error != null;
15+
16+
public void AddResponseInfo(ResponseInfo info) => _headers = info.Headers;
17+
18+
public string Header(string key) => _headers?.Get(key);
19+
20+
public WebHeaderCollection Headers() => _headers;
1521
}
1622
}

‎SpotifyAPI/Web/Models/ResponseInfo.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Net;
2+
3+
namespace SpotifyAPI.Web.Models
4+
{
5+
public class ResponseInfo
6+
{
7+
public WebHeaderCollection Headers { get; set; }
8+
}
9+
}

0 commit comments

Comments
 (0)