Пример #1
0
        private static bool CheckRequestContainsSocketIdParameter(IPusherRestRequest request, string expectedSocketId)
        {
            var parameter = request.GetContentAsJsonString();

            return(parameter.Contains("socket_id") &&
                   parameter.Contains(expectedSocketId));
        }
Пример #2
0
        private bool CheckRequestContainsPayload(IPusherRestRequest request, string channelName, string eventName, object eventData)
        {
            var expectedBody = new TriggerBody()
            {
                name     = eventName,
                channels = new[] { channelName },
                data     = JsonConvert.SerializeObject(eventData)
            };

            var expected = JsonConvert.SerializeObject(expectedBody);

            return(request.GetContentAsJsonString().Contains(expected));
        }
Пример #3
0
        ///<inheritDoc/>
        public async Task <TriggerResult> ExecutePostAsync(IPusherRestRequest pusherRestRequest)
        {
            if (pusherRestRequest.Method == PusherMethod.POST)
            {
                var content = new StringContent(pusherRestRequest.GetContentAsJsonString(), Encoding.UTF8, "application/json");

                var response = await _httpClient.PostAsync(pusherRestRequest.ResourceUri, content);

                var responseContent = await response.Content.ReadAsStringAsync();

                return(new TriggerResult(response, responseContent));
            }

            return(null);
        }
        ///<inheritDoc/>
        public TriggerResult ExecutePost(IPusherRestRequest pusherRestRequest)
        {
            if (pusherRestRequest.Method == PusherMethod.POST)
            {
                var content = new StringContent(pusherRestRequest.GetContentAsJsonString(), Encoding.UTF8, "application/json");

                _webClient.Headers["Content-Type"] = "application/json";
                var responseContent = _webClient.UploadString(pusherRestRequest.ResourceUri, "POST", pusherRestRequest.GetContentAsJsonString());

                return(new TriggerResult(new HttpResponseMessage()
                {
                    Content = new StringContent(responseContent), StatusCode = HttpStatusCode.OK
                }, responseContent));
            }

            return(null);
        }
        ///<inheritDoc/>
        public async Task <TriggerResult> ExecutePostAsync(IPusherRestRequest pusherRestRequest)
        {
            _httpClient.DefaultRequestHeaders.Clear();
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            _httpClient.DefaultRequestHeaders.Add("Pusher-Library-Name", _libraryName);
            _httpClient.DefaultRequestHeaders.Add("Pusher-Library-Version", _version);

            if (pusherRestRequest.Method == PusherMethod.POST)
            {
                var content = new StringContent(pusherRestRequest.GetContentAsJsonString(), Encoding.UTF8, "application/json");

                var response = await _httpClient.PostAsync(pusherRestRequest.ResourceUri, content);

                var responseContent = await response.Content.ReadAsStringAsync();

                return(new TriggerResult(response, responseContent));
            }

            return(null);
        }
Пример #6
0
 private static bool CheckRequestContainsSocketIdParameter(IPusherRestRequest request, string expectedSocketId)
 {
     var parameter = request.GetContentAsJsonString();
     return parameter.Contains("socket_id") &&
            parameter.Contains(expectedSocketId);
 }
Пример #7
0
        private bool CheckRequestContainsPayload(IPusherRestRequest request, string channelName, string eventName, object eventData)
        {
            var expectedBody = new TriggerBody()
            {
                name = eventName,
                channels = new[] { channelName },
                data = JsonConvert.SerializeObject(eventData)
            };

            var expected = JsonConvert.SerializeObject(expectedBody);

            return request.GetContentAsJsonString().Contains(expected);
        }