Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion BetaSeries.Net/Models/Oauth.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,59 @@
using BetaSeries.Net.Core;
using BetaSeries.Net.Exceptions;
using System.Threading.Tasks;

namespace BetaSeries.Net.Models
{
public abstract class OAUTH
{
#region Public Classes
private static string _device_code;
private static string _developerKey;
private static string _oautsecret;

public static void RegisterDeveloperKey(string key)
{
_developerKey = key;
}

public static void RegisterOAuthSecret(string secret)
{
_oautsecret = secret;
}

[Rest]
public class Access_token : RestMethod<Access_token> { }
public class Access_token : RestMethod<Access_token>
{
public static async System.Threading.Tasks.Task<dynamic> PollForAuthorization()
{
while (true)
{
try
{
dynamic result = await Post(new { client_id = _developerKey, client_secret = _oautsecret, code = _device_code });

RestHelper.RegisterUserToken(result.access_token.ToString());

return result;
}
catch (BetaSeriesException)
{
await Task.Delay(5000);
}
}
}
}

[Rest]
public class Device : RestMethod<Device>
{
public static async Task<dynamic> Post()
{
dynamic res = await RestHelper.Post<Device>(new { });
_device_code = res.device_code;
return res;
}
}
#endregion Public Classes
}
}
3 changes: 3 additions & 0 deletions BetaSeries.Net/Models/Shows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class Recommendations : RestMethod<Recommendations> { }
[Rest]
public class Search : RestMethod<Search> { }

[Rest]
public class Seasons : RestMethod<Seasons> { }

[Rest]
public class Show : RestMethod<Show> { }

Expand Down
14 changes: 14 additions & 0 deletions BetaSeries.Net/RestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static class RestHelper
private static string _apiBaseUri = "https://api.betaseries.com/";
private static string _apiVersion = "3.0";
private static string _developerKey = null;
private static string _userAgent = "BetaSeries.Net/0.0.1";
private static Dictionary<Type, string> _urlByType = new Dictionary<Type, string>();
private static string _userToken = null;

Expand Down Expand Up @@ -105,13 +106,24 @@ public static async Task<dynamic> Put<T>(dynamic parameters) where T : class
public static void RegisterDeveloperKey(string key)
{
_developerKey = key;
OAUTH.RegisterDeveloperKey(key);
}

public static void RegisterDeveloperKey(string key, string oauthsecret)
{
RegisterDeveloperKey(key);
OAUTH.RegisterOAuthSecret(oauthsecret);
}

public static void RegisterUserToken(string token)
{
_userToken = token;
}

public static void SetUserAgent(string userAgent)
{
_userAgent = userAgent;
}
#endregion Public Methods

#region Private Methods
Expand Down Expand Up @@ -177,6 +189,8 @@ private static async Task<dynamic> Request<T>(AllowedHttpVerbs method, string ur
client.BaseAddress = new Uri(_apiBaseUri);
client.DefaultRequestHeaders.Add("X-BetaSeries-Key", _developerKey);
client.DefaultRequestHeaders.Add("X-BetaSeries-Version", _apiVersion);
client.DefaultRequestHeaders.UserAgent.ParseAdd(_userAgent);


//add usertoken
if (_userToken != null)
Expand Down