From c4c203915ccae286080e423af36a2d1a06de7e90 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Wed, 19 Oct 2016 12:30:43 -0400 Subject: [PATCH] language: upgrade generated layer --- packages/language/package.json | 2 +- packages/language/src/document.js | 25 ++--- .../src/v1beta1/language_service_api.js | 99 ++++++++----------- packages/language/test/document.js | 36 +++---- 4 files changed, 74 insertions(+), 88 deletions(-) diff --git a/packages/language/package.json b/packages/language/package.json index 1f950607a610..dbd4644dfa9f 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -55,7 +55,7 @@ "@google-cloud/common": "^0.7.0", "arrify": "^1.0.1", "extend": "^3.0.0", - "google-gax": "^0.7.0", + "google-gax": "^0.8.0", "google-proto-files": "^0.8.3", "is": "^3.0.1", "propprop": "^0.3.1" diff --git a/packages/language/src/document.js b/packages/language/src/document.js index d06c41784742..c97e2c4b9222 100644 --- a/packages/language/src/document.js +++ b/packages/language/src/document.js @@ -395,10 +395,11 @@ Document.prototype.annotate = function(options, callback) { var verbose = options.verbose === true; - var doc = this.document; - var encType = this.encodingType; - - this.api.Language.annotateText(doc, features, encType, function(err, resp) { + this.api.Language.annotateText({ + document: this.document, + features: features, + encodingType: this.encodingType + }, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -547,10 +548,10 @@ Document.prototype.detectEntities = function(options, callback) { var verbose = options.verbose === true; - var doc = this.document; - var encType = this.encodingType; - - this.api.Language.analyzeEntities(doc, encType, function(err, resp) { + this.api.Language.analyzeEntities({ + document: this.document, + encodingType: this.encodingType + }, function(err, resp) { if (err) { callback(err, null, resp); return; @@ -621,10 +622,10 @@ Document.prototype.detectSentiment = function(options, callback) { var verbose = options.verbose === true; - var doc = this.document; - var encType = this.encodingType; - - this.api.Language.analyzeSentiment(doc, encType, function(err, resp) { + this.api.Language.analyzeSentiment({ + document: this.document, + encodingType: this.encodingType + }, function(err, resp) { if (err) { callback(err, null, resp); return; diff --git a/packages/language/src/v1beta1/language_service_api.js b/packages/language/src/v1beta1/language_service_api.js index 2460c7733341..26182642f7ff 100644 --- a/packages/language/src/v1beta1/language_service_api.js +++ b/packages/language/src/v1beta1/language_service_api.js @@ -109,7 +109,9 @@ function LanguageServiceApi(gaxGrpc, grpcClients, opts) { /** * Analyzes the sentiment of the provided text. * - * @param {Object} document + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document * Input document. Currently, `analyzeSentiment` only supports English text * ({@link Document.language}="EN"). * @@ -121,25 +123,20 @@ function LanguageServiceApi(gaxGrpc, grpcClients, opts) { * The function which will be called with the result of the API call. * * The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = languageV1beta1.languageServiceApi(); * var document = {}; - * api.analyzeSentiment(document, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * api.analyzeSentiment({document: document}).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment( - document, - options, - callback) { +LanguageServiceApi.prototype.analyzeSentiment = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -147,21 +144,20 @@ LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment( if (options === undefined) { options = {}; } - var req = { - document: document - }; - return this._analyzeSentiment(req, options, callback); + return this._analyzeSentiment(request, options, callback); }; /** * Finds named entities (currently finds proper names) in the text, * entity types, salience, mentions for each entity, and other properties. * - * @param {Object} document + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document * Input document. * * This object should have the same structure as [Document]{@link Document} - * @param {number} encodingType + * @param {number} request.encodingType * The encoding type used by the API to calculate offsets. * * The number should be among the values of [EncodingType]{@link EncodingType} @@ -172,27 +168,25 @@ LanguageServiceApi.prototype.analyzeSentiment = function analyzeSentiment( * The function which will be called with the result of the API call. * * The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * * var api = languageV1beta1.languageServiceApi(); * var document = {}; * var encodingType = EncodingType.NONE; - * api.analyzeEntities(document, encodingType, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * var request = { + * document: document, + * encodingType: encodingType + * }; + * api.analyzeEntities(request).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities( - document, - encodingType, - options, - callback) { +LanguageServiceApi.prototype.analyzeEntities = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -200,11 +194,7 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities( if (options === undefined) { options = {}; } - var req = { - document: document, - encodingType: encodingType - }; - return this._analyzeEntities(req, options, callback); + return this._analyzeEntities(request, options, callback); }; /** @@ -213,15 +203,17 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities( * API is intended for users who are familiar with machine learning and need * in-depth text features to build upon. * - * @param {Object} document + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document * Input document. * * This object should have the same structure as [Document]{@link Document} - * @param {Object} features + * @param {Object} request.features * The enabled features. * * This object should have the same structure as [Features]{@link Features} - * @param {number} encodingType + * @param {number} request.encodingType * The encoding type used by the API to calculate offsets. * * The number should be among the values of [EncodingType]{@link EncodingType} @@ -232,8 +224,8 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities( * The function which will be called with the result of the API call. * * The second parameter to the callback is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse} - * @returns {gax.EventEmitter} - the event emitter to handle the call - * status. + * @returns {Promise} - The promise which resolves to the response object. + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * @@ -241,20 +233,18 @@ LanguageServiceApi.prototype.analyzeEntities = function analyzeEntities( * var document = {}; * var features = {}; * var encodingType = EncodingType.NONE; - * api.annotateText(document, features, encodingType, function(err, response) { - * if (err) { - * console.error(err); - * return; - * } + * var request = { + * document: document, + * features: features, + * encodingType: encodingType + * }; + * api.annotateText(request).then(function(response) { * // doThingsWith(response) + * }).catch(function(err) { + * console.error(err); * }); */ -LanguageServiceApi.prototype.annotateText = function annotateText( - document, - features, - encodingType, - options, - callback) { +LanguageServiceApi.prototype.annotateText = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -262,12 +252,7 @@ LanguageServiceApi.prototype.annotateText = function annotateText( if (options === undefined) { options = {}; } - var req = { - document: document, - features: features, - encodingType: encodingType - }; - return this._annotateText(req, options, callback); + return this._annotateText(request, options, callback); }; function LanguageServiceApiBuilder(gaxGrpc) { diff --git a/packages/language/test/document.js b/packages/language/test/document.js index 296cd0ce0577..9c74bb5c45a4 100644 --- a/packages/language/test/document.js +++ b/packages/language/test/document.js @@ -180,16 +180,16 @@ describe('Document', function() { describe('annotate', function() { it('should make the correct API request', function(done) { document.api.Language = { - annotateText: function(doc, features, encType) { - assert.strictEqual(doc, document.document); + annotateText: function(reqOpts) { + assert.strictEqual(reqOpts.document, document.document); - assert.deepEqual(features, { + assert.deepEqual(reqOpts.features, { extractDocumentSentiment: true, extractEntities: true, extractSyntax: true }); - assert.strictEqual(encType, document.encodingType); + assert.strictEqual(reqOpts.encodingType, document.encodingType); done(); } @@ -201,8 +201,8 @@ describe('Document', function() { it('should allow specifying individual features', function(done) { document.api.Language = { - annotateText: function(doc, features) { - assert.deepEqual(features, { + annotateText: function(reqOpts) { + assert.deepEqual(reqOpts.features, { extractDocumentSentiment: false, extractEntities: true, extractSyntax: true @@ -224,7 +224,7 @@ describe('Document', function() { beforeEach(function() { document.api.Language = { - annotateText: function(doc, features, encType, callback) { + annotateText: function(options, callback) { callback(error, apiResponse); } }; @@ -271,7 +271,7 @@ describe('Document', function() { ); function createAnnotateTextWithResponse(apiResponse) { - return function(doc, features, encType, callback) { + return function(reqOpts, callback) { callback(null, apiResponse); }; } @@ -436,9 +436,9 @@ describe('Document', function() { describe('detectEntities', function() { it('should make the correct API request', function(done) { document.api.Language = { - analyzeEntities: function(doc, encType) { - assert.strictEqual(doc, document.document); - assert.strictEqual(encType, document.encodingType); + analyzeEntities: function(reqOpts) { + assert.strictEqual(reqOpts.document, document.document); + assert.strictEqual(reqOpts.encodingType, document.encodingType); done(); } }; @@ -453,7 +453,7 @@ describe('Document', function() { beforeEach(function() { document.api.Language = { - analyzeEntities: function(doc, encType, callback) { + analyzeEntities: function(reqOpts, callback) { callback(error, apiResponse); } }; @@ -478,7 +478,7 @@ describe('Document', function() { beforeEach(function() { document.api.Language = { - analyzeEntities: function(doc, encType, callback) { + analyzeEntities: function(reqOpts, callback) { callback(null, apiResponse); } }; @@ -525,9 +525,9 @@ describe('Document', function() { describe('detectSentiment', function() { it('should make the correct API request', function(done) { document.api.Language = { - analyzeSentiment: function(doc, encType) { - assert.strictEqual(doc, document.document); - assert.strictEqual(encType, document.encodingType); + analyzeSentiment: function(reqOpts) { + assert.strictEqual(reqOpts.document, document.document); + assert.strictEqual(reqOpts.encodingType, document.encodingType); done(); } }; @@ -542,7 +542,7 @@ describe('Document', function() { beforeEach(function() { document.api.Language = { - analyzeSentiment: function(doc, encType, callback) { + analyzeSentiment: function(reqOpts, callback) { callback(error, apiResponse); } }; @@ -569,7 +569,7 @@ describe('Document', function() { Document.formatSentiment_ = util.noop; document.api.Language = { - analyzeSentiment: function(doc, encType, callback) { + analyzeSentiment: function(reqOpts, callback) { callback(null, apiResponse); } };