cloudsearchdomain.js (3602B)
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 CloudSearchDomain 8 * 9 * ```javascript 10 * var csd = new AWS.CloudSearchDomain({endpoint: 'my.host.tld'}); 11 * csd.search(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 CloudSearchDomain 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 csd = new AWS.CloudSearchDomain({ 25 * endpoint: 'my.host.tld', 26 * apiVersion: '2013-01-01' 27 * }); 28 * ``` 29 * 30 * You can also set the API version globally in `AWS.config.apiVersions` using 31 * the **cloudsearchdomain** service identifier: 32 * 33 * ```javascript 34 * AWS.config.apiVersions = { 35 * cloudsearchdomain: '2013-01-01', 36 * // other service API versions 37 * }; 38 * 39 * var csd = new AWS.CloudSearchDomain({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 CloudSearchDomain object 50 * var csd = new AWS.CloudSearchDomain({endpoint: 'my.host.tld'}); 51 * @note You *must* provide an `endpoint` when constructing this service. 52 * @option (see AWS.Config.constructor) 53 * 54 * @service cloudsearchdomain 55 * @version 2013-01-01 56 */ 57 AWS.util.update(AWS.CloudSearchDomain.prototype, { 58 /** 59 * @api private 60 */ 61 validateService: function validateService() { 62 if (!this.config.endpoint || this.config.endpoint.indexOf('{') >= 0) { 63 var msg = 'AWS.CloudSearchDomain 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.removeListener('validate', 75 AWS.EventListeners.Core.VALIDATE_CREDENTIALS 76 ); 77 request.onAsync('validate', this.validateCredentials); 78 request.addListener('validate', this.updateRegion); 79 if (request.operation === 'search') { 80 request.addListener('build', this.convertGetToPost); 81 } 82 }, 83 84 /** 85 * @api private 86 */ 87 validateCredentials: function(req, done) { 88 if (!req.service.api.signatureVersion) return done(); // none 89 req.service.config.getCredentials(function(err) { 90 if (err) { 91 req.removeListener('sign', AWS.EventListeners.Core.SIGN); 92 } 93 done(); 94 }); 95 }, 96 97 /** 98 * @api private 99 */ 100 convertGetToPost: function(request) { 101 var httpRequest = request.httpRequest 102 // convert queries to POST to avoid length restrictions 103 var path = httpRequest.path.split('?') 104 httpRequest.method = 'POST' 105 httpRequest.path = path[0] 106 httpRequest.body = path[1] 107 httpRequest.headers['Content-Length'] = httpRequest.body.length 108 httpRequest.headers['Content-Type'] = 'application/x-www-form-urlencoded' 109 }, 110 111 /** 112 * @api private 113 */ 114 updateRegion: function updateRegion(request) { 115 var endpoint = request.httpRequest.endpoint.hostname; 116 var zones = endpoint.split('.'); 117 request.httpRequest.region = zones[1] || request.httpRequest.region; 118 } 119 120 });