Spotify.NET/SpotifyAPI.Web/Models/Token.cs

47 lines
1.1 KiB
C#
Raw Permalink Normal View History

using Newtonsoft.Json;
using System;
namespace SpotifyAPI.Web.Models
{
public class Token
{
2015-07-26 13:02:22 +01:00
public Token()
{
CreateDate = DateTime.Now;
}
[JsonProperty("access_token")]
2016-03-31 11:08:23 +01:00
public string AccessToken { get; set; }
2015-07-26 13:02:22 +01:00
[JsonProperty("token_type")]
2016-03-31 11:08:23 +01:00
public string TokenType { get; set; }
2015-07-26 13:02:22 +01:00
[JsonProperty("expires_in")]
public double ExpiresIn { get; set; }
2015-07-26 13:02:22 +01:00
[JsonProperty("refresh_token")]
2016-03-31 11:08:23 +01:00
public string RefreshToken { get; set; }
2015-07-26 13:02:22 +01:00
[JsonProperty("error")]
2016-03-31 11:08:23 +01:00
public string Error { get; set; }
2015-07-26 13:02:22 +01:00
[JsonProperty("error_description")]
2016-03-31 11:08:23 +01:00
public string ErrorDescription { get; set; }
public DateTime CreateDate { get; set; }
/// <summary>
/// Checks if the token has expired
/// </summary>
/// <returns></returns>
public bool IsExpired()
{
return CreateDate.Add(TimeSpan.FromSeconds(ExpiresIn)) <= DateTime.Now;
}
public bool HasError()
{
return Error != null;
}
}
2015-07-26 13:02:22 +01:00
}