private static string GetDefaultUrl(this IEnumerable <ChannelEndpoint> endpoints) { string result = string.Empty; ChannelEndpoint endpoint = endpoints.FirstOrDefault(); if (endpoint != null && endpoint.Url != null) { result = endpoint.Url.ToString(); } return(result); }
/// <summary> /// Creates an instance of ChannelEndpointData class from an instance of ChannelEndpoint. /// </summary> /// <param name="endpoint">Channel endpoint to copy into newly created instance.</param> public ChannelEndpointData(ChannelEndpoint endpoint) { if (endpoint == null) { throw new ArgumentNullException("endpoint"); } if (endpoint.Url != null) { Url = endpoint.Url.AbsoluteUri; } Protocol = endpoint.Protocol.ToString(); }
/// <summary> /// Live endpoint data... need to consume by games instead. /// </summary> /// <returns></returns> public async Task <Response <string> > ConsumeLive() { Response <string> response = new Response <string>(); string query = "http://api.azubu.tv/public/channel/live/list"; try { response = await VisitEndpointAsync(query); response.Query = query; List <ChannelEndpoint> cache = new List <ChannelEndpoint>(); BsonDocument doc = BsonDocument.Parse(response.Result); int cnt = doc[0].AsBsonArray.Count; foreach (var _doc in doc[0].AsBsonArray) { ChannelEndpoint temp = new ChannelEndpoint(); temp.ApiId = _doc["user"]["id"].ToString(); //temp.Game = need to find a way to populate friggin' games. temp.Name = (string)_doc["user"]["username"]; temp.EndpointUrl = (string)_doc["url_channel"]; temp.TotalViewCount = (int)_doc["view_count"]; temp.OrigionalCacheDate = DateTime.Now; temp.LatesteCacheDate = DateTime.Now; cache.Add(temp); } MongoAccess mongo = new MongoAccess(_config.ConnectionStrings["local"], "stream_cache"); var col = mongo.DBContext.GetCollection <ChannelEndpoint>("azubu"); await col.InsertManyAsync(cache); response.Result = "Insert successful"; } catch (Exception ex) { response.ReceiveException(ex, MethodBase.GetCurrentMethod()); } return(response); }
public async Task <Response <string> > ConsumeFeatured() { Response <string> response = new Response <string>(); ChannelEndpointCollection channelEndpoints = new ChannelEndpointCollection("https://api.twitch.tv/kraken/streams/featured?limit=100"); try { for (int i = 0; i <= 4; i++) { channelEndpoints.SetQuery(i); response = await VisitEndpointAsync(channelEndpoints.Query); BsonDocument doc = BsonDocument.Parse(response.Result); foreach (var _doc in doc["featured"].AsBsonArray) { //i'd like to be able for this to be configurable in a separate class //so that you could iterate through a collection of array indexes to set the object's properties ChannelEndpoint temp = new ChannelEndpoint(); temp.ApiId = (string)_doc["stream"]["channel"]["_id"]; temp.Name = (string)_doc["stream"]["channel"]["name"]; temp.Game = (string)_doc["stream"]["game"]; temp.Url = (string)_doc["stream"]["channel"]["url"]; temp.TotalViewCount = (int)_doc["stream"]["channel"]["views"]; channelEndpoints.Cache.Add(temp); } //a representation of a database to cache model response.Consume(await channelEndpoints.SaveCache(new MongoAccess(_config.ConnectionStrings["local"], "stream_cache"), "twitch")); Thread.Sleep(10000); } } catch (Exception ex) { response.ReceiveException(ex, MethodBase.GetCurrentMethod()); } return(response); }
public ChannelConfigurationInfo Configure(HttpListener httpChannel, Type channel, MethodInfo method, string baseURL) { ChannelEndpoint endpoint = new ChannelEndpoint(); ChannelAttribute channelAttr = channel.GetCustomAttribute <ChannelAttribute>(); if (!String.IsNullOrEmpty(channelAttr.Name)) { endpoint.URL = "/channels/" + channelAttr.Name + "/" + method.Name + "/"; } else { endpoint.URL = "/channels/" + channel.Name + "/" + method.Name + "/"; } endpoint.Name = channel.Name + "." + method.Name; ChannelMethodAttribute channelMethod = method.GetCustomAttribute <ChannelMethodAttribute>(); AuthorizeChannelAttribute authAttr = channel.GetCustomAttribute <AuthorizeChannelAttribute>(); ChannelAuthenticationSchemes channelSchema = channelMethod.Schema; ChannelHttpMethod httpMethod = channelMethod.HttpMethod; string methodURL = string.Empty; if (baseURL == null) { methodURL = "http://localhost:4200" + endpoint.URL; } else { methodURL = baseURL + endpoint.URL; } bool httpAuthRequired = false; //Start hosting httpChannel.Prefixes.Add(methodURL); if (authAttr != null) { if (authAttr.Schema != ChannelAuthenticationSchemes.Anonymous) { httpAuthRequired = true; } } //ChannelMethod can override ChannelAttribute Authentication Schemes if (channelSchema != ChannelAuthenticationSchemes.Anonymous) { httpAuthRequired = true; } else { if (authAttr != null) { channelSchema = authAttr.Schema; } } return(new ChannelConfigurationInfo { ChannelAttribute = channelAttr, MethodAttribute = channelMethod, MethodUrl = methodURL, HttpMethod = httpMethod, AuthScheme = channelSchema, AuthorizeAttribute = authAttr, AuthenticationRequired = httpAuthRequired, Endpoint = endpoint }); }