1+ /*
2+ * Copyright 2016 Google Inc. All rights reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ *
16+ * EDITING INSTRUCTIONS
17+ * This file was generated from the file
18+ * https://github.com/googleapis/googleapis/blob/master/google/cloud/vision/v1/image_annotator.proto,
19+ * and updates to that file get reflected here through a refresh process.
20+ * For the short term, the refresh process will only be runnable by Google
21+ * engineers.
22+ *
23+ * The only allowed edits are to method and file documentation. A 3-way
24+ * merge preserves those additions if the generated source changes.
25+ */
26+ /* TODO: introduce line-wrapping so that it never exceeds the limit. */
27+ /* jscs: disable maximumLineLength */
28+ 'use strict' ;
29+
30+ var arguejs = require ( 'arguejs' ) ;
31+ var configData = require ( './image_annotator_client_config' ) ;
32+ var extend = require ( 'extend' ) ;
33+ var gax = require ( 'google-gax' ) ;
34+
35+ var SERVICE_ADDRESS = 'vision.googleapis.com' ;
36+
37+ var DEFAULT_SERVICE_PORT = 443 ;
38+
39+ var CODE_GEN_NAME_VERSION = 'gapic/0.1.0' ;
40+
41+ var DEFAULT_TIMEOUT = 30 ;
42+
43+ /**
44+ * The scopes needed to make gRPC calls to all of the methods defined in
45+ * this service.
46+ */
47+ var ALL_SCOPES = [
48+ 'https://www.googleapis.com/auth/cloud-platform'
49+ ] ;
50+
51+ /**
52+ * Service that performs Google Cloud Vision API detection tasks, such as face,
53+ * landmark, logo, label, and text detection, over client images, and returns
54+ * detected entities from the images.
55+ *
56+ * This will be created through a builder function which can be obtained by the module.
57+ * See the following example of how to initialize the module and how to access to the builder.
58+ * @see {@link imageAnnotatorApi }
59+ *
60+ * @example
61+ * var visionV1 = require('@google-cloud/vision').v1({
62+ * // optional auth parameters.
63+ * });
64+ * var api = visionV1.imageAnnotatorApi();
65+ *
66+ * @class
67+ */
68+ function ImageAnnotatorApi ( gaxGrpc , grpcClient , opts ) {
69+ opts = opts || { } ;
70+ var servicePath = opts . servicePath || SERVICE_ADDRESS ;
71+ var port = opts . port || DEFAULT_SERVICE_PORT ;
72+ var sslCreds = opts . sslCreds || null ;
73+ var clientConfig = opts . clientConfig || { } ;
74+ var timeout = opts . timeout || DEFAULT_TIMEOUT ;
75+ var appName = opts . appName || 'gax' ;
76+ var appVersion = opts . appVersion || gax . Version ;
77+
78+ var googleApiClient = [
79+ appName + '/' + appVersion ,
80+ CODE_GEN_NAME_VERSION ,
81+ 'nodejs/' + process . version ] . join ( ' ' ) ;
82+
83+ var defaults = gaxGrpc . constructSettings (
84+ 'google.cloud.vision.v1.ImageAnnotator' ,
85+ configData ,
86+ clientConfig ,
87+ timeout ,
88+ null ,
89+ null ,
90+ { 'x-goog-api-client' : googleApiClient } ) ;
91+
92+ var stub = gaxGrpc . createStub (
93+ servicePath ,
94+ port ,
95+ grpcClient . google . cloud . vision . v1 . ImageAnnotator ,
96+ { sslCreds : sslCreds } ) ;
97+ var methods = [
98+ 'batchAnnotateImages'
99+ ] ;
100+ methods . forEach ( function ( methodName ) {
101+ this [ '_' + methodName ] = gax . createApiCall (
102+ stub . then ( function ( stub ) { return stub [ methodName ] . bind ( stub ) ; } ) ,
103+ defaults [ methodName ] ) ;
104+ } . bind ( this ) ) ;
105+ }
106+
107+ // Service calls
108+
109+ /**
110+ * Run image detection and annotation for a batch of images.
111+ *
112+ * @param {Object[] } requests
113+ * Individual image annotation requests for this batch.
114+ *
115+ * This object should have the same structure as [AnnotateImageRequest]{@link AnnotateImageRequest}
116+ * @param {gax.CallOptions= } options
117+ * Overrides the default settings for this call, e.g, timeout,
118+ * retries, etc.
119+ * @param {function(?Error, ?Object)= } callback
120+ * The function which will be called with the result of the API call.
121+ *
122+ * The second parameter to the callback is an object representing [BatchAnnotateImagesResponse]{@link BatchAnnotateImagesResponse}
123+ * @returns {gax.EventEmitter } - the event emitter to handle the call
124+ * status.
125+ *
126+ * @example
127+ *
128+ * var api = visionV1.imageAnnotatorApi();
129+ * var requests = [];
130+ * api.batchAnnotateImages(requests, function(err, response) {
131+ * if (err) {
132+ * console.error(err);
133+ * return;
134+ * }
135+ * // doThingsWith(response)
136+ * });
137+ */
138+ ImageAnnotatorApi . prototype . batchAnnotateImages = function batchAnnotateImages ( ) {
139+ var args = arguejs ( {
140+ requests : Array ,
141+ options : [ gax . CallOptions ] ,
142+ callback : [ Function ]
143+ } , arguments ) ;
144+ var req = {
145+ requests : args . requests
146+ } ;
147+ return this . _batchAnnotateImages ( req , args . options , args . callback ) ;
148+ } ;
149+
150+ function ImageAnnotatorApiBuilder ( gaxGrpc ) {
151+ if ( ! ( this instanceof ImageAnnotatorApiBuilder ) ) {
152+ return new ImageAnnotatorApiBuilder ( gaxGrpc ) ;
153+ }
154+
155+ var grpcClient = gaxGrpc . load ( [ {
156+ root : require ( 'google-proto-files' ) ( '..' ) ,
157+ file : 'google/cloud/vision/v1/image_annotator.proto'
158+ } ] ) ;
159+ extend ( this , grpcClient . google . cloud . vision . v1 ) ;
160+
161+ /**
162+ * Build a new instance of {@link ImageAnnotatorApi}.
163+ *
164+ * @param {Object= } opts - The optional parameters.
165+ * @param {String= } opts.servicePath
166+ * The domain name of the API remote host.
167+ * @param {number= } opts.port
168+ * The port on which to connect to the remote host.
169+ * @param {grpc.ClientCredentials= } opts.sslCreds
170+ * A ClientCredentials for use with an SSL-enabled channel.
171+ * @param {Object= } opts.clientConfig
172+ * The customized config to build the call settings. See
173+ * {@link gax.constructSettings} for the format.
174+ * @param {number= } opts.timeout
175+ * The default timeout, in seconds, for calls made through this client.
176+ * @param {number= } opts.appName
177+ * The codename of the calling service.
178+ * @param {String= } opts.appVersion
179+ * The version of the calling service.
180+ */
181+ this . imageAnnotatorApi = function ( opts ) {
182+ return new ImageAnnotatorApi ( gaxGrpc , grpcClient , opts ) ;
183+ } ;
184+ extend ( this . imageAnnotatorApi , ImageAnnotatorApi ) ;
185+ }
186+ module . exports = ImageAnnotatorApiBuilder ;
187+ module . exports . SERVICE_ADDRESS = SERVICE_ADDRESS ;
188+ module . exports . ALL_SCOPES = ALL_SCOPES ;
0 commit comments