public string buildJson_Playback(PluginConfiguration.Hook hooks, SessionInfo sessionInfo, PlaybackProgressEventArgs playbackData, string trigger) { if ((trigger == "Paused" || trigger == "Resumed") && string.IsNullOrEmpty(sessionInfo.NowPlayingItem.ToString())) { return("_redundant_"); } string playbackTicks = (string.IsNullOrEmpty(playbackData.PlaybackPositionTicks.ToString())) ? sessionInfo.PlayState.PositionTicks.ToString() : playbackData.PlaybackPositionTicks.ToString(); string msgPlayback = buildJson_BaseItem(hooks.removeQuotes, hooks.msgHook, sessionInfo.FullNowPlayingItem); return(msgPlayback.Replace("{Event}", testString(hooks.removeQuotes, trigger, true)). Replace("{ServerID}", testString(hooks.removeQuotes, _appHost.SystemId, true)). Replace("{ServerName}", testString(hooks.removeQuotes, _appHost.FriendlyName, true)). Replace("{UserID}", testString(hooks.removeQuotes, sessionInfo.UserId.ToString(), true)). Replace("{UserName}", testString(hooks.removeQuotes, sessionInfo.UserName, true)). Replace("{AppName}", testString(hooks.removeQuotes, sessionInfo.AppName, true)). Replace("{DeviceID}", testString(hooks.removeQuotes, sessionInfo.DeviceId.ToString(), true)). Replace("{DeviceName}", testString(hooks.removeQuotes, sessionInfo.DeviceName, true)). Replace("{DeviceIP}", testString(hooks.removeQuotes, sessionInfo.RemoteEndPoint.ToString(), true)). Replace("{SessionID}", testString(hooks.removeQuotes, sessionInfo.Id, true)). Replace("{SessionPlaybackPositionTicks}", testString(hooks.removeQuotes, playbackTicks, false)). Replace("{TimeStamp}", testString(hooks.removeQuotes, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), true))); }
public string buildJson_Added(PluginConfiguration.Hook hooks, BaseItem e, string trigger) { string msgAdded = buildJson_BaseItem(hooks.removeQuotes, hooks.msgHook, e); return(msgAdded.Replace("{Event}", testString(hooks.removeQuotes, trigger, true)). Replace("{ServerID}", testString(hooks.removeQuotes, _appHost.SystemId, true)). Replace("{ServerName}", testString(hooks.removeQuotes, _appHost.FriendlyName, true)). Replace("{TimeStamp}", testString(hooks.removeQuotes, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), true))); }
public async Task <bool> SendHook(PluginConfiguration.Hook h, string jsonString) { _logger.Debug("WebHook sent to {0}", h.URL); _logger.Debug(jsonString); using (var client = new HttpClient()) { var httpContent = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json"); var response = await client.PostAsync(h.URL, httpContent); var responseString = await response.Content.ReadAsStringAsync(); _logger.Debug(response.StatusCode.ToString()); } return(true); }