示例#1
0
        internal async Task <JsonMessageEnvelope> PostMessageAsync(YamsterNewMessage messageToPost)
        {
            var parameters = messageToPost.BuildParameters();

            try
            {
                byte[] result = await this.asyncRestCaller.PostFormAsync("/api/v1/messages", parameters);

                var untypedEnvelope = YamsterApi.ParseJsonResponse <JsonMessageEnvelopeUntyped>(result);
                var envelope        = ConvertArchiveMessageEnvelope(untypedEnvelope);
                return(envelope);
            }
            catch (WebException ex)
            {
                var response = (HttpWebResponse)ex.Response;
                if (response.StatusCode == HttpStatusCode.BadRequest)
                {
                    // Fish out the JSON error message from the response, e.g. something like this:
                    //   {"base":["Cannot reply to deleted message: 12345"]}
                    using (var reader = new StreamReader(ex.Response.GetResponseStream()))
                    {
                        string json = reader.ReadToEnd();
                        throw new YamsterProtocolException("POST failed:\r\n\r\n" + json);
                    }
                }
                throw;
            }
        }
示例#2
0
        public T ProcessRequest <T>(YamsterHttpRequest request)
        {
            AsyncRestCall call = CreateRequestObject(request);

            call.ProcessThreadsafe();
            byte[] bytes = call.GetResult();
            return(YamsterApi.ParseJsonResponse <T>(bytes));
        }
示例#3
0
        public async Task <T> ProcessRequestAsync <T>(YamsterHttpRequest request)
        {
            byte[] bytes = await this.ProcessRawRequestAsync(request);

            return(YamsterApi.ParseJsonResponse <T>(bytes));
        }