Пример #1
0
        /// <summary>
        /// Provide an answer to a job.
        /// </summary>
        /// <param name="value">The answer to submit.</param>
        public void Answer(string value)
        {
            if (_username == null || _password == null)
            {
                throw new Exception("INVALID USER");
            }
            else if (_enqueueJobId == null)
            {
                throw new Exception("INVALID TICKET");
            }
            else
            {
                CaptchaTraderRequest request = new CaptchaTraderRequest(CaptchaTraderRequestType.ANSWER);
                request.setParameter("username", _username);
                request.setParameter("password", _password);
                request.setParameter("ticket", _enqueueJobId);
                request.setParameter("value", value);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(request.post());
                if (doc["error"] != null)
                {
                    throw new Exception(doc["error"].InnerText);
                }
                else
                {
                    _enqueueJobId = null;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Respond to the last sent job.
        /// </summary>
        /// <param name="isCorrect">Whether the job was correct or not.</param>
        public void Respond(bool isCorrect)
        {
            if (_activeJobId == null)
            {
                throw new Exception("INVALID TICKET");
            }
            else
            {
                CaptchaTraderRequest request = new CaptchaTraderRequest(CaptchaTraderRequestType.RESPOND);
                request.setParameter("username", _username);
                request.setParameter("password", _password);
                request.setParameter("ticket", _activeJobId);
                request.setParameter("is_correct", isCorrect ? "1" : "0");

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(request.post());
                if (doc["error"] != null)
                {
                    throw new Exception(doc["error"].InnerText);
                }
                else
                {
                    _activeJobId = null;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Submit a CAPTCHA currently saved as a file.
        /// </summary>
        /// <param name="file">The file that the CAPTCHA is saved as.</param>
        /// <returns>The decoded CAPTCHA.</returns>
        public string Submit(FileInfo file)
        {
            CaptchaTraderRequest request = new CaptchaTraderRequest();

            request.setParameter("value", file);
            return(submitJob(request));
        }
Пример #4
0
        /// <summary>
        /// Submit a CAPTCHA URL.
        /// </summary>
        /// <param name="url">The URL of the CAPTCHA.</param>
        /// <returns>The decoded CAPTCHA.</returns>
        public string Submit(Uri url)
        {
            CaptchaTraderRequest request = new CaptchaTraderRequest();

            request.setParameter("value", url.OriginalString);
            return(submitJob(request));
        }
Пример #5
0
        /// <summary>
        /// Complete a job submission.
        /// </summary>
        /// <param name="request">The CaptchaTraderRequest of the job.</param>
        /// <returns>The decoded CAPTCHA.</returns>
        private string submitJob(CaptchaTraderRequest request)
        {
            request.setParameter("username", _username);
            request.setParameter("password", _password);
            request.setParameter("api_key", _apiKey);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(request.post());
            if (doc["error"] != null)
            {
                throw new Exception(doc["error"].InnerText);
            }
            else
            {
                _activeJobId = doc["job"].Attributes["id"].InnerText;
                return(doc["job"]["response"].InnerText);
            }
        }
Пример #6
0
        /// <summary>
        /// Remove the user from all pending jobs and the job queue.
        /// </summary>
        public void Dequeue()
        {
            if (_username == null || _password == null)
            {
                throw new Exception("INVALID USER");
            }
            else
            {
                CaptchaTraderRequest request = new CaptchaTraderRequest(CaptchaTraderRequestType.DEQUEUE);
                request.setParameter("username", _username);
                request.setParameter("password", _password);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(request.post());
                if (doc["error"] != null)
                {
                    throw new Exception(doc["error"].InnerText);
                }
                else
                {
                    _enqueueJobId = null;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Provide an answer to a job.
        /// </summary>
        /// <param name="value">The answer to submit.</param>
        public void Answer(string value)
        {
            if (_username == null || _password == null)
            {
                throw new Exception("INVALID USER");
            }
            else if (_enqueueJobId == null)
            {
                throw new Exception("INVALID TICKET");
            }
            else
            {
                CaptchaTraderRequest request = new CaptchaTraderRequest(CaptchaTraderRequestType.ANSWER);
                request.setParameter("username", _username);
                request.setParameter("password", _password);
                request.setParameter("ticket", _enqueueJobId);
                request.setParameter("value", value);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(request.post());
                if (doc["error"] != null)
                {
                    throw new Exception(doc["error"].InnerText);
                }
                else
                {
                    _enqueueJobId = null;
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Remove the user from all pending jobs and the job queue.
        /// </summary>
        public void Dequeue()
        {
            if (_username == null || _password == null)
            {
                throw new Exception("INVALID USER");
            }
            else
            {
                CaptchaTraderRequest request = new CaptchaTraderRequest(CaptchaTraderRequestType.DEQUEUE);
                request.setParameter("username", _username);
                request.setParameter("password", _password);

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(request.post());
                if (doc["error"] != null)
                {
                    throw new Exception(doc["error"].InnerText);
                }
                else
                {
                    _enqueueJobId = null;
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Respond to the last sent job.
        /// </summary>
        /// <param name="isCorrect">Whether the job was correct or not.</param>
        public void Respond(bool isCorrect)
        {
            if (_activeJobId == null)
            {
                throw new Exception("INVALID TICKET");
            }
            else
            {
                CaptchaTraderRequest request = new CaptchaTraderRequest(CaptchaTraderRequestType.RESPOND);
                request.setParameter("username", _username);
                request.setParameter("password", _password);
                request.setParameter("ticket", _activeJobId);
                request.setParameter("is_correct", isCorrect ? "1" : "0");

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(request.post());
                if (doc["error"] != null)
                {
                    throw new Exception(doc["error"].InnerText);
                }
                else
                {
                    _activeJobId = null;
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Complete a job submission.
        /// </summary>
        /// <param name="request">The CaptchaTraderRequest of the job.</param>
        /// <returns>The decoded CAPTCHA.</returns>
        private string submitJob(CaptchaTraderRequest request) {
            request.setParameter("username", _username);
            request.setParameter("password", _password);
            request.setParameter("api_key", _apiKey);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(request.post());
            if (doc["error"] != null)
            {
                throw new Exception(doc["error"].InnerText);
            }
            else
            {
                _activeJobId = doc["job"].Attributes["id"].InnerText;
                return doc["job"]["response"].InnerText;
            }
        }
Пример #11
0
 /// <summary>
 /// Submit a CAPTCHA currently saved as a file.
 /// </summary>
 /// <param name="file">The file that the CAPTCHA is saved as.</param>
 /// <returns>The decoded CAPTCHA.</returns>
 public string Submit(FileInfo file)
 {
     CaptchaTraderRequest request = new CaptchaTraderRequest();
     request.setParameter("value", file);
     return submitJob(request);
 }
Пример #12
0
 /// <summary>
 /// Submit a CAPTCHA URL.
 /// </summary>
 /// <param name="url">The URL of the CAPTCHA.</param>
 /// <returns>The decoded CAPTCHA.</returns>
 public string Submit(Uri url)
 {
     CaptchaTraderRequest request = new CaptchaTraderRequest();
     request.setParameter("value", url.OriginalString);
     return submitJob(request);
 }