Beispiel #1
0
        public PushSummary Push(string channelId, string title, string message)
        {
            var result = new PushSummary {
                Input = string.Format(@"{{""channel_tag"": ""{0}"", ""type"": ""note"", ""title"": ""{1}"", ""body"": ""{2}""}}", _valueEscaper(channelId), _valueEscaper(title), _valueEscaper(message))
            };
            var postData = Encoding.ASCII.GetBytes(result.Input);
            var request  = WebRequest.Create(PUSHES_URL);

            request.Method      = "POST";
            request.ContentType = "application/json";
            request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", _encodedAuthKey);
            request.ContentLength = postData.Length;
            var requestStream = request.GetRequestStream();

            requestStream.Write(postData, 0, postData.Length);
            try
            {
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    result = _resultPropertiesSetter(response, result);
                }
            }
            catch (WebException e)
            {
                using (var response = (HttpWebResponse)e.Response)
                {
                    result = _resultPropertiesSetter(response, result);
                }
            }
            return(result);
        }
Beispiel #2
0
        public bool WasSuccessful(PushSummary summary)
        {
            var result = summary.ResultCode == 200;

            return(result);
        }