A response from the Postmark API after a request sent with PostmarkClient.
Пример #1
0
        private static PostmarkResponse TryGetPostmarkResponse(RestResponseBase response)
        {
            PostmarkResponse result = null;
            var statusCode          = (int)response.StatusCode;

            if (statusCode == 200 || statusCode == 401 || statusCode == 422 || statusCode == 500)
            {
                try
                {
                    result = JsonConvert.DeserializeObject <PostmarkResponse>(response.Content, _settings);
                }
                catch (JsonReaderException)
                {
                    result = null;
                }
            }
            return(result);
        }
Пример #2
0
        private PostmarkResponse GetPostmarkResponse(RestRequest request)
        {
            var response = _client.Request(request);

            PostmarkResponse result;
            switch ((int) response.StatusCode)
            {
                case 200:
                    result = JsonConvert.DeserializeObject<PostmarkResponse>(response.Content, _settings);
                    result.Status = PostmarkStatus.Success;
                    break;
                case 401:
                case 422:
                    result = JsonConvert.DeserializeObject<PostmarkResponse>(response.Content, _settings);
                    result.Status = PostmarkStatus.UserError;
                    break;
                case 500:
                    result = JsonConvert.DeserializeObject<PostmarkResponse>(response.Content, _settings);
                    result.Status = PostmarkStatus.ServerError;
                    break;
                default:
                    result = new PostmarkResponse
                                 {
                                     Status = PostmarkStatus.Unknown,
                                     Message = response.StatusDescription
                                 };
                    break;
            }

            return result;
        }