Skip to content

Commit 997d29c

Browse files
committed
Response Models -> no public set; Request models -> no set for collections
1 parent 28531ab commit 997d29c

74 files changed

Lines changed: 503 additions & 387 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.editorconfig‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ indent_size = 2
1313
indent_size = 2
1414

1515
[*.{cs,vb}]
16+
# Does not seem to work...
17+
dotnet_diagnostic.CA1303.severity = none
18+
dotnet_diagnostic.CA1056.severity = none
1619
# Sort using and Import directives with System.* appearing first
1720
dotnet_sort_system_directives_first = true
1821
dotnet_style_require_accessibility_modifiers = always:warning
@@ -26,3 +29,5 @@ dotnet_style_qualification_for_event = false:warning
2629
# Code-block preferences
2730
csharp_prefer_braces = true:warning
2831
csharp_prefer_simple_using_statement = true:warning
32+
33+
# Custom disabled

‎SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public interface IPlaylistsClient
2020
Task<Paging<SimplePlaylist>> GetUsers(string userId);
2121
Task<Paging<SimplePlaylist>> GetUsers(string userId, PlaylistGetUsersRequest request);
2222

23+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
2324
Task<FullPlaylist> Get(string playlistId);
25+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
2426
Task<FullPlaylist> Get(string playlistId, PlaylistGetRequest request);
2527

2628
Task<bool> ReplaceItems(string playlistId, PlaylistReplaceItemsRequest request);

‎SpotifyAPI.Web/Clients/Interfaces/IShowsClient.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ namespace SpotifyAPI.Web
44
{
55
public interface IShowsClient
66
{
7+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
78
Task<FullShow> Get(string showId);
9+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
810
Task<FullShow> Get(string showId, ShowRequest request);
911

1012
Task<ShowsResponse> GetSeveral(ShowsRequest request);

‎SpotifyAPI.Web/Clients/Interfaces/IUserProfileClient.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public interface IUserProfileClient
1919
/// <param name="userId"></param>
2020
/// <exception cref="APIUnauthorizedException">Thrown if the client is not authenticated.</exception>
2121
/// <returns></returns>
22+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
2223
Task<PublicUser> Get(string userId);
2324
}
2425
}

