public Task <bool> GameAnalyticsAsync(string callbackUrl, Enums.WebhookCallMode mode, string gameId, TimeSpan?duration = null, string signingSecret = null, string authToken = null) { Api.Settings.DynamicScopeValidation(AuthScopes.Helix_Analytics_Read_Games, authToken); var leaseSeconds = (int)ValidateTimespan(duration).TotalSeconds; return(PerformWebhookRequestAsync(mode, $"https://api.twitch.tv/helix/analytics/games?game_id={gameId}", callbackUrl, leaseSeconds, signingSecret)); }
private async Task <bool> performWebhookRequestAsync(Enums.WebhookCallMode mode, string topicUrl, string callbackUrl, int leaseSeconds, string signingSecret = null) { List <KeyValuePair <string, string> > getParams = new List <KeyValuePair <string, string> >(); if (mode == Enums.WebhookCallMode.Subscribe) { getParams.Add(new KeyValuePair <string, string>("hub.mode", "subscribe")); } else { getParams.Add(new KeyValuePair <string, string>("hub.mode", "unsubscribe")); } getParams.Add(new KeyValuePair <string, string>("hub.topic", topicUrl)); getParams.Add(new KeyValuePair <string, string>("hub.callback", callbackUrl)); getParams.Add(new KeyValuePair <string, string>("hub.lease_seconds", leaseSeconds.ToString())); if (signingSecret != null) { getParams.Add(new KeyValuePair <string, string>("hub.secret", signingSecret)); } var resp = await Api.PostAsync("https://api.twitch.tv/helix/webhooks/hub", null, getParams); if (resp.Key == 202) { return(true); } else { return(false); } }
private async Task <bool> PerformWebhookRequestAsync(Enums.WebhookCallMode mode, string topicUrl, string callbackUrl, int leaseSeconds, string signingSecret = null, string accessToken = null) { var getParams = new List <KeyValuePair <string, string> > { mode == Enums.WebhookCallMode.Subscribe ? new KeyValuePair <string, string>("hub.mode", "subscribe") : new KeyValuePair <string, string>("hub.mode", "unsubscribe"), new KeyValuePair <string, string>("hub.topic", topicUrl), new KeyValuePair <string, string>("hub.callback", callbackUrl), new KeyValuePair <string, string>("hub.lease_seconds", leaseSeconds.ToString()) }; if (signingSecret != null) { getParams.Add(new KeyValuePair <string, string>("hub.secret", signingSecret)); } var resp = await Api.TwitchPostAsync("/webhooks/hub", ApiVersion.Helix, null, getParams, accessToken : accessToken).ConfigureAwait(false); return(resp.Key == 202); }
public async Task <bool> StreamUpDown(string callbackUrl, Enums.WebhookCallMode mode, string userId, TimeSpan?duration = null, string signingSecret = null) { var leaseSeconds = (int)ValidateTimespan(duration).TotalSeconds; return(await PerformWebhookRequestAsync(mode, $"https://api.twitch.tv/helix/streams?user_id={userId}", callbackUrl, leaseSeconds, signingSecret)); }
public async Task <bool> UserFollowsUser(string callbackUrl, Enums.WebhookCallMode mode, string userInitiator, string userReceiverId, TimeSpan?duration = null, string signingSecret = null) { var leaseSeconds = (int)ValidateTimespan(duration).TotalSeconds; return(await PerformWebhookRequestAsync(mode, $"https://api.twitch.tv/helix/users/follows?to_id={userReceiverId}", callbackUrl, leaseSeconds, signingSecret)); }
public Task <bool> UserChangedAsync(string callbackUrl, Enums.WebhookCallMode mode, int id, TimeSpan?duration = null, string signingSecret = null) { var leaseSeconds = (int)ValidateTimespan(duration).TotalSeconds; return(PerformWebhookRequestAsync(mode, $"https://api.twitch.tv/helix/users?id={id}", callbackUrl, leaseSeconds, signingSecret)); }
public Task <bool> UserReceivesFollowerAsync(string callbackUrl, Enums.WebhookCallMode mode, string userReceiverId, TimeSpan?duration = null, string signingSecret = null, string accessToken = null) { var leaseSeconds = (int)ValidateTimespan(duration).TotalSeconds; return(PerformWebhookRequestAsync(mode, $"https://api.twitch.tv/helix/users/follows?first=1&to_id={userReceiverId}", callbackUrl, leaseSeconds, signingSecret, accessToken)); }
public async Task <bool> UserFollowsSomeoneAsync(string callbackUrl, Enums.WebhookCallMode mode, string userInitiatorId, TimeSpan?duration = null, string signingSecret = null) { int leaseSeconds = (int)validateTimespan(duration).TotalSeconds; return(await performWebhookRequestAsync(mode, $"https://api.twitch.tv/helix/users/follows?first=1&from_id={userInitiatorId}", callbackUrl, leaseSeconds, signingSecret)); }