コード例 #1
0
 /// <summary>
 /// Creates an Instance of the TwitchAPI Class.
 /// </summary>
 /// <param name="logger">Instance Of Logger, otherwise no logging is used,  </param>
 /// <param name="rateLimiter">Instance Of RateLimiter, otherwise no ratelimiter is used. </param>
 public TwitchAPI(ILoggerFactory loggerFactory = null, IRateLimiter rateLimiter = null, IHttpCallHandler http = null)
 {
     _logger         = loggerFactory?.CreateLogger <TwitchAPI>();
     _http           = http ?? new TwitchHttpClient(loggerFactory?.CreateLogger <TwitchHttpClient>());
     _rateLimiter    = rateLimiter ?? BypassLimiter.CreateLimiterBypassInstance();
     Analytics       = new Analytics(this);
     Auth            = new Auth(this);
     Badges          = new Badges(this);
     Bits            = new Bits(this);
     ChannelFeeds    = new ChannelFeeds(this);
     Channels        = new Channels(this);
     Chat            = new Chat(this);
     Clips           = new Clips(this);
     Collections     = new Collections(this);
     Communities     = new Communities(this);
     Entitlements    = new Entitlements(this);
     Games           = new Games(this);
     Ingests         = new Ingests(this);
     Root            = new Root(this);
     Search          = new Search(this);
     Streams         = new Streams(this);
     Teams           = new Teams(this);
     ThirdParty      = new ThirdParty(this);
     Undocumented    = new Undocumented(this);
     Users           = new Users(this);
     Videos          = new Videos(this);
     Webhooks        = new Webhooks(this);
     Debugging       = new Debugging();
     Settings        = new ApiSettings(this);
     _jsonSerializer = new TwitchLibJsonSerializer();
 }
コード例 #2
0
 /// <summary>
 /// Creates an Instance of the TwitchAPI Class.
 /// </summary>
 /// <param name="logger">Instance Of Logger, otherwise no logging is used,  </param>
 /// <param name="rateLimiter">Instance Of RateLimiter, otherwise no ratelimiter is used. </param>
 public TwitchAPI(ILogger <TwitchAPI> logger = null, IRateLimiter rateLimiter = null)
 {
     _logger         = logger;
     _http           = new HttpClient(new TwitchLibCustomHttpMessageHandler(new HttpClientHandler(), _logger));
     _rateLimiter    = rateLimiter ?? BypassLimiter.CreateLimiterBypassInstance();
     Auth            = new Auth(this);
     Blocks          = new Blocks(this);
     Badges          = new Badges(this);
     Bits            = new Bits(this);
     ChannelFeeds    = new ChannelFeeds(this);
     Channels        = new Channels(this);
     Chat            = new Chat(this);
     Clips           = new Clips(this);
     Collections     = new Collections(this);
     Communities     = new Communities(this);
     Follows         = new Follows(this);
     Games           = new Games(this);
     Ingests         = new Ingests(this);
     Root            = new Root(this);
     Search          = new Search(this);
     Streams         = new Streams(this);
     Subscriptions   = new Subscriptions(this);
     Teams           = new Teams(this);
     ThirdParty      = new ThirdParty(this);
     Undocumented    = new Undocumented(this);
     Users           = new Users(this);
     Videos          = new Videos(this);
     Webhooks        = new Webhooks(this);
     Debugging       = new Debugging();
     Settings        = new ApiSettings(this);
     _jsonSerializer = new TwitchLibJsonSerializer();
 }
コード例 #3
0
 public ApiBase(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler http)
 {
     Settings        = settings;
     _rateLimiter    = rateLimiter;
     _http           = http;
     _jsonSerializer = new TwitchLibJsonSerializer();
 }
コード例 #4
0
        /// <summary>
        /// Creates an Instance of the TwitchAPI Class.
        /// </summary>
        /// <param name="clientId">Twitch Client Id.</param>
        /// <param name="accessToken">Twitch Access Token.</param>
        /// <param name="rateLimit">Should RateLimit Requests?</param>
        /// <param name="rateLimiter">Instance Of RateLimiter. Useful if using multiple API instances on one connection and you wish to share the requests ratelimiter.</param>
        /// <param name="callsPerPeriod">Number of Requests per Period to rate limit to</param>
        /// <param name="ratePeriod">Period for Rate Limit (In Seconds)</param>
        public TwitchAPI(string clientId = null, string accessToken = null, bool rateLimit = true, IRateLimiter rateLimiter = null, int callsPerPeriod = 1, int ratePeriod = 1)
        {
            _rateLimiter = rateLimit ?
                           (rateLimiter ?? TimeLimiter.GetFromMaxCountByInterval(callsPerPeriod, TimeSpan.FromSeconds(ratePeriod)))
                : BypassLimiter.CreateLimiterBypassInstance();

            Auth            = new Auth(this);
            Blocks          = new Blocks(this);
            Badges          = new Badges(this);
            Bits            = new Bits(this);
            ChannelFeeds    = new ChannelFeeds(this);
            Channels        = new Channels(this);
            Chat            = new Chat(this);
            Clips           = new Clips(this);
            Collections     = new Collections(this);
            Communities     = new Communities(this);
            Follows         = new Follows(this);
            Games           = new Games(this);
            Ingests         = new Ingests(this);
            Root            = new Root(this);
            Search          = new Search(this);
            Streams         = new Streams(this);
            Subscriptions   = new Subscriptions(this);
            Teams           = new Teams(this);
            ThirdParty      = new ThirdParty(this);
            Undocumented    = new Undocumented(this);
            Users           = new Users(this);
            Videos          = new Videos(this);
            Webhooks        = new Webhooks(this);
            Debugging       = new Debugging();
            Settings        = new ApiSettings(this);
            _jsonSerializer = new TwitchLibJsonSerializer();

            if (!string.IsNullOrWhiteSpace(clientId))
            {
                Settings.ClientId = clientId;
            }
            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                Settings.AccessToken = accessToken;
            }
        }
コード例 #5
0
 public async static Task PostModelAsync(string url, Models.API.RequestModel model, string accessToken = null, API api = API.v5, string clientId = null)
 {
     await generalRequestAsync(url, "POST", TwitchLibJsonSerializer.SerializeObject(model), accessToken, api, clientId);
 }
コード例 #6
0
 public async static Task <T> PostGenericModelAsync <T>(string url, Models.API.RequestModel model, string accessToken = null, API api = API.v5, string clientId = null)
 {
     if (model != null)
     {
         return(JsonConvert.DeserializeObject <T>(await generalRequestAsync(url, "POST", TwitchLibJsonSerializer.SerializeObject(model), accessToken, api, clientId), TwitchLibJsonDeserializer));
     }
     else
     {
         return(JsonConvert.DeserializeObject <T>(await generalRequestAsync(url, "POST", "", accessToken, api), TwitchLibJsonDeserializer));
     }
 }