‎SpotifyAPI.Web/Clients/SimplePaginator.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SpotifyAPI.Web
77
{
88
public class SimplePaginator : IPaginator
99
{
10-
protected bool ShouldContinue<T>(List<T> results, Paging<T> page)
10+
protected virtual bool ShouldContinue<T>(List<T> results, Paging<T> page)
1111
{
1212
return true;
1313
}

‎SpotifyAPI.Web/Clients/SpotifyClientConfig.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static SpotifyClientConfig CreateDefault()
105105
public static SpotifyClientConfig CreateDefault(IAuthenticator authenticator)
106106
{
107107
return new SpotifyClientConfig(
108-
SpotifyUrls.API_V1,
108+
SpotifyUrls.APIV1,
109109
authenticator,
110110
new NewtonsoftJSONSerializer(),
111111
new NetHttpClient(),

‎SpotifyAPI.Web/Exceptions/APIException.cs‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1-
using System.Net;
21
using Newtonsoft.Json;
32
using Newtonsoft.Json.Linq;
43
using SpotifyAPI.Web.Http;
4+
using System;
5+
using System.Runtime.Serialization;
56

67
namespace SpotifyAPI.Web
78
{
8-
[System.Serializable]
9+
[Serializable]
910
public class APIException : System.Exception
1011
{
12+
public IResponse Response { get; set; }
13+
1114
public APIException(IResponse response) : base(ParseAPIErrorMessage(response))
1215
{
1316
Ensure.ArgumentNotNull(response, nameof(response));
1417

1518
Response = response;
1619
}
1720

21+
public APIException()
22+
{
23+
}
24+
25+
public APIException(string message) : base(message)
26+
{
27+
}
28+
29+
public APIException(string message, System.Exception innerException) : base(message, innerException)
30+
{
31+
}
32+
33+
protected APIException(SerializationInfo info, StreamingContext context) : base(info, context)
34+
{
35+
Response = info.GetValue("APIException.Response", typeof(IResponse)) as IResponse;
36+
}
37+
1838
private static string ParseAPIErrorMessage(IResponse response)
1939
{
2040
var body = response.Body as string;
@@ -38,6 +58,10 @@ private static string ParseAPIErrorMessage(IResponse response)
3858
return null;
3959
}
4060

41-
public IResponse Response { get; set; }
61+
public override void GetObjectData(SerializationInfo info, StreamingContext context)
62+
{
63+
base.GetObjectData(info, context);
64+
info.AddValue("APIException.Response", Response);
65+
}
4266
}
4367
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
using System.Runtime.Serialization;
2+
using System;
13
using SpotifyAPI.Web.Http;
24

35
namespace SpotifyAPI.Web
46
{
5-
[System.Serializable]
7+
[Serializable]
68
public class APIUnauthorizedException : APIException
79
{
810
public APIUnauthorizedException(IResponse response) : base(response) { }
11+
12+
public APIUnauthorizedException() { }
13+
14+
public APIUnauthorizedException(string message) : base(message) { }
15+
16+
public APIUnauthorizedException(string message, Exception innerException) : base(message, innerException) { }
17+
18+
protected APIUnauthorizedException(SerializationInfo info, StreamingContext context) : base(info, context) { }
919
}
1020
}

‎SpotifyAPI.Web/Http/APIConnector.cs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ object body
158158
Ensure.ArgumentNotNull(uri, nameof(uri));
159159
Ensure.ArgumentNotNull(method, nameof(method));
160160

161-
return new Request
161+
return new Request(parameters)
162162
{
163163
BaseAddress = _baseAddress,
164-
Parameters = parameters,
165164
Endpoint = uri,
166165
Method = method,
167166
Body = body
@@ -183,13 +182,13 @@ private async Task<IResponse> DoRequest(IRequest request)
183182
_httpLogger?.OnResponse(response);
184183
if (_retryHandler != null)
185184
{
186-
response = await _retryHandler?.HandleRetry(request, response, async (newRequest) =>
185+
response = await _retryHandler.HandleRetry(request, response, async (newRequest) =>
187186
{
188187
await _authenticator.Apply(newRequest).ConfigureAwait(false);
189188
var newResponse = await _httpClient.DoRequest(request).ConfigureAwait(false);
190189
_httpLogger?.OnResponse(newResponse);
191190
return newResponse;
192-
});
191+
}).ConfigureAwait(false);
193192
}
194193
ProcessErrors(response);
195194
return response;
@@ -214,7 +213,7 @@ public async Task<T> SendAPIRequest<T>(
214213
)
215214
{
216215
var request = CreateRequest(uri, method, parameters, body);
217-
IAPIResponse<T> apiResponse = await DoSerializedRequest<T>(request);
216+
IAPIResponse<T> apiResponse = await DoSerializedRequest<T>(request).ConfigureAwait(false);
218217
return apiResponse.Body;
219218
}
220219

@@ -226,11 +225,11 @@ public async Task<IResponse> SendAPIRequestDetailed(
226225
)
227226
{
228227
var request = CreateRequest(uri, method, parameters, body);
229-
var response = await DoSerializedRequest<object>(request);
228+
var response = await DoSerializedRequest<object>(request).ConfigureAwait(false);
230229
return response.Response;
231230
}
232231

233-
private void ProcessErrors(IResponse response)
232+
private static void ProcessErrors(IResponse response)
234233
{
235234
Ensure.ArgumentNotNull(response, nameof(response));
236235

‎SpotifyAPI.Web/Http/Interfaces/IAPIConnector.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public interface IAPIConnector
1414

1515
// IHTTPClient HTTPClient { get; }
1616

17+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
1718
Task<T> Get<T>(Uri uri);
19+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
1820
Task<T> Get<T>(Uri uri, IDictionary<string, string> parameters);
1921

2022
Task<T> Post<T>(Uri uri);

0 commit comments

Comments
 (0)