<commit_before>﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.RegularExpressions;

namespace RingCentral.Http
{
    public class ApiResponse : Headers
    {
        public string Body { get; private set; }
        private readonly HttpResponseMessage _response;

        public ApiResponse(HttpResponseMessage response)
        {
            Status = Convert.ToInt32(response.StatusCode);
            Body = response.Content.ReadAsStringAsync().Result;
            var headers = response.Content.Headers;

            _response = response;
            SetHeaders(headers);

            if (!OK)
            {
                throw new Exception(Error);
            }
        }

        public HttpResponseMessage Response
        {
            get
            {
                return _response;
            }
        }

        public HttpRequestMessage Request
        {
            get
            {
                return _response.RequestMessage;
            }
        }

        /// <summary>
        ///     Checks to be sure the status code is greater than or equal to 200 and less than 300
        /// </summary>
        /// <returns>bool value if status code is successful</returns>
        public bool OK
        {
            get
            {
                return Status >= 200 && Status < 300;
            }
        }

        /// <summary>
        ///     If header content is JSON it will return full formed and parsed json
        /// </summary>
        /// <returns>A JObject parsed body</returns>
        public JObject Json<commit_msg>Refactor code<commit_after>﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.RegularExpressions;

namespace RingCentral.Http
{
    public class ApiResponse : Headers
    {
        public string Body { get; private set; }

        public ApiResponse(HttpResponseMessage response)
        {
            Status = Convert.ToInt32(response.StatusCode);
            Body = response.Content.ReadAsStringAsync().Result;
            var headers = response.Content.Headers;

            Response = response;
            SetHeaders(headers);

            if (!OK)
            {
                throw new Exception(Error);
            }
        }

        public HttpResponseMessage Response { get; private set; }

        public HttpRequestMessage Request
        {
            get
            {
                return Response.RequestMessage;
            }
        }

        /// <summary>
        ///     Checks to be sure the status code is greater than or equal to 200 and less than 300
        /// </summary>
        /// <returns>bool value if status code is successful</returns>
        public bool OK
        {
            get
            {
                return Status >= 200 && Status < 300;
            }
        }

        /// <summary>
        ///     If header content is JSON it will return full formed and parsed json
        /// </summary>
        /// <returns>A JObject parsed body</returns>
        public JObject Json
{'fraction_non_alphanumeric': 0.07943625880845612, 'fraction_numerical': 0.008968609865470852, 'mean_word_length': 1.4785714285714286, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4127886', 'n_tokens_mistral': 770, 'n_tokens_neox': 726, 'n_words': 224}