public async Task <SubsModel> GetSubs(int broadcasterId, string userAccessToken, string cursor = null) { var url = "https://api.twitch.tv/helix/subscriptions"; url = QueryHelpers.AddQueryString(url, "broadcaster_id", broadcasterId.ToString()); if (cursor != null) { url = QueryHelpers.AddQueryString(url, "after", cursor); } HttpResponseMessage response = await _client.SendAsync(new HttpRequestMessage() { RequestUri = new Uri(url), Method = HttpMethod.Get, Headers = { { "Authorization", $"Bearer {userAccessToken}" } } }); string jsonString = await response.Content.ReadAsStringAsync(); SubsModel data = JsonConvert.DeserializeObject <SubsModel>(jsonString); return(data); }
// Get Subsidiaries public JsonResult GetAutoSubs(string Prefix, int empId) // Subsidiaries List { List <Subsidary> result; if (string.IsNullOrEmpty(Prefix)) { result = subsidiariesbusinessManager.GetUnmappedSubsidiariesByEmpID(empId); } else { result = subsidiariesbusinessManager.GetUnmappedSubsidiariesByEmpID(empId); result = result.Where(s => s.Name.ToLower().Contains(Prefix.ToLower())).ToList(); } var translatedResult = SubsModel.Translate(result); // to avoid circular reference return(Json(translatedResult, JsonRequestBehavior.AllowGet)); }
// autocomplete for subs public JsonResult GetAutoSubs(string Prefix) { List <Subsidary> result; List <Subsidary> all; if (string.IsNullOrEmpty(Prefix)) { all = subsidiariesbusinessManager.GetAll(); result = all.Except(searchSubs, new IdComparerSubs()).ToList(); } else { all = subsidiariesbusinessManager.GetAll(); result = all.Except(searchSubs, new IdComparerSubs()).ToList(); result = result.Where(s => s.Name.ToLower().Contains(Prefix.ToLower())).ToList(); } var translatedResult = SubsModel.Translate(result); return(Json(translatedResult, JsonRequestBehavior.AllowGet)); }
public async Task <int> GetSubsCountAsync(int streamId) { string userAccessToken = _userAccessTokenStore?.UserAccessToken?.AccessToken; if (userAccessToken == null) { return(-1); } SubsModel subs = await _twitchApiClient.GetSubs(streamId, userAccessToken); List <SubDataModel> subData = new List <SubDataModel>(subs.Data); while (subs.Pagination.Cursor != null) { subs = await _twitchApiClient.GetSubs(streamId, userAccessToken, subs.Pagination.Cursor); subData.AddRange(subs.Data); } return(subData.Count - 1); }