Пример #1
0
        // Execute an API query
        private String _execute_query(TWFYAPI_Request query)
        {
            // Make the final URL
            String URL = query.encode_arguments();

            // Get the result
            StringBuilder result = new StringBuilder();

            byte[]         buf     = new byte[8192];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);

            request.UserAgent = "TheyWorkForYou.com API C# interface (+https://github.com/rubenarakelyan/twfyapi)";
            request.MaximumAutomaticRedirections = 1;
            request.AllowAutoRedirect            = true;
            HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
            Stream          responseStream = response.GetResponseStream();
            int             count          = 0;

            do
            {
                count = responseStream.Read(buf, 0, buf.Length);
                if (count != 0)
                {
                    result.Append(Encoding.ASCII.GetString(buf, 0, count));
                }
            }while (count > 0);
            return(result.ToString());
        }
Пример #2
0
        // Send an API query
        public String query(String func, String[] args)
        {
            // Exit if any arguments are not defined
            if (func == null || func == "" || args == null)
            {
                throw new Exception("ERROR: Function name or arguments not provided.");
            }

            // Construct the query
            TWFYAPI_Request query = new TWFYAPI_Request(func, args, this.key);

            // Execute the query
            return(this._execute_query(query));
        }
Пример #3
0
        // Send an API query
        public String query(String func, String[] args)
        {
            // Exit if any arguments are not defined
            if (func == null || func == "" || args == null)
            {
                throw new Exception("ERROR: Function name or arguments not provided.");
            }

            // Construct the query
            TWFYAPI_Request query = new TWFYAPI_Request(func, args, this.key);

            // Execute the query
            return this._execute_query(query);
        }
Пример #4
0
        // Execute an API query
        private String _execute_query(TWFYAPI_Request query)
        {
            // Make the final URL
            String URL = query.encode_arguments();

            // Get the result
            StringBuilder result = new StringBuilder();
            byte[] buf = new byte[8192];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream responseStream = response.GetResponseStream();
            int count = 0;
            do
            {
                count = responseStream.Read(buf, 0, buf.Length);
                if (count != 0)
                {
                    result.Append(Encoding.ASCII.GetString(buf, 0, count));
                }
            }
            while (count > 0);
            return result.ToString();
        }