@@ -68,7 +68,9 @@ var prop = require('propprop');
6868function Document ( language , config ) {
6969 var content = config . content || config ;
7070
71- // `reqOpts` is the payload passed to each `request()`. This object is used as
71+ this . api = language . api ;
72+
73+ // `reqOpts` is the payload passed to each API request. This object is used as
7274 // the default for all API requests made with this Document.
7375 this . reqOpts = {
7476 document : { }
@@ -102,8 +104,6 @@ function Document(language, config) {
102104 } else {
103105 this . reqOpts . document . content = content ;
104106 }
105-
106- this . request = language . request . bind ( language ) ;
107107}
108108
109109/**
@@ -392,16 +392,10 @@ Document.prototype.annotate = function(options, callback) {
392392
393393 var verbose = options . verbose === true ;
394394
395- var grpcOpts = {
396- service : 'LanguageService' ,
397- method : 'annotateText'
398- } ;
399-
400- var reqOpts = extend ( {
401- features : features
402- } , this . reqOpts ) ;
395+ var doc = this . reqOpts . document ;
396+ var encType = this . reqOpts . encodingType ;
403397
404- this . request ( grpcOpts , reqOpts , function ( err , resp ) {
398+ this . api . Language . annotateText ( doc , features , encType , function ( err , resp ) {
405399 if ( err ) {
406400 callback ( err , null , resp ) ;
407401 return ;
@@ -542,12 +536,10 @@ Document.prototype.detectEntities = function(options, callback) {
542536
543537 var verbose = options . verbose === true ;
544538
545- var grpcOpts = {
546- service : 'LanguageService' ,
547- method : 'analyzeEntities'
548- } ;
539+ var doc = this . reqOpts . document ;
540+ var encType = this . reqOpts . encodingType ;
549541
550- this . request ( grpcOpts , this . reqOpts , function ( err , resp ) {
542+ this . api . Language . analyzeEntities ( doc , encType , function ( err , resp ) {
551543 if ( err ) {
552544 callback ( err , null , resp ) ;
553545 return ;
@@ -610,12 +602,10 @@ Document.prototype.detectSentiment = function(options, callback) {
610602
611603 var verbose = options . verbose === true ;
612604
613- var grpcOpts = {
614- service : 'LanguageService' ,
615- method : 'analyzeSentiment'
616- } ;
605+ var doc = this . reqOpts . document ;
606+ var encType = this . reqOpts . encodingType ;
617607
618- this . request ( grpcOpts , this . reqOpts , function ( err , resp ) {
608+ this . api . Language . analyzeSentiment ( doc , encType , function ( err , resp ) {
619609 if ( err ) {
620610 callback ( err , null , resp ) ;
621611 return ;
0 commit comments