<commit_before>/**
 * myGengo API Client
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that came
 * with this package in the file LICENSE.txt. It is also available 
 * through the world-wide-web at this URL:
 * http://mygengo.com/services/api/dev-docs/mygengo-code-license
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   myGengo
 * @package    API Client Library
 * @copyright  Copyright (c) 2009-2010 myGengo, Inc. (http://mygengo.com)
 * @license    http://mygengo.com/services/api/dev-docs/mygengo-code-license New BSD License
 */

using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Net;
namespace myGengo
{
    class Client
    {
        protected static Client instance = null;
        protected HttpWebRequest client = null;//a web client
        protected Config config = null;
        /**
         * singleton class
         */
        protected Client()
        {
            config = Config.getInstance();
        }

        public static Client getInstance()
        {
            if(null == instance)
            {
                instance = new Client();
            }
            return instance;
        }

        public HttpWebResponse get(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.GET, format, param);
        }

        public HttpWebResponse post(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.POST, format, param);
        }

        public HttpWebResponse put(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.PUT, format, param);
        }

        public HttpWebResponse delete(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.DELETE, format, param);
        }

        public static string GET = "get";
        public static string POST = "post";
        public static string PUT = "put";
        public static string DELETE = "delete";

        public WebResponse request(string url, string method, string format, IDictionary param)
        {
            format = format.ToLower();
            string[] formats = { "xml", "json" };
            if (!formats.Contains(format))
            {
                throw new GengoException("Invalid response format: " + format + ", accepted formats are: json or xml.");
            }
            method = method.ToUpper();
            string[] methods = { "GET", "POST", "PUT", "DELTE" };
            if (!methods.Contains(method))
            {
                throw new GengoException("HTTP method: " + method + " not supported");
            }
            string data = Http.Utils.buildQuery(param);
            switch (method)
            {
                case "GET":
                    url = url + "?" + data;
                    client = (HttpWebRequest)WebRequest.Create(url);
                    client.Method = method;
                    switch (format)
                    {
                        case "xml":
                            client.Accept = "application/xml";
                            break;
                        case "json":
                            client.Accept = "application/json";
                            break;<commit_msg>- Typo bug fixed in the method list<commit_after>/**
 * myGengo API Client
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that came
 * with this package in the file LICENSE.txt. It is also available 
 * through the world-wide-web at this URL:
 * http://mygengo.com/services/api/dev-docs/mygengo-code-license
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   myGengo
 * @package    API Client Library
 * @copyright  Copyright (c) 2009-2010 myGengo, Inc. (http://mygengo.com)
 * @license    http://mygengo.com/services/api/dev-docs/mygengo-code-license New BSD License
 */

using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Net;
namespace myGengo
{
    class Client
    {
        protected static Client instance = null;
        protected HttpWebRequest client = null;//a web client
        protected Config config = null;
        /**
         * singleton class
         */
        protected Client()
        {
            config = Config.getInstance();
        }

        public static Client getInstance()
        {
            if(null == instance)
            {
                instance = new Client();
            }
            return instance;
        }

        public HttpWebResponse get(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.GET, format, param);
        }

        public HttpWebResponse post(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.POST, format, param);
        }

        public HttpWebResponse put(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.PUT, format, param);
        }

        public HttpWebResponse delete(string url, string format, IDictionary param)
        {
            return (HttpWebResponse)this.request(url, Client.DELETE, format, param);
        }

        public static string GET = "get";
        public static string POST = "post";
        public static string PUT = "put";
        public static string DELETE = "delete";

        public WebResponse request(string url, string method, string format, IDictionary param)
        {
            format = format.ToLower();
            string[] formats = { "xml", "json" };
            if (!formats.Contains(format))
            {
                throw new GengoException("Invalid response format: " + format + ", accepted formats are: json or xml.");
            }
            method = method.ToUpper();
            string[] methods = { "GET", "POST", "PUT", "DELETE" };
            if (!methods.Contains(method))
            {
                throw new GengoException("HTTP method: " + method + " not supported");
            }
            string data = Http.Utils.buildQuery(param);
            switch (method)
            {
                case "GET":
                    url = url + "?" + data;
                    client = (HttpWebRequest)WebRequest.Create(url);
                    client.Method = method;
                    switch (format)
                    {
                        case "xml":
                            client.Accept = "application/xml";
                            break;
                        case "json":
                            client.Accept = "application/json";
                            break;
{'fraction_non_alphanumeric': 0.0950976260710774, 'fraction_numerical': 0.0022475066722854333, 'mean_word_length': 1.7416249518675395, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '7613632', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1737, 'n_words': 564}