Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pubsub: convert to grpc #1070

Merged
merged 1 commit into from
Feb 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions lib/common/grpc-service-object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*!
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*!
* @module common/grpcServiceObject
*/

'use strict';

var extend = require('extend');
var nodeutil = require('util');

/**
* @type {module:common/serviceObject}
* @private
*/
var ServiceObject = require('./service-object.js');

/**
* @type {module:common/util}
* @private
*/
var util = require('./util.js');

/**
* GrpcServiceObject is a base class, meant to be inherited from by a service
* object that uses the gRPC protobuf API.
*
* @private
*
* @param {object} config - Configuration object.
*/
function GrpcServiceObject(config) {
ServiceObject.call(this, config);
}

nodeutil.inherits(GrpcServiceObject, ServiceObject);

/**
* Delete the object.
*
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
*/
GrpcServiceObject.prototype.delete = function(callback) {
var protoOpts = this.methods.delete.protoOpts;
var reqOpts = this.methods.delete.reqOpts;

this.request(protoOpts, reqOpts, callback || util.noop);
};

/**
* Get the metadata of this object.
*
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {object} callback.metadata - The metadata for this object.
*/
GrpcServiceObject.prototype.getMetadata = function(callback) {
var protoOpts = this.methods.getMetadata.protoOpts;
var reqOpts = this.methods.getMetadata.reqOpts;

this.request(protoOpts, reqOpts, callback);
};

/**
* Set the metadata for this object.
*
* @param {object} metadata - The metadata to set on this object.
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
*/
GrpcServiceObject.prototype.setMetadata = function(metadata, callback) {
var protoOpts = this.methods.setMetadata.protoOpts;
var reqOpts = extend(true, {}, this.methods.setMetadata.reqOpts, metadata);

this.request(protoOpts, reqOpts, callback || util.noop);
};

/**
* Patch a request to the GrpcService object.
*
* @private
*/
GrpcServiceObject.prototype.request = function(protoOpts, reqOpts, callback) {
this.parent.request(protoOpts, reqOpts, callback);
};

module.exports = GrpcServiceObject;
Loading