# Class: TwoCaptchaClient

## TwoCaptchaClient(key, paramsopt) → {TwoCaptchaClient}

#### new TwoCaptchaClient(key, paramsopt) → {TwoCaptchaClient}

Constructor for the 2Captcha client object

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`key` | string |  | Your 2Captcha API key
`params` | Object | <optional> | Params for the client ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`timeout` | number | <optional> | milliseconds before giving up on an captcha
`polling` | number | <optional> | milliseconds between polling for answer
`throwErrors` | Boolean | <optional> | Whether the client should throw errors or just log the errors

Source:
  - two_captcha_client.js, line 23

##### Returns:

The client object

Type
  TwoCaptchaClient

### Methods

#### (async) _loadCaptcha(options) → {Promise.<string>}

Loads a captcha image and converts to base64

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | The source of the image ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`base64` | string | <optional> | An already base64-coded image
`buffer` | Buffer | <optional> | A buffer object of a binary image
`path` | string | <optional> | The path for a system-stored image
`url` | string | <optional> | Url for a web-located image

Source:
  - two_captcha_client.js, line 158

##### Returns:

Promise for a base64 string representation of an image

Type
  Promise.<string>

#### (async) _request(action, method, payload) → {Promise.<string>}

Makes a HTTP request for the 2Captcha API

##### Parameters:

Name | Type | Default | Description
--- | --- | --- | ---
`action` | string |  | Path used in the 2Captcha api URL
`method` | string | get | HTTP verb to be used
`payload` | string |  | Body of the requisition

Source:
  - two_captcha_client.js, line 182

##### Returns:

Promise for the response body

Type
  Promise.<string>

#### (async) _sleep(ms) → {Promise.<undefined>}

Blocks the code for the specified amount of time

##### Parameters:

Name | Type | Description
--- | --- | ---
`ms` | number | The time in milliseconds to block the code

Source:
  - two_captcha_client.js, line 216

##### Returns:

Promise for undefined that resolves after ms milliseconds

Type
  Promise.<undefined>

#### _throwError(message) → {undefined|Boolean}

Throws an Error if this.throwErrors is true. If this.throwErrors is false, a warn is logged in the console.

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | string | Message of the error

Source:
  - two_captcha_client.js, line 244

##### Returns:

If an error wasn't thrown, returns false.

Type
  undefined | Boolean

#### (async) _upload(options) → {Promise.<Captcha>}

Uploads a captcha for the 2Captcha API

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | Parametes for the controlling the requistion ###### Properties
Name | Type | Description
--- | --- | ---
`base64` | string | The base64 encoded image
`method` | string | 2Captcha method of image sending. Can be either base64 or multipart

Source:
  - two_captcha_client.js, line 262

##### Returns:

Promise for Captcha object containing the captcha ID

Type
  Promise.<Captcha>

#### _validateResponse(body) → {undefined|Boolean}

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.

##### Parameters:

Name | Type | Description
--- | --- | ---
`body` | string | Body from the 2Captcha response

Source:
  - two_captcha_client.js, line 294

##### Returns:

Returns true if response is valid

Type
  undefined | Boolean

#### (async) balance() → {Promise.<float>}

Get balance from your account

Source:
  - two_captcha_client.js, line 41

##### Returns:

Account balance in USD

Type
  Promise.<float>

#### (async) captcha(captchaId) → {Promis.<Captcha>}

Gets the response from a solved captcha

##### Parameters:

Name | Type | Description
--- | --- | ---
`captchaId` | string | The id of the desired captcha

Source:
  - two_captcha_client.js, line 54

##### Returns:

A promise for the captcha

Type
  Promis.<Captcha>

#### (async) decode(options) → {Promise.<Captcha>}

Sends an image captcha and polls for its response

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | Parameters for the requests ###### Properties
Name | Type | Attributes | Description
--- | --- | --- | ---
`base64` | string | <optional> | An already base64-coded image
`buffer` | Buffer | <optional> | A buffer object of a binary image
`path` | string | <optional> | The path for a system-stored image
`url` | string | <optional> | Url for a web-located image
`method` | string | <optional> | 2Captcha method of image sending. Can be either base64 or multipart

Source:
  - two_captcha_client.js, line 80

##### Returns:

Promise for a Captcha object

Type
  Promise.<Captcha>

#### (async) decodeRecaptchaV2(options) → {Promise.<Captcha>}

Sends a ReCaptcha v2 and polls for its response

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | Parameters for the request ###### Properties
Name | Type | Description
--- | --- | ---
`googlekey` | string | The google key from the ReCaptcha
`pageurl` | string | The URL where the ReCaptcha is

Source:
  - two_captcha_client.js, line 110

##### Returns:

Promise for a Captcha object

Type
  Promise.<Captcha>

#### (async) load() → {Promise.<string>}

Deprecated:
  - /load.php route is returning error 500 Get current load from 2Captcha service
Source:
  - two_captcha_client.js, line 144

##### Returns:

Promise for an XML containing current load from 2Captcha service

Type
  Promise.<string>

#### (async) report(captchaId) → {Promise.<Boolean>}

Report incorrectly solved captcha for refund

##### Parameters:

Name | Type | Description
--- | --- | ---
`captchaId` | string | The id of the incorrectly solved captcha

Source:
  - two_captcha_client.js, line 202

##### Returns:

Promise for a boolean informing if the report was received

Type
  Promise.<Boolean>

#### (async) stats(date) → {Promise.<string>}

Get usage statistics from your account

##### Parameters:

Name | Type | Description
--- | --- | ---
`date` | Date | Date for the target day

Source:
  - two_captcha_client.js, line 229

##### Returns:

Promise for an XML containing statistics about target day

Type
  Promise.<string>