/// <summary> /// Performs a POST REST request using the provided request URI for New Twitch API-wrapped data. /// </summary> /// <param name="requestUri">The request URI to use</param> /// <returns>A type-casted object of the contents of the response</returns> public async Task <T> PostDataResultAsync <T>(string requestUri) { NewTwitchAPIDataRestResult <T> result = await this.PostAsync <NewTwitchAPIDataRestResult <T> >(requestUri); if (result != null && result.data.Count > 0) { return(result.data.First()); } return(default(T)); }
/// <summary> /// Performs a GET REST request using the provided request URI for New Twitch API-wrapped data. /// </summary> /// <param name="requestUri">The request URI to use</param> /// <returns>A type-casted object of the contents of the response</returns> public async Task <IEnumerable <T> > GetDataResultAsync <T>(string requestUri) { NewTwitchAPIDataRestResult <T> result = await this.GetAsync <NewTwitchAPIDataRestResult <T> >(requestUri); if (result != null && result.data.Count > 0) { return(result.data); } return(new List <T>()); }
/// <summary> /// Performs a POST REST request using the provided request URI for New Twitch API-wrapped data. /// </summary> /// <param name="requestUri">The request URI to use</param> /// <param name="content">The post body content</param> /// <returns>A type-casted object of the contents of the response</returns> public async Task <T[]> PostDataResultAsync <T>(string requestUri, HttpContent content) { NewTwitchAPIDataRestResult <T> result = await this.PostAsync <NewTwitchAPIDataRestResult <T> >(requestUri, content); if (result != null && result.data != null && result.data.Count > 0) { return(result.data.ToArray()); } return(null); }
/// <summary> /// Updates the description of the current user. /// </summary> /// <param name="description">The description to set</param> /// <returns>The updated current user</returns> public async Task <UserModel> UpdateCurrentUserDescription(string description) { NewTwitchAPIDataRestResult <UserModel> result = await this.PutAsync <NewTwitchAPIDataRestResult <UserModel> >("users?description=" + AdvancedHttpClient.EncodeString(description)); if (result != null && result.data != null) { return(result.data.FirstOrDefault()); } return(null); }
/// <summary> /// Creates a new reward associated with the broadcaster with the specified information. /// </summary> /// <param name="broadcaster">The broadcaster to create the reward for</param> /// <param name="reward">The reward information</param> /// <returns>The created reward</returns> public async Task <CustomChannelPointRewardModel> CreateCustomReward(UserModel broadcaster, UpdatableCustomChannelPointRewardModel reward) { Validator.ValidateVariable(broadcaster, "broadcaster"); Validator.ValidateVariable(reward, "reward"); NewTwitchAPIDataRestResult <CustomChannelPointRewardModel> result = await this.PostAsync <NewTwitchAPIDataRestResult <CustomChannelPointRewardModel> >("channel_points/custom_rewards?broadcaster_id=" + broadcaster.id, AdvancedHttpClient.CreateContentFromObject(reward)); if (result != null && result.data != null) { return(result.data.FirstOrDefault()); } return(null); }
/// <summary> /// Updates an existing reward associated with the broadcaster with the specified information. /// </summary> /// <param name="broadcaster">The broadcaster to create the reward for</param> /// <param name="rewardID">The ID of the reward</param> /// <param name="updatableFields">The reward information to update</param> /// <returns>The updated reward</returns> public async Task <CustomChannelPointRewardModel> UpdateCustomReward(UserModel broadcaster, Guid rewardID, JObject updatableFields) { Validator.ValidateVariable(broadcaster, "broadcaster"); Validator.ValidateGuid(rewardID, "rewardID"); Validator.ValidateVariable(updatableFields, "updatableFields"); NewTwitchAPIDataRestResult <CustomChannelPointRewardModel> result = await this.PatchAsync <NewTwitchAPIDataRestResult <CustomChannelPointRewardModel> >($"channel_points/custom_rewards?broadcaster_id={broadcaster.id}&id={rewardID}", AdvancedHttpClient.CreateContentFromObject(updatableFields)); if (result != null && result.data != null) { return(result.data.FirstOrDefault()); } return(null); }
/// <summary> /// Updates the specified redemption for the specified reward associated with the broadcaster. /// </summary> /// <param name="broadcaster">The broadcaster to update rewards for</param> /// <param name="rewardID">ID of the Custom Reward the redemptions to be updated are for.</param> /// <param name="id">ID of the Custom Reward Redemption to update</param> /// <param name="status">The new status for the reward. Can be FULFILLED or CANCELED</param> /// <returns>The reward redemptions</returns> public async Task <CustomChannelPointRewardRedemptionModel> UpdateCustomRewardRedemptions(UserModel broadcaster, Guid rewardID, Guid id, string status) { Validator.ValidateVariable(broadcaster, "broadcaster"); Validator.ValidateGuid(rewardID, "rewardID"); Validator.ValidateGuid(id, "id"); Validator.ValidateString(status, "status"); CustomChannelPointRewardRedemptionUpdateModel redemption = new CustomChannelPointRewardRedemptionUpdateModel(); redemption.status = status; NewTwitchAPIDataRestResult <CustomChannelPointRewardRedemptionModel> result = await this.PatchAsync <NewTwitchAPIDataRestResult <CustomChannelPointRewardRedemptionModel> >($"channel_points/custom_rewards/redemptions?broadcaster_id={broadcaster.id}&reward_id={rewardID}&id={id}", AdvancedHttpClient.CreateContentFromObject(redemption)); if (result != null && result.data != null) { return(result.data.FirstOrDefault()); } return(null); }
/// <summary> /// Performs a GET REST request using the provided request URI for New Twitch API-wrapped data. /// </summary> /// <param name="requestUri">The request URI to use</param> /// <param name="maxResults">The maximum number of results. Will be either that amount or slightly more</param> /// <returns>A type-casted object of the contents of the response</returns> public async Task <IEnumerable <T> > GetPagedDataResultAsync <T>(string requestUri, int maxResults = 1) { if (!requestUri.Contains("?")) { requestUri += "?"; } else { requestUri += "&"; } Dictionary <string, string> queryParameters = new Dictionary <string, string>(); queryParameters.Add("first", ((maxResults > 100) ? 100 : maxResults).ToString()); List <T> results = new List <T>(); string cursor = null; do { if (!string.IsNullOrEmpty(cursor)) { queryParameters["after"] = cursor; } NewTwitchAPIDataRestResult <T> data = await this.GetAsync <NewTwitchAPIDataRestResult <T> >(requestUri + string.Join("&", queryParameters.Select(kvp => kvp.Key + "=" + kvp.Value))); cursor = null; if (data != null) { if (data.data != null) { results.AddRange(data.data); } cursor = data.Cursor; } }while (results.Count < maxResults && !string.IsNullOrEmpty(cursor)); return(results); }