mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 15:06:26 +00:00
VSCode Formatter - Also bumped tests to net core 3.1
This commit is contained in:
parent
307d69945e
commit
466e61523d
@ -1,4 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Auth
|
namespace SpotifyAPI.Web.Auth
|
||||||
|
@ -18,13 +18,10 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
|
|
||||||
public ProxyConfig ProxyConfig { get; set; }
|
public ProxyConfig ProxyConfig { get; set; }
|
||||||
|
|
||||||
public AuthorizationCodeAuth(string redirectUri, string serverUri, Scope scope = Scope.None, string state = "")
|
public AuthorizationCodeAuth(string redirectUri, string serverUri, Scope scope = Scope.None, string state = "") : base("code", "AuthorizationCodeAuth", redirectUri, serverUri, scope, state)
|
||||||
: base("code", "AuthorizationCodeAuth", redirectUri, serverUri, scope, state)
|
{ }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public AuthorizationCodeAuth(string clientId, string secretId, string redirectUri, string serverUri, Scope scope = Scope.None, string state = "")
|
public AuthorizationCodeAuth(string clientId, string secretId, string redirectUri, string serverUri, Scope scope = Scope.None, string state = "") : this(redirectUri, serverUri, scope, state)
|
||||||
: this(redirectUri, serverUri, scope, state)
|
|
||||||
{
|
{
|
||||||
ClientId = clientId;
|
ClientId = clientId;
|
||||||
SecretId = secretId;
|
SecretId = secretId;
|
||||||
@ -130,7 +127,6 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AuthorizationCodeAuthController(IHttpContext context) : base(context)
|
public AuthorizationCodeAuthController(IHttpContext context) : base(context)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -27,8 +27,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(ClientId + ":" + ClientSecret));
|
string auth = Convert.ToBase64String(Encoding.UTF8.GetBytes(ClientId + ":" + ClientSecret));
|
||||||
|
|
||||||
List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>
|
List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>
|
||||||
{
|
{new KeyValuePair<string, string>("grant_type", "client_credentials")
|
||||||
new KeyValuePair<string, string>("grant_type", "client_credentials")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpClientHandler handler = ProxyConfig.CreateClientHandler(ProxyConfig);
|
HttpClientHandler handler = ProxyConfig.CreateClientHandler(ProxyConfig);
|
||||||
|
@ -9,8 +9,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
{
|
{
|
||||||
public class ImplicitGrantAuth : SpotifyAuthServer<Token>
|
public class ImplicitGrantAuth : SpotifyAuthServer<Token>
|
||||||
{
|
{
|
||||||
public ImplicitGrantAuth(string clientId, string redirectUri, string serverUri, Scope scope = Scope.None, string state = "") :
|
public ImplicitGrantAuth(string clientId, string redirectUri, string serverUri, Scope scope = Scope.None, string state = "") : base("token", "ImplicitGrantAuth", redirectUri, serverUri, scope, state)
|
||||||
base("token", "ImplicitGrantAuth", redirectUri, serverUri, scope, state)
|
|
||||||
{
|
{
|
||||||
ClientId = clientId;
|
ClientId = clientId;
|
||||||
}
|
}
|
||||||
@ -59,7 +58,6 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ImplicitGrantAuthController(IHttpContext context) : base(context)
|
public ImplicitGrantAuthController(IHttpContext context) : base(context)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using SpotifyAPI.Web.Enums;
|
using SpotifyAPI.Web.Enums;
|
||||||
|
using SpotifyAPI.Web.Models;
|
||||||
using Unosquare.Labs.EmbedIO;
|
using Unosquare.Labs.EmbedIO;
|
||||||
using Unosquare.Labs.EmbedIO.Constants;
|
using Unosquare.Labs.EmbedIO.Constants;
|
||||||
using Unosquare.Labs.EmbedIO.Modules;
|
using Unosquare.Labs.EmbedIO.Modules;
|
||||||
using SpotifyAPI.Web.Models;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net.Http;
|
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Auth
|
namespace SpotifyAPI.Web.Auth
|
||||||
{
|
{
|
||||||
@ -91,10 +91,9 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
int currentRetries = 0)
|
int currentRetries = 0)
|
||||||
{
|
{
|
||||||
FormUrlEncodedContent content = new FormUrlEncodedContent(new Dictionary<string, string>
|
FormUrlEncodedContent content = new FormUrlEncodedContent(new Dictionary<string, string>
|
||||||
{
|
{ { "grant_type", grantType },
|
||||||
{"grant_type", grantType},
|
{ "code", authorizationCode },
|
||||||
{"code", authorizationCode},
|
{ "refresh_token", refreshToken }
|
||||||
{"refresh_token", refreshToken}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -111,8 +110,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
if (currentRetries >= MaxGetTokenRetries)
|
if (currentRetries >= MaxGetTokenRetries)
|
||||||
{
|
{
|
||||||
@ -165,7 +163,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Token> ExchangeCodeAsync(string authorizationCode)
|
public async Task<Token> ExchangeCodeAsync(string authorizationCode)
|
||||||
{
|
{
|
||||||
Token token = await GetToken("authorization_code", authorizationCode: authorizationCode);
|
Token token = await GetToken("authorization_code", authorizationCode : authorizationCode);
|
||||||
if (token != null && !token.HasError() && !string.IsNullOrEmpty(token.AccessToken))
|
if (token != null && !token.HasError() && !string.IsNullOrEmpty(token.AccessToken))
|
||||||
{
|
{
|
||||||
SetAccessExpireTimer(token);
|
SetAccessExpireTimer(token);
|
||||||
@ -181,7 +179,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<Token> RefreshAuthAsync(string refreshToken)
|
public async Task<Token> RefreshAuthAsync(string refreshToken)
|
||||||
{
|
{
|
||||||
Token token = await GetToken("refresh_token", refreshToken: refreshToken);
|
Token token = await GetToken("refresh_token", refreshToken : refreshToken);
|
||||||
if (token != null && !token.HasError() && !string.IsNullOrEmpty(token.AccessToken))
|
if (token != null && !token.HasError() && !string.IsNullOrEmpty(token.AccessToken))
|
||||||
{
|
{
|
||||||
SetAccessExpireTimer(token);
|
SetAccessExpireTimer(token);
|
||||||
@ -194,8 +192,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
internal class TokenSwapAuthController : WebApiController
|
internal class TokenSwapAuthController : WebApiController
|
||||||
{
|
{
|
||||||
public TokenSwapAuthController(IHttpContext context) : base(context)
|
public TokenSwapAuthController(IHttpContext context) : base(context)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
[WebApiHandler(HttpVerbs.Get, "/auth")]
|
[WebApiHandler(HttpVerbs.Get, "/auth")]
|
||||||
public Task<bool> GetAuth()
|
public Task<bool> GetAuth()
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
using SpotifyAPI.Web.Enums;
|
|
||||||
using SpotifyAPI.Web.Models;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using SpotifyAPI.Web.Enums;
|
||||||
|
using SpotifyAPI.Web.Models;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Auth
|
namespace SpotifyAPI.Web.Auth
|
||||||
{
|
{
|
||||||
@ -69,7 +69,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
HostServerUri = hostServerUri;
|
HostServerUri = hostServerUri;
|
||||||
OpenBrowser = openBrowser;
|
OpenBrowser = openBrowser;
|
||||||
|
|
||||||
OnAccessTokenExpired += async (sender, e) =>
|
OnAccessTokenExpired += async(sender, e) =>
|
||||||
{
|
{
|
||||||
if (AutoRefresh)
|
if (AutoRefresh)
|
||||||
{
|
{
|
||||||
@ -127,8 +127,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
public static new AccessTokenExpiredEventArgs Empty { get; } = new AccessTokenExpiredEventArgs();
|
public static new AccessTokenExpiredEventArgs Empty { get; } = new AccessTokenExpiredEventArgs();
|
||||||
|
|
||||||
public AccessTokenExpiredEventArgs()
|
public AccessTokenExpiredEventArgs()
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When the authorization from Spotify expires. This will only occur if <see cref="AutoRefresh"/> is true.
|
/// When the authorization from Spotify expires. This will only occur if <see cref="AutoRefresh"/> is true.
|
||||||
@ -140,8 +139,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
public static new AuthSuccessEventArgs Empty { get; } = new AuthSuccessEventArgs();
|
public static new AuthSuccessEventArgs Empty { get; } = new AuthSuccessEventArgs();
|
||||||
|
|
||||||
public AuthSuccessEventArgs()
|
public AuthSuccessEventArgs()
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When an authorization attempt succeeds and gains authorization.
|
/// When an authorization attempt succeeds and gains authorization.
|
||||||
@ -202,7 +200,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
MaxGetTokenRetries = MaxGetTokenRetries,
|
MaxGetTokenRetries = MaxGetTokenRetries,
|
||||||
TimeAccessExpiry = AutoRefresh || TimeAccessExpiry
|
TimeAccessExpiry = AutoRefresh || TimeAccessExpiry
|
||||||
};
|
};
|
||||||
lastAuth.AuthReceived += async (sender, response) =>
|
lastAuth.AuthReceived += async(sender, response) =>
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(response.Error) || string.IsNullOrEmpty(response.Code))
|
if (!string.IsNullOrEmpty(response.Error) || string.IsNullOrEmpty(response.Code))
|
||||||
{
|
{
|
||||||
@ -241,7 +239,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
OnAuthSuccess?.Invoke(this, AuthSuccessEventArgs.Empty);
|
OnAuthSuccess?.Invoke(this, AuthSuccessEventArgs.Empty);
|
||||||
currentlyAuthorizing = false;
|
currentlyAuthorizing = false;
|
||||||
};
|
};
|
||||||
lastAuth.OnAccessTokenExpired += async (sender, e) =>
|
lastAuth.OnAccessTokenExpired += async(sender, e) =>
|
||||||
{
|
{
|
||||||
if (TimeAccessExpiry)
|
if (TimeAccessExpiry)
|
||||||
{
|
{
|
||||||
@ -267,7 +265,7 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
Interval = Timeout * 1000
|
Interval = Timeout * 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
while (currentlyAuthorizing && webApiTimeoutTimer.Enabled) ;
|
while (currentlyAuthorizing && webApiTimeoutTimer.Enabled);
|
||||||
|
|
||||||
// If a timeout occurred
|
// If a timeout occurred
|
||||||
if (lastWebApi == null && currentlyAuthorizing)
|
if (lastWebApi == null && currentlyAuthorizing)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
@ -26,7 +26,7 @@ namespace SpotifyAPI.Web.Examples.ASP
|
|||||||
.AddCookie()
|
.AddCookie()
|
||||||
.AddSpotify(options =>
|
.AddSpotify(options =>
|
||||||
{
|
{
|
||||||
var scopes = Scope.UserLibraryRead;
|
var scopes = Scope.UserLibraryRead | Scope.UserModifyPlaybackState;
|
||||||
options.Scope.Add(scopes.GetStringAttribute(","));
|
options.Scope.Add(scopes.GetStringAttribute(","));
|
||||||
|
|
||||||
options.SaveTokens = true;
|
options.SaveTokens = true;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using SpotifyAPI.Web.Auth;
|
using SpotifyAPI.Web.Auth;
|
||||||
using SpotifyAPI.Web.Enums;
|
using SpotifyAPI.Web.Enums;
|
||||||
@ -14,13 +14,13 @@ namespace SpotifyAPI.Web.Examples.CLI
|
|||||||
// ReSharper disable once UnusedParameter.Local
|
// ReSharper disable once UnusedParameter.Local
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
_clientId = string.IsNullOrEmpty(_clientId)
|
_clientId = string.IsNullOrEmpty(_clientId) ?
|
||||||
? Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID")
|
Environment.GetEnvironmentVariable("SPOTIFY_CLIENT_ID") :
|
||||||
: _clientId;
|
_clientId;
|
||||||
|
|
||||||
_secretId = string.IsNullOrEmpty(_secretId)
|
_secretId = string.IsNullOrEmpty(_secretId) ?
|
||||||
? Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID")
|
Environment.GetEnvironmentVariable("SPOTIFY_SECRET_ID") :
|
||||||
: _secretId;
|
_secretId;
|
||||||
|
|
||||||
Console.WriteLine("####### Spotify API Example #######");
|
Console.WriteLine("####### Spotify API Example #######");
|
||||||
Console.WriteLine("This example uses AuthorizationCodeAuth.");
|
Console.WriteLine("This example uses AuthorizationCodeAuth.");
|
||||||
@ -37,8 +37,6 @@ namespace SpotifyAPI.Web.Examples.CLI
|
|||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
auth.Stop(0);
|
auth.Stop(0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
|
private static async void AuthOnAuthReceived(object sender, AuthorizationCode payload)
|
||||||
@ -60,7 +58,7 @@ namespace SpotifyAPI.Web.Examples.CLI
|
|||||||
if (playlists.Items == null) return;
|
if (playlists.Items == null) return;
|
||||||
|
|
||||||
playlists.Items.ForEach(playlist => Console.WriteLine($"- {playlist.Name}"));
|
playlists.Items.ForEach(playlist => Console.WriteLine($"- {playlist.Name}"));
|
||||||
if(playlists.HasNextPage())
|
if (playlists.HasNextPage())
|
||||||
await PrintAllPlaylistTracks(api, await api.GetNextPageAsync(playlists));
|
await PrintAllPlaylistTracks(api, await api.GetNextPageAsync(playlists));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Tests
|
namespace SpotifyAPI.Web.Tests
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -67,7 +67,6 @@ namespace SpotifyAPI.Web.Tests
|
|||||||
_mock.Setup(client => client.DownloadJson<PublicProfile>(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>()))
|
_mock.Setup(client => client.DownloadJson<PublicProfile>(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>()))
|
||||||
.Returns(new Tuple<ResponseInfo, PublicProfile>(ResponseInfo.Empty, profile));
|
.Returns(new Tuple<ResponseInfo, PublicProfile>(ResponseInfo.Empty, profile));
|
||||||
|
|
||||||
|
|
||||||
_spotify.UseAuth = false;
|
_spotify.UseAuth = false;
|
||||||
Assert.AreEqual(profile, _spotify.GetPublicProfile("wizzler"));
|
Assert.AreEqual(profile, _spotify.GetPublicProfile("wizzler"));
|
||||||
_mock.Verify(client => client.DownloadJson<PublicProfile>(
|
_mock.Verify(client => client.DownloadJson<PublicProfile>(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Tests
|
namespace SpotifyAPI.Web.Tests
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Enums
|
namespace SpotifyAPI.Web.Enums
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Enums
|
namespace SpotifyAPI.Web.Enums
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Enums
|
namespace SpotifyAPI.Web.Enums
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Enums
|
namespace SpotifyAPI.Web.Enums
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Enums
|
namespace SpotifyAPI.Web.Enums
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Enums
|
namespace SpotifyAPI.Web.Enums
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Enums
|
namespace SpotifyAPI.Web.Enums
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using SpotifyAPI.Web.Models;
|
using SpotifyAPI.Web.Models;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web
|
namespace SpotifyAPI.Web
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
@ -18,8 +18,7 @@ namespace SpotifyAPI.Web.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class ErrorResponse : BasicModel
|
public class ErrorResponse : BasicModel
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
public class Error
|
public class Error
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using SpotifyAPI.Web.Enums;
|
using SpotifyAPI.Web.Enums;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web.Models
|
namespace SpotifyAPI.Web.Models
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
@ -55,11 +55,11 @@ namespace SpotifyAPI.Web.Models
|
|||||||
{
|
{
|
||||||
object value = info.GetValue(this);
|
object value = info.GetValue(this);
|
||||||
string name = info.GetCustomAttribute<StringAttribute>()?.Text;
|
string name = info.GetCustomAttribute<StringAttribute>()?.Text;
|
||||||
if(name == null || value == null)
|
if (name == null || value == null)
|
||||||
continue;
|
continue;
|
||||||
urlParams.Add(value is float valueAsFloat
|
urlParams.Add(value is float valueAsFloat ?
|
||||||
? $"{prefix}_{name}={valueAsFloat.ToString(CultureInfo.InvariantCulture)}"
|
$"{prefix}_{name}={valueAsFloat.ToString(CultureInfo.InvariantCulture)}" :
|
||||||
: $"{prefix}_{name}={value}");
|
$"{prefix}_{name}={value}");
|
||||||
}
|
}
|
||||||
if (urlParams.Count > 0)
|
if (urlParams.Count > 0)
|
||||||
return "&" + string.Join("&", urlParams);
|
return "&" + string.Join("&", urlParams);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@ -6,6 +5,7 @@ using System.Net.Http;
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using SpotifyAPI.Web.Models;
|
using SpotifyAPI.Web.Models;
|
||||||
|
|
||||||
namespace SpotifyAPI.Web
|
namespace SpotifyAPI.Web
|
||||||
@ -42,7 +42,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
AddHeaders(headers);
|
AddHeaders(headers);
|
||||||
}
|
}
|
||||||
using (HttpResponseMessage response = Task.Run(() => _client.GetAsync(url)).Result)
|
using(HttpResponseMessage response = Task.Run(() => _client.GetAsync(url)).Result)
|
||||||
{
|
{
|
||||||
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
||||||
{
|
{
|
||||||
@ -58,7 +58,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
AddHeaders(headers);
|
AddHeaders(headers);
|
||||||
}
|
}
|
||||||
using (HttpResponseMessage response = await _client.GetAsync(url).ConfigureAwait(false))
|
using(HttpResponseMessage response = await _client.GetAsync(url).ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
||||||
{
|
{
|
||||||
@ -83,7 +83,8 @@ namespace SpotifyAPI.Web
|
|||||||
|
|
||||||
public async Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url, Dictionary<string, string> headers = null)
|
public async Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url, Dictionary<string, string> headers = null)
|
||||||
{
|
{
|
||||||
Tuple<ResponseInfo, string> response = await DownloadAsync(url, headers).ConfigureAwait(false);try
|
Tuple<ResponseInfo, string> response = await DownloadAsync(url, headers).ConfigureAwait(false);
|
||||||
|
try
|
||||||
{
|
{
|
||||||
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
|
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
|
||||||
}
|
}
|
||||||
@ -116,7 +117,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
Content = new StringContent(body, _encoding)
|
Content = new StringContent(body, _encoding)
|
||||||
};
|
};
|
||||||
using (HttpResponseMessage response = Task.Run(() => _client.SendAsync(message)).Result)
|
using(HttpResponseMessage response = Task.Run(() => _client.SendAsync(message)).Result)
|
||||||
{
|
{
|
||||||
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
||||||
{
|
{
|
||||||
@ -137,7 +138,7 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
Content = new StringContent(body, _encoding)
|
Content = new StringContent(body, _encoding)
|
||||||
};
|
};
|
||||||
using (HttpResponseMessage response = await _client.SendAsync(message))
|
using(HttpResponseMessage response = await _client.SendAsync(message))
|
||||||
{
|
{
|
||||||
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
return new Tuple<ResponseInfo, byte[]>(new ResponseInfo
|
||||||
{
|
{
|
||||||
@ -192,7 +193,7 @@ namespace SpotifyAPI.Web
|
|||||||
return newHeaders;
|
return newHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddHeaders(Dictionary<string,string> headers)
|
private void AddHeaders(Dictionary<string, string> headers)
|
||||||
{
|
{
|
||||||
_client.DefaultRequestHeaders.Clear();
|
_client.DefaultRequestHeaders.Clear();
|
||||||
foreach (KeyValuePair<string, string> headerPair in headers)
|
foreach (KeyValuePair<string, string> headerPair in headers)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -9,13 +9,13 @@ namespace SpotifyAPI.Web
|
|||||||
{
|
{
|
||||||
public static string GetStringAttribute<T>(this T en, string separator = "") where T : struct, IConvertible
|
public static string GetStringAttribute<T>(this T en, string separator = "") where T : struct, IConvertible
|
||||||
{
|
{
|
||||||
Enum e = (Enum)(object)en;
|
Enum e = (Enum) (object) en;
|
||||||
IEnumerable<StringAttribute> attributes =
|
IEnumerable<StringAttribute> attributes =
|
||||||
Enum.GetValues(typeof(T))
|
Enum.GetValues(typeof(T))
|
||||||
.Cast<T>()
|
.Cast<T>()
|
||||||
.Where(v => e.HasFlag((Enum)(object)v))
|
.Where(v => e.HasFlag((Enum) (object) v))
|
||||||
.Select(v => typeof(T).GetField(v.ToString(CultureInfo.InvariantCulture)))
|
.Select(v => typeof(T).GetField(v.ToString(CultureInfo.InvariantCulture)))
|
||||||
.Select(f => f.GetCustomAttributes(typeof(StringAttribute), false)[0])
|
.Select(f => f.GetCustomAttributes(typeof(StringAttribute), false) [0])
|
||||||
.Cast<StringAttribute>();
|
.Cast<StringAttribute>();
|
||||||
|
|
||||||
List<string> list = new List<string>();
|
List<string> list = new List<string>();
|
||||||
@ -25,7 +25,7 @@ namespace SpotifyAPI.Web
|
|||||||
|
|
||||||
public static long ToUnixTimeMillisecondsPoly(this DateTime time)
|
public static long ToUnixTimeMillisecondsPoly(this DateTime time)
|
||||||
{
|
{
|
||||||
return (long)time.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
|
return (long) time.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user