### @tuya/cloud

`0.1.0`
Need help reading this?

### TuyaCloud

A TuyaCloud object

new TuyaCloud(options: Object)
Parameters
options `(Object)` construction options

Name | Description
--- | ---
options.key `String` | API key
options.secret `String` | API secret
options.region `String` (default `'AZ'`) | region (AZ=Americas, AY=Asia, EU=Europe)
options.deviceID `String?` | ID of device calling API (defaults to a random value)

Example

    const api = new Cloud({key: 'your-api-key', secret: 'your-api-secret'})

Instance Members
▸ request(options)

Sends an API request

request(options: Object): Promise<Object>
Parameters
options `(Object)` request options

Name | Description
--- | ---
options.action `String` | API action to invoke (for example, 'tuya.cloud.device.token.create')
options.data `Object` (default `{}`) | data to send in the request body
options.requiresSID `Boolean` (default `true`) | set to false if the request doesn't require a session ID

Returns
`Promise<Object>`: A Promise that contains the response body parsed as JSON
Example

    // generate a new token
    api.request({action: 'tuya.m.device.token.create',
                 data: {'timeZone': '-05:00'}}).then(token => console.log(token))

▸ register(options)

Helper to register a new user. If user already exists, it instead attempts to log in.

register(options: Object): Promise<String>
Parameters
options `(Object)` register options

Name | Description
--- | ---
options.email `String` | email to register
options.password `String` | password for new user

Returns
`Promise<String>`: A Promise that contains the session ID
Example

    api.register({email: 'example@example.com',
    password: 'example-password'})
    .then(sid => console.log('Session ID: ', sid))

▸ login(options)

Helper to log in a user.

login(options: Object): Promise<String>
Parameters
options `(Object)` register options

Name | Description
--- | ---
options.email `String` | user's email
options.password `String` | user's password

Returns
`Promise<String>`: A Promise that contains the session ID
Example

    api.login({email: 'example@example.com',
    password: 'example-password'}).then(sid => console.log('Session ID: ', sid))

▸ waitForToken(options)

Helper to wait for device(s) to be registered. It's possible to register multiple devices at once, so this returns an array.

waitForToken(options: Object): Promise<Array>
Parameters
options `(Object)` options

Name | Description
--- | ---
options.token `String` | token being registered
options.devices `Number` (default `1`) | number of devices to wait for

Returns
`Promise<Array>`: A Promise that contains an array of registered devices
Example

    api.waitForToken({token: token.token}).then(result => {
      let device = result[0];
      console.log('Params:');
      console.log(JSON.stringify({id: device['id'], localKey: device['localKey']}));
    });