|
| 1 | +/*! |
| 2 | + * Copyright 2017 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 | + |
| 17 | +/*! |
| 18 | + * @module compute/project |
| 19 | + */ |
| 20 | + |
| 21 | +'use strict'; |
| 22 | + |
| 23 | +var common = require('@google-cloud/common'); |
| 24 | +var util = require('util'); |
| 25 | + |
| 26 | +/*! Developer Documentation |
| 27 | + * |
| 28 | + * @param {module:compute} compute - Compute object this project belongs to. |
| 29 | + */ |
| 30 | +/** |
| 31 | + * A Project object allows you to interact with your Google Compute Engine |
| 32 | + * project. |
| 33 | + * |
| 34 | + * @resource [Projects Overview]{@link https://cloud.google.com/compute/docs/projects} |
| 35 | + * @resource [Projects Resource]{@link https://cloud.google.com/compute/docs/reference/v1/projects} |
| 36 | + * |
| 37 | + * @constructor |
| 38 | + * @alias module:compute/project |
| 39 | + * |
| 40 | + * @example |
| 41 | + * var project = gce.project(); |
| 42 | + */ |
| 43 | +function Project(compute) { |
| 44 | + this.id = compute.projectId; |
| 45 | + |
| 46 | + var methods = { |
| 47 | + /** |
| 48 | + * Get a Project object. |
| 49 | + * |
| 50 | + * @example |
| 51 | + * project.get(function(err, project, apiResponse) { |
| 52 | + * // `project` is a Project object. |
| 53 | + * }); |
| 54 | + * |
| 55 | + * //- |
| 56 | + * // If the callback is omitted, we'll return a Promise. |
| 57 | + * //- |
| 58 | + * project.get().then(function(data) { |
| 59 | + * var project = data[0]; |
| 60 | + * var apiResponse = data[1]; |
| 61 | + * }); |
| 62 | + */ |
| 63 | + get: true, |
| 64 | + |
| 65 | + /** |
| 66 | + * Get the project's metadata. |
| 67 | + * |
| 68 | + * @resource [Projects: get API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/projects/get} |
| 69 | + * @resource [Projects Resource]{@link https://cloud.google.com/compute/docs/reference/v1/projects} |
| 70 | + * |
| 71 | + * @param {function=} callback - The callback function. |
| 72 | + * @param {?error} callback.err - An error returned while making this |
| 73 | + * request. |
| 74 | + * @param {object} callback.metadata - The machine type's metadata. |
| 75 | + * @param {object} callback.apiResponse - The full API response. |
| 76 | + * |
| 77 | + * @example |
| 78 | + * project.getMetadata(function(err, metadata, apiResponse) {}); |
| 79 | + * |
| 80 | + * //- |
| 81 | + * // If the callback is omitted, we'll return a Promise. |
| 82 | + * //- |
| 83 | + * project.getMetadata().then(function(data) { |
| 84 | + * var metadata = data[0]; |
| 85 | + * var apiResponse = data[1]; |
| 86 | + * }); |
| 87 | + */ |
| 88 | + getMetadata: true |
| 89 | + }; |
| 90 | + |
| 91 | + common.ServiceObject.call(this, { |
| 92 | + parent: compute, |
| 93 | + baseUrl: '', |
| 94 | + id: '', |
| 95 | + methods: methods |
| 96 | + }); |
| 97 | +} |
| 98 | + |
| 99 | +util.inherits(Project, common.ServiceObject); |
| 100 | + |
| 101 | +/*! Developer Documentation |
| 102 | + * |
| 103 | + * All async methods (except for streams) will return a Promise in the event |
| 104 | + * that a callback is omitted. |
| 105 | + */ |
| 106 | +common.util.promisifyAll(Project); |
| 107 | + |
| 108 | +module.exports = Project; |
0 commit comments