/// <summary> /// Calls to Twitch Helix API and deseralizes to HelixData object. /// </summary> /// <param name="url">Specified url</param> /// <param name="channel">Target channel</param> /// <param name="callType">The API call type</param> /// <returns>Deserialized HelixData Object</returns> public async Task <HelixData> helixCall(string url, string channel, ApiCallType callType) { if (rateRemaining == 0) { Debug.WriteLine("Could not execute call. No more rate remaining."); return(null); } else { string result = ""; HelixData helixData = null; Debug.WriteLine($"Calling to {baseUrl}{url}"); try { using (HttpResponseMessage response = await httpClient.GetAsync(baseUrl + url)) using (HttpContent content = response.Content) { rateRemaining = Int32.Parse(response.Headers.GetValues("ratelimit-remaining").FirstOrDefault()); Debug.WriteLine($"Rate left: {rateRemaining}"); result = await content.ReadAsStringAsync(); Debug.WriteLine("Api call resulted in the following: " + result.Substring(0, 50) + "..."); helixData = JsonConvert.DeserializeObject <HelixData>(result); if (helixData.data.Count() > 0 && callType != ApiCallType.NoCall) { onHelixCallArgs?.Invoke(this, new OnHelixCallArgs { response = helixData, type = callType, channel = channel }); } } return(helixData); } catch (Exception e) { Debug.WriteLine(e.StackTrace); } return(helixData); } }
public ApiContext(ApiCallType callType, string uri, JsonObject request, JsonObject response) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (response == null) { throw new ArgumentNullException(nameof(response)); } ResultCode = ApiResultCode.Success; CallType = callType; Uri = uri; Request = request; Response = response; }
public QueueBasedApiContext(JsonObject brokerProperties, JsonObject message, Stopwatch processingStopwatch, ApiCallType callType, string uri, JsonObject request, JsonObject response) : base(callType, uri, request, response) { if (brokerProperties == null) { throw new ArgumentNullException(nameof(brokerProperties)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } if (processingStopwatch == null) { throw new ArgumentNullException(nameof(processingStopwatch)); } BrokerProperties = brokerProperties; Message = message; ProcessingStopwatch = processingStopwatch; }
public HelixHelper(string url, string channel, ApiCallType callType) { this.url = url; this.callType = callType; this.channel = channel; }