Skip to content

Commit 1d657f3

Browse files
swcloudstephenplusplus
authored andcommitted
Introduce Gapic-generated files for cloud vision API. (googleapis#1576)
1 parent d6e6d78 commit 1d657f3

File tree

5 files changed

+257
-0
lines changed

5 files changed

+257
-0
lines changed

packages/vision/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@
5151
],
5252
"dependencies": {
5353
"@google-cloud/common": "^0.3.0",
54+
"arguejs": "^0.2.3",
5455
"arrify": "^1.0.0",
5556
"async": "^1.4.2",
5657
"extend": "^3.0.0",
58+
"google-gax": "^0.6.0",
59+
"google-proto-files": "^0.7.0",
5760
"is": "^3.0.1",
5861
"propprop": "^0.3.0",
5962
"request": "^2.70.0",

packages/vision/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1550,3 +1550,4 @@ Vision.formatSafeSearchAnnotation_ = function(ssAnnotation, options) {
15501550
};
15511551

15521552
module.exports = Vision;
1553+
module.exports.v1 = require('./v1');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"interfaces": {
3+
"google.cloud.vision.v1.ImageAnnotator": {
4+
"retry_codes": {
5+
"retry_codes_def": {
6+
"idempotent": [
7+
"DEADLINE_EXCEEDED",
8+
"UNAVAILABLE"
9+
],
10+
"non_idempotent": []
11+
}
12+
},
13+
"retry_params": {
14+
"default": {
15+
"initial_retry_delay_millis": 100,
16+
"retry_delay_multiplier": 1.3,
17+
"max_retry_delay_millis": 60000,
18+
"initial_rpc_timeout_millis": 60000,
19+
"rpc_timeout_multiplier": 1.0,
20+
"max_rpc_timeout_millis": 60000,
21+
"total_timeout_millis": 600000
22+
}
23+
},
24+
"methods": {
25+
"BatchAnnotateImages": {
26+
"timeout_millis": 60000,
27+
"retry_codes_name": "idempotent",
28+
"retry_params_name": "default"
29+
}
30+
}
31+
}
32+
}
33+
}

packages/vision/src/v1/index.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
'use strict';
17+
18+
var visionApi = require('./image_annotator_api');
19+
var extend = require('extend');
20+
var gax = require('google-gax');
21+
22+
function v1(options) {
23+
options = extend({
24+
scopes: v1.ALL_SCOPES
25+
}, options);
26+
var gaxGrpc = gax.grpc(options);
27+
return visionApi(gaxGrpc);
28+
}
29+
30+
v1.SERVICE_ADDRESS = visionApi.SERVICE_ADDRESS;
31+
v1.ALL_SCOPES = visionApi.ALL_SCOPES;
32+
module.exports = v1;

0 commit comments

Comments
 (0)