UNPKG

node_two_captcha_fork_emd

Version:

Node.js package for easy integration with 2Captcha API (Captcha Solver as a Service)

3,312 lines (943 loc) 39.5 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: TwoCaptchaClient</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: TwoCaptchaClient</h1> <section> <header> <h2><span class="attribs"><span class="type-signature"></span></span>TwoCaptchaClient<span class="signature">(key, params<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="TwoCaptchaClient.html">TwoCaptchaClient</a>}</span></h2> </header> <article> <div class="container-overview"> <h4 class="name" id="TwoCaptchaClient"><span class="type-signature"></span>new TwoCaptchaClient<span class="signature">(key, params<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {<a href="TwoCaptchaClient.html">TwoCaptchaClient</a>}</span></h4> <div class="description"> Constructor for the 2Captcha client object </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>key</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last">Your 2Captcha API key</td> </tr> <tr> <td class="name"><code>params</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Params for the client <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>timeout</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">milliseconds before giving up on an captcha</td> </tr> <tr> <td class="name"><code>polling</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">milliseconds between polling for answer</td> </tr> <tr> <td class="name"><code>throwErrors</code></td> <td class="type"> <span class="param-type">Boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Whether the client should throw errors or just log the errors</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line23">line 23</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> The client object </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="TwoCaptchaClient.html">TwoCaptchaClient</a></span> </dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="_loadCaptcha"><span class="type-signature">(async) </span>_loadCaptcha<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;string>}</span></h4> <div class="description"> Loads a captcha image and converts to base64 </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">The source of the image <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>base64</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">An already base64-coded image</td> </tr> <tr> <td class="name"><code>buffer</code></td> <td class="type"> <span class="param-type">Buffer</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">A buffer object of a binary image</td> </tr> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The path for a system-stored image</td> </tr> <tr> <td class="name"><code>url</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Url for a web-located image</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line202">line 202</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for a base64 string representation of an image </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;string></span> </dd> </dl> <h4 class="name" id="_request"><span class="type-signature">(async) </span>_request<span class="signature">(action, method, payload)</span><span class="type-signature"> &rarr; {Promise.&lt;string>}</span></h4> <div class="description"> Makes a HTTP request for the 2Captcha API </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>action</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="default"> </td> <td class="description last">Path used in the 2Captcha api URL</td> </tr> <tr> <td class="name"><code>method</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="default"> get </td> <td class="description last">HTTP verb to be used</td> </tr> <tr> <td class="name"><code>payload</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="default"> </td> <td class="description last">Body of the requisition</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line226">line 226</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for the response body </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;string></span> </dd> </dl> <h4 class="name" id="_sleep"><span class="type-signature">(async) </span>_sleep<span class="signature">(ms)</span><span class="type-signature"> &rarr; {Promise.&lt;undefined>}</span></h4> <div class="description"> Blocks the code for the specified amount of time </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>ms</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">The time in milliseconds to block the code</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line261">line 261</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for undefined that resolves after ms milliseconds </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;undefined></span> </dd> </dl> <h4 class="name" id="_throwError"><span class="type-signature"></span>_throwError<span class="signature">(message)</span><span class="type-signature"> &rarr; {undefined|Boolean}</span></h4> <div class="description"> Throws an Error if this.throwErrors is true. If this.throwErrors is false, a warn is logged in the console. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>message</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Message of the error</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line289">line 289</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> If an error wasn't thrown, returns false. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">undefined</span> | <span class="param-type">Boolean</span> </dd> </dl> <h4 class="name" id="_upload"><span class="type-signature">(async) </span>_upload<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="Captcha.html">Captcha</a>>}</span></h4> <div class="description"> Uploads a captcha for the 2Captcha API </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">Parametes for the controlling the requistion <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>base64</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The base64 encoded image</td> </tr> <tr> <td class="name"><code>method</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">2Captcha method of image sending. Can be either base64 or multipart</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line307">line 307</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for Captcha object containing the captcha ID </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;<a href="Captcha.html">Captcha</a>></span> </dd> </dl> <h4 class="name" id="_validateResponse"><span class="type-signature"></span>_validateResponse<span class="signature">(body)</span><span class="type-signature"> &rarr; {undefined|Boolean}</span></h4> <div class="description"> Checks if the response from 2Captcha is an Error. It may throw an error if the class parameter throwExceptions is true. If it is false, only a warning will be logged. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>body</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Body from the 2Captcha response</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line339">line 339</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Returns true if response is valid </div> <dl> <dt> Type </dt> <dd> <span class="param-type">undefined</span> | <span class="param-type">Boolean</span> </dd> </dl> <h4 class="name" id="balance"><span class="type-signature">(async) </span>balance<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;float>}</span></h4> <div class="description"> Get balance from your account </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line41">line 41</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Account balance in USD </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;float></span> </dd> </dl> <h4 class="name" id="captcha"><span class="type-signature">(async) </span>captcha<span class="signature">(captchaId)</span><span class="type-signature"> &rarr; {Promis.&lt;<a href="Captcha.html">Captcha</a>>}</span></h4> <div class="description"> Gets the response from a solved captcha </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>captchaId</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The id of the desired captcha</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line54">line 54</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> A promise for the captcha </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promis.&lt;<a href="Captcha.html">Captcha</a>></span> </dd> </dl> <h4 class="name" id="decode"><span class="type-signature">(async) </span>decode<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="Captcha.html">Captcha</a>>}</span></h4> <div class="description"> Sends an image captcha and polls for its response </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">Parameters for the requests <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>base64</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">An already base64-coded image</td> </tr> <tr> <td class="name"><code>buffer</code></td> <td class="type"> <span class="param-type">Buffer</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">A buffer object of a binary image</td> </tr> <tr> <td class="name"><code>path</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">The path for a system-stored image</td> </tr> <tr> <td class="name"><code>url</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">Url for a web-located image</td> </tr> <tr> <td class="name"><code>method</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last">2Captcha method of image sending. Can be either base64 or multipart</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line80">line 80</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for a Captcha object </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;<a href="Captcha.html">Captcha</a>></span> </dd> </dl> <h4 class="name" id="decodeRecaptchaV2"><span class="type-signature">(async) </span>decodeRecaptchaV2<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="Captcha.html">Captcha</a>>}</span></h4> <div class="description"> Sends a ReCaptcha v2 and polls for its response </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">Parameters for the request <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>googlekey</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The google key from the ReCaptcha</td> </tr> <tr> <td class="name"><code>pageurl</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The URL where the ReCaptcha is</td> </tr> <tr> <td class="name"><code>invisible</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="description last">Invisible ReCaptcha switch</td> </tr> <tr> <td class="name"><code>enterprise</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="description last">Enterprise ReCaptcha switch</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line112">line 112</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for a Captcha object </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;<a href="Captcha.html">Captcha</a>></span> </dd> </dl> <h4 class="name" id="decodeRecaptchaV3"><span class="type-signature">(async) </span>decodeRecaptchaV3<span class="signature">(options)</span><span class="type-signature"> &rarr; {Promise.&lt;<a href="Captcha.html">Captcha</a>>}</span></h4> <div class="description"> Sends a ReCaptcha v3 and polls for its response </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>options</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="description last">Parameters for the request <h6>Properties</h6> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>googlekey</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The google key from the ReCaptcha</td> </tr> <tr> <td class="name"><code>pageurl</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The URL where the ReCaptcha is</td> </tr> <tr> <td class="name"><code>action</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">Action value for ReCaptcha</td> </tr> <tr> <td class="name"><code>enterprise</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="description last">Enterprise ReCaptcha switch</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line151">line 151</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for a Captcha object </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;<a href="Captcha.html">Captcha</a>></span> </dd> </dl> <h4 class="name" id="load"><span class="type-signature">(async) </span>load<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;string>}</span></h4> <dl class="details"> <dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>/load.php route is returning error 500 Get current load from 2Captcha service</li></ul></dd> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line188">line 188</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for an XML containing current load from 2Captcha service </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;string></span> </dd> </dl> <h4 class="name" id="report"><span class="type-signature">(async) </span>report<span class="signature">(captchaId, bad)</span><span class="type-signature"> &rarr; {Promise.&lt;Boolean>}</span></h4> <div class="description"> Report incorrectly solved captcha for refund </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>captchaId</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="default"> </td> <td class="description last">The id of the incorrectly solved captcha</td> </tr> <tr> <td class="name"><code>bad</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="default"> true </td> <td class="description last">If reporting an incorrectly solved captcha. Default is true.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line247">line 247</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for a boolean informing if the report was received </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;Boolean></span> </dd> </dl> <h4 class="name" id="stats"><span class="type-signature">(async) </span>stats<span class="signature">(date)</span><span class="type-signature"> &rarr; {Promise.&lt;string>}</span></h4> <div class="description"> Get usage statistics from your account </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>date</code></td> <td class="type"> <span class="param-type">Date</span> </td> <td class="description last">Date for the target day</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="two_captcha_client.js.html">two_captcha_client.js</a>, <a href="two_captcha_client.js.html#line274">line 274</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Promise for an XML containing statistics about target day </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Promise.&lt;string></span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Captcha.html">Captcha</a></li><li><a href="HTTPRequest.html">HTTPRequest</a></li><li><a href="TwoCaptchaClient.html">TwoCaptchaClient</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Mon May 17 2021 19:14:49 GMT-0300 (Brasilia Standard Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>