/// <inheritdoc/>
        public async Task <ITriggerResult> TriggerAsync(string[] channelNames, string eventName, object data, ITriggerOptions options = null)
        {
            if (options == null)
            {
                options = new TriggerOptions();
            }

            var bodyData = CreateTriggerBody(channelNames, eventName, data, options);

            var request = _factory.Build(PusherMethod.POST, "/events", requestBody: bodyData);

            DebugTriggerRequest(request);

            var result = await _options.RestClient.ExecutePostAsync(request);

            DebugTriggerResponse(result);

            return(result);
        }
        private TriggerBody CreateTriggerBody(string[] channelNames, string eventName, object data, ITriggerOptions options)
        {
            ValidationHelper.ValidateChannelNames(channelNames);
            ValidationHelper.ValidateSocketId(options.SocketId);

            TriggerBody bodyData = new TriggerBody()
            {
                name     = eventName,
                data     = _options.JsonSerializer.Serialize(data),
                channels = channelNames
            };
            string channelName = null;

            if (channelNames != null && channelNames.Length > 0)
            {
                channelName = channelNames[0];
            }

            ValidationHelper.ValidateBatchEventData(bodyData.data, channelName, eventName, _options);

            if (string.IsNullOrEmpty(options.SocketId) == false)
            {
                bodyData.socket_id = options.SocketId;
            }

            return(bodyData);
        }
 /// <inheritdoc/>
 public async Task <ITriggerResult> TriggerAsync(string channelName, string eventName, object data, ITriggerOptions options = null)
 {
     return(await TriggerAsync(new[] { channelName }, eventName, data, options));
 }
 /// <inheritdoc/>
 public ITriggerResult Trigger(string channelName, string eventName, object data, ITriggerOptions options = null)
 {
     return(Trigger(new[] { channelName }, eventName, data, options));
 }
        private TriggerBody CreateTriggerBody(string[] channelNames, string eventName, object data, ITriggerOptions options)
        {
            ValidationHelper.ValidateChannelNames(channelNames);
            ValidationHelper.ValidateSocketId(options.SocketId);

            TriggerBody bodyData = new TriggerBody()
            {
                name     = eventName,
                data     = _options.JsonSerializer.Serialize(data),
                channels = channelNames
            };

            if (string.IsNullOrEmpty(options.SocketId) == false)
            {
                bodyData.socket_id = options.SocketId;
            }

            return(bodyData);
        }
Exemple #6
0
        /// <summary>
        /// Triggers an event on the specified channels.
        /// </summary>
        /// <param name="channelNames"></param>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="data">The data to be sent with the event. The event payload.</param>
        /// <param name="options">Additional options to be used when triggering the event. See <see cref="ITriggerOptions" />.</param>
        /// <returns>The result of the call to the REST API</returns>
        public ITriggerResult Trigger(string[] channelNames, string eventName, object data, ITriggerOptions options)
        {
            TriggerBody bodyData = new TriggerBody()
            {
                name     = eventName,
                data     = BodySerializer.Serialize(data),
                channels = channelNames
            };

            if (string.IsNullOrEmpty(options.SocketId) == false)
            {
                bodyData.socket_id = options.SocketId;
            }

            IRestResponse response = ExecuteTrigger(channelNames, eventName, bodyData);
            TriggerResult result   = new TriggerResult(response);

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// Triggers an event on the specified channel.
        /// </summary>
        /// <param name="channelName">The name of the channel the event should be triggered on.</param>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="data">The data to be sent with the event. The event payload.</param>
        /// <param name="options">Additional options to be used when triggering the event. See <see cref="ITriggerOptions" />.</param>
        /// <returns>The result of the call to the REST API</returns>
        public ITriggerResult Trigger(string channelName, string eventName, object data, ITriggerOptions options)
        {
            var channelNames = new string[] { channelName };

            return(Trigger(channelNames, eventName, data, options));
        }
Exemple #8
0
        /// <inheritdoc/>
        public void TriggerAsync(string[] channelNames, string eventName, object data, ITriggerOptions options, Action <ITriggerResult> callback)
        {
            var bodyData = CreateTriggerBody(channelNames, eventName, data, options);

            ExecuteTriggerAsync("/events", bodyData, baseResponse =>
            {
                if (callback != null)
                {
                    callback(new TriggerResult(baseResponse));
                }
            });
        }
Exemple #9
0
 /// <inheritdoc/>
 public void TriggerAsync(string channelName, string eventName, object data, ITriggerOptions options, Action <ITriggerResult> callback)
 {
     TriggerAsync(new string[] { channelName }, eventName, data, options, callback);
 }
Exemple #10
0
        /// <summary>
        /// Triggers an event on the specified channels.
        /// </summary>
        /// <param name="channelNames"></param>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="data">The data to be sent with the event. The event payload.</param>
        /// <param name="options">Additional options to be used when triggering the event. See <see cref="ITriggerOptions" />.</param>
        /// <returns>The result of the call to the REST API</returns>
        public ITriggerResult Trigger(string[] channelNames, string eventName, object data, ITriggerOptions options)
        {
            var           bodyData = CreateTriggerBody(channelNames, eventName, data, options);
            IRestResponse response = ExecuteTrigger("/events", bodyData);
            TriggerResult result   = new TriggerResult(response);

            return(result);
        }