iotdata.js (2601B)
1 var AWS = require('../core'); 2 3 /** 4 * Constructs a service interface object. Each API operation is exposed as a 5 * function on service. 6 * 7 * ### Sending a Request Using IotData 8 * 9 * ```javascript 10 * var iotdata = new AWS.IotData({endpoint: 'my.host.tld'}); 11 * iotdata.getThingShadow(params, function (err, data) { 12 * if (err) console.log(err, err.stack); // an error occurred 13 * else console.log(data); // successful response 14 * }); 15 * ``` 16 * 17 * ### Locking the API Version 18 * 19 * In order to ensure that the IotData object uses this specific API, 20 * you can construct the object by passing the `apiVersion` option to the 21 * constructor: 22 * 23 * ```javascript 24 * var iotdata = new AWS.IotData({ 25 * endpoint: 'my.host.tld', 26 * apiVersion: '2015-05-28' 27 * }); 28 * ``` 29 * 30 * You can also set the API version globally in `AWS.config.apiVersions` using 31 * the **iotdata** service identifier: 32 * 33 * ```javascript 34 * AWS.config.apiVersions = { 35 * iotdata: '2015-05-28', 36 * // other service API versions 37 * }; 38 * 39 * var iotdata = new AWS.IotData({endpoint: 'my.host.tld'}); 40 * ``` 41 * 42 * @note You *must* provide an `endpoint` configuration parameter when 43 * constructing this service. See {constructor} for more information. 44 * 45 * @!method constructor(options = {}) 46 * Constructs a service object. This object has one method for each 47 * API operation. 48 * 49 * @example Constructing a IotData object 50 * var iotdata = new AWS.IotData({endpoint: 'my.host.tld'}); 51 * @note You *must* provide an `endpoint` when constructing this service. 52 * @option (see AWS.Config.constructor) 53 * 54 * @service iotdata 55 * @version 2015-05-28 56 */ 57 AWS.util.update(AWS.IotData.prototype, { 58 /** 59 * @api private 60 */ 61 validateService: function validateService() { 62 if (!this.config.endpoint || this.config.endpoint.indexOf('{') >= 0) { 63 var msg = 'AWS.IotData requires an explicit ' + 64 '`endpoint\' configuration option.'; 65 throw AWS.util.error(new Error(), 66 {name: 'InvalidEndpoint', message: msg}); 67 } 68 }, 69 70 /** 71 * @api private 72 */ 73 setupRequestListeners: function setupRequestListeners(request) { 74 request.addListener('validateResponse', this.validateResponseBody) 75 }, 76 77 /** 78 * @api private 79 */ 80 validateResponseBody: function validateResponseBody(resp) { 81 var body = resp.httpResponse.body.toString() || '{}'; 82 var bodyCheck = body.trim(); 83 if (!bodyCheck || bodyCheck.charAt(0) !== '{') { 84 resp.httpResponse.body = ''; 85 } 86 } 87 88 });