Skip to content

Commit

Permalink
Change how the Access Token can be used
Browse files Browse the repository at this point in the history
It can now be set at any time and you can check if it's valid.
  • Loading branch information
CryZe committed Aug 10, 2015
1 parent a988ca8 commit 5c86f92
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions SpeedrunComSharp/SpeedrunComClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,25 @@ public class SpeedrunComClient
public static readonly Uri APIUri = new Uri(BaseUri, "api/v1/");
public const string APIHttpHeaderRelation = "alternate http://www.speedrun.com/api";

internal string accessToken;
public string AccessToken { internal get; set; }

public bool IsAccessTokenValid
{
get
{
if (AccessToken == null)
return false;

try
{
Profile.GetProfile();
return true;
}
catch { }

return false;
}
}

public string UserAgent { get; private set; }
private Dictionary<Uri, dynamic> Cache { get; set; }
Expand All @@ -38,7 +56,7 @@ public SpeedrunComClient(string userAgent = "SpeedRunComSharp/1.0",
{
UserAgent = userAgent;
MaxCacheElements = maxCacheElements;
this.accessToken = accessToken;
this.AccessToken = accessToken;
Cache = new Dictionary<Uri, dynamic>();
Categories = new CategoriesClient(this);
Games = new GamesClient(this);
Expand Down Expand Up @@ -124,7 +142,7 @@ internal dynamic DoPostRequest(Uri uri, string postBody)
{
try
{
return JSON.FromUriPost(uri, UserAgent, accessToken, postBody);
return JSON.FromUriPost(uri, UserAgent, AccessToken, postBody);
}
catch (WebException ex)
{
Expand Down Expand Up @@ -167,7 +185,7 @@ internal dynamic DoRequest(Uri uri)
#endif
try
{
result = JSON.FromUri(uri, UserAgent, accessToken);
result = JSON.FromUri(uri, UserAgent, AccessToken);
}
catch (WebException ex)
{
Expand Down

0 comments on commit 5c86f92

Please sign in to comment.