<commit_before>﻿using CakeMail.RestClient.Exceptions;
using CakeMail.RestClient.Resources;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

namespace CakeMail.RestClient
{
	/// <summary>
	/// Core class for using the CakeMail Api
	/// </summary>
	public class CakeMailRestClient : ICakeMailRestClient
	{
		#region Fields

		private static readonly string _version = GetVersion();
		private readonly IRestClient _client;

		#endregion

		#region Properties

		/// <summary>
		/// The API key provided by CakeMail
		/// </summary>
		public string ApiKey { get; private set; }

		/// <summary>
		/// The web proxy
		/// </summary>
		public IWebProxy Proxy
		{
			get { return _client.Proxy; }
		}

		/// <summary>
		/// The user agent
		/// </summary>
		public string UserAgent
		{
			get { return _client.UserAgent; }
		}

		/// <summary>
		/// The timeout
		/// </summary>
		public int Timeout
		{
			get { return _client.Timeout; }
		}

		/// <summary>
		/// The URL where all API requests are sent
		/// </summary>
		public Uri BaseUrl
		{
			get { return _client.BaseUrl; }
		}


		/// <summary>
		/// The <see cref="Campaigns">Campaigns</see> resource
		/// </summary>
		public Campaigns Campaigns { get; private set; }

		/// <summary>
		/// The <see cref="Clients">Clients</see> resource
		/// </summary>
		public Clients Clients { get; private set; }

		/// <summary>
		/// The <see cref="Countries">Countries</see> resource
		/// </summary>
		public Countries Countries { get; private set; }

		/// <summary>
		/// The <see cref="Permissions">Permissions</see> resource
		/// </summary>
		public Permissions Permissions { get; private set; }

		/// <summary>
		/// The <see cref="Lists">Lists</see> resource
		/// </summary>
		public Lists Lists { get; private set; }

		/// <summary>
		/// The <see cref="Timezones">Timezones</see> resource
		/// </summary>
		public Timezones Timezones { get; private set; }

		/// <summary>
		/// The <see cref="Mailings">Mailings</see> resource
		/// </summary>
		public Mailings Mailings { get; private set; }

		/// <summary>
		/// The <see cref="Relays">Relays</see> resource
		/// </summary>
		public Relays Relays { get; private set; }

		/// <summary>
		/// The <see cref="Segments">Segments</see> resource
		/// </summary>
		public Segments Segments { get; private set; }

		/// <summary>
		/// The <see cref="Users">Users</see> resource
		/// </summary>
		public Users Users { get; private set; }

		/// <summary>
		/// The <see cref="SuppressionLists">SuppressionLists</see> resource
		/// </summary>
		public SuppressionLists SuppressionLists { get; private set; }

		/// <summary>
		/// The <see cref="Templates">Templates</see> resource
		/// </summary>
		public Templates Templates { get; private set; }

		/// <summary>
		/// The <see cref="Triggers">Triggers</see> resource
		/// </summary>
		public Triggers Triggers { get; private set; }

		#endregion

		#region Constructors and Destructors

		/// <summary>
		/// Initializes a new instance of the <see cref="CakeMailRestClient"/> class.
		/// </summary>
		/// <param name="apiKey">The API Key received from CakeMail</param>
		/// <param name="restClient">The rest client</param>
		public CakeMailRestClient(string apiKey, IRestClient restClient)
		{
			this.ApiKey = apiKey;
			_client = restClient;

			InitializeResources();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CakeMailRestClient"/> class.
		/// </summary>
		/// <param name="apiKey">The API Key received from CakeMail</param>
		/// <param name="host">The host where the API is hosted. The default is api.wbsrvc.com</param>
		/// <param name="timeout">Timeout in milliseconds for connection to web service. The default is 5000.</param>
		/// <param name="webProxy">The web proxy</param>
		public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int timeout = 5000, IWebProxy webProxy = null)
		{
			this.ApiKey = apiKey;

			_client = new RestSharp.RestClient("https://" + host)
			{
				Timeout = timeout,
				UserAgent = string.Format("CakeMail .NET REST Client {0}", _version),
				Proxy = webProxy
			};

			InitializeResources();
		}

		#endregion

		#region Internal Methods

		internal async Task<long> ExecuteCountRequestAsync(string urlPath, IEnumerable<KeyValuePair<string, object>> parameters, CancellationToken cancellationToken = default(CancellationToken))
		{
			return await ExecuteRequestAsync<long>(urlPath, parameters, "count", cancellationToken).ConfigureAwait(false);
		}

		internal async Task<T[]> ExecuteArrayRequestAsync<T>(string urlPath, IEnumerable<KeyValuePair<string, object>> parameters, string propertyName = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			return await ExecuteRequestAsync<T[]>(urlPath, parameters, propertyName, cancellationToken).ConfigureAwait(false);
		}
<commit_msg>Fix "The method 'ExecuteCountRequestAsync' do not need to use async/await" as suggested by AsyncFixer<commit_after>﻿using CakeMail.RestClient.Exceptions;
using CakeMail.RestClient.Resources;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

namespace CakeMail.RestClient
{
	/// <summary>
	/// Core class for using the CakeMail Api
	/// </summary>
	public class CakeMailRestClient : ICakeMailRestClient
	{
		#region Fields

		private static readonly string _version = GetVersion();
		private readonly IRestClient _client;

		#endregion

		#region Properties

		/// <summary>
		/// The API key provided by CakeMail
		/// </summary>
		public string ApiKey { get; private set; }

		/// <summary>
		/// The web proxy
		/// </summary>
		public IWebProxy Proxy
		{
			get { return _client.Proxy; }
		}

		/// <summary>
		/// The user agent
		/// </summary>
		public string UserAgent
		{
			get { return _client.UserAgent; }
		}

		/// <summary>
		/// The timeout
		/// </summary>
		public int Timeout
		{
			get { return _client.Timeout; }
		}

		/// <summary>
		/// The URL where all API requests are sent
		/// </summary>
		public Uri BaseUrl
		{
			get { return _client.BaseUrl; }
		}


		/// <summary>
		/// The <see cref="Campaigns">Campaigns</see> resource
		/// </summary>
		public Campaigns Campaigns { get; private set; }

		/// <summary>
		/// The <see cref="Clients">Clients</see> resource
		/// </summary>
		public Clients Clients { get; private set; }

		/// <summary>
		/// The <see cref="Countries">Countries</see> resource
		/// </summary>
		public Countries Countries { get; private set; }

		/// <summary>
		/// The <see cref="Permissions">Permissions</see> resource
		/// </summary>
		public Permissions Permissions { get; private set; }

		/// <summary>
		/// The <see cref="Lists">Lists</see> resource
		/// </summary>
		public Lists Lists { get; private set; }

		/// <summary>
		/// The <see cref="Timezones">Timezones</see> resource
		/// </summary>
		public Timezones Timezones { get; private set; }

		/// <summary>
		/// The <see cref="Mailings">Mailings</see> resource
		/// </summary>
		public Mailings Mailings { get; private set; }

		/// <summary>
		/// The <see cref="Relays">Relays</see> resource
		/// </summary>
		public Relays Relays { get; private set; }

		/// <summary>
		/// The <see cref="Segments">Segments</see> resource
		/// </summary>
		public Segments Segments { get; private set; }

		/// <summary>
		/// The <see cref="Users">Users</see> resource
		/// </summary>
		public Users Users { get; private set; }

		/// <summary>
		/// The <see cref="SuppressionLists">SuppressionLists</see> resource
		/// </summary>
		public SuppressionLists SuppressionLists { get; private set; }

		/// <summary>
		/// The <see cref="Templates">Templates</see> resource
		/// </summary>
		public Templates Templates { get; private set; }

		/// <summary>
		/// The <see cref="Triggers">Triggers</see> resource
		/// </summary>
		public Triggers Triggers { get; private set; }

		#endregion

		#region Constructors and Destructors

		/// <summary>
		/// Initializes a new instance of the <see cref="CakeMailRestClient"/> class.
		/// </summary>
		/// <param name="apiKey">The API Key received from CakeMail</param>
		/// <param name="restClient">The rest client</param>
		public CakeMailRestClient(string apiKey, IRestClient restClient)
		{
			this.ApiKey = apiKey;
			_client = restClient;

			InitializeResources();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CakeMailRestClient"/> class.
		/// </summary>
		/// <param name="apiKey">The API Key received from CakeMail</param>
		/// <param name="host">The host where the API is hosted. The default is api.wbsrvc.com</param>
		/// <param name="timeout">Timeout in milliseconds for connection to web service. The default is 5000.</param>
		/// <param name="webProxy">The web proxy</param>
		public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int timeout = 5000, IWebProxy webProxy = null)
		{
			this.ApiKey = apiKey;

			_client = new RestSharp.RestClient("https://" + host)
			{
				Timeout = timeout,
				UserAgent = string.Format("CakeMail .NET REST Client {0}", _version),
				Proxy = webProxy
			};

			InitializeResources();
		}

		#endregion

		#region Internal Methods

		internal Task<long> ExecuteCountRequestAsync(string urlPath, IEnumerable<KeyValuePair<string, object>> parameters, CancellationToken cancellationToken = default(CancellationToken))
		{
			return ExecuteRequestAsync<long>(urlPath, parameters, "count", cancellationToken);
		}

		internal Task<T[]> ExecuteArrayRequestAsync<T>(string urlPath, IEnumerable<KeyValuePair<string, object>> parameters, string propertyName = null, CancellationToken cancellationToken = default(CancellationToken))
		{
			return ExecuteRequestAsync<T[]>(urlPath, parameters, propertyName, cancellationToken);
		}

{'fraction_non_alphanumeric': 0.14452741206523875, 'fraction_numerical': 0.0017685203379838867, 'mean_word_length': 3.307659754549302, 'pattern_counts': {'":': 0, '<': 185, '<?xml version=': 0, '>': 185, 'https://': 2, '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': '5616357', 'n_tokens_mistral': 3437, 'n_tokens_neox': 3063, 'n_words': 867}