11/*!
2- * Copyright 2014 Google Inc. All Rights Reserved.
2+ * Copyright 2015 Google Inc. All Rights Reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2626 */
2727var util = require ( '../common/util.js' ) ;
2828
29- /**
30- * Create an Address object to interact with a Google Compute Engine address.
29+ /*! Developer Documentation
3130 *
32- * @constructor
33- * @alias module:region/address
31+ * @param {module:region } region - Region this address belongs to.
32+ * @param {string } name - The name of the address.
33+ */
34+ /**
35+ * An Address object allows you to interact with a Google Compute Engine
36+ * address.
3437 *
35- * @throws {Error } if an address name or a region are not provided.
38+ * @resource [Instances and Networks]{@link https://cloud.google.com/compute/docs/instances-and-network}
39+ * @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses} *
3640 *
37- * @param {module:region } region - The Google Compute Engine region this
38- * address belongs to.
39- * @param {string } name - The name of the address.
40- * @param {object= } metadata - Address metadata.
41+ * @constructor
42+ * @alias module:compute/address
4143 *
4244 * @example
4345 * var gcloud = require('gcloud')({
44- * keyFilename: '/path/to/keyfile.json'
46+ * keyFilename: '/path/to/keyfile.json',
47+ * projectId: 'grape-spaceship-123'
4548 * });
4649 *
47- * var compute = gcloud.compute();
50+ * var gce = gcloud.compute();
4851 *
49- * var myRegion = compute .region('region-name');
52+ * var region = gce .region('region-name');
5053 *
51- * var address = myRegion .address('address1');
54+ * var address = region .address('address1');
5255 */
53- function Address ( region , name , metadata ) {
56+ function Address ( region , name ) {
5457 this . region = region ;
5558 this . name = name ;
56- this . metadata = metadata ;
57-
58- if ( ! util . is ( this . name , 'string' ) ) {
59- throw new Error ( 'A name is needed to use a Compute Engine Address.' ) ;
60- }
61- if ( ! this . region ) {
62- throw new Error ( 'A region is needed to use a Compute Engine Address.' ) ;
63- }
59+ this . metadata = { } ;
6460}
6561
6662/**
6763 * Delete the address.
6864 *
69- * @param {function } callback - The callback function.
65+ * @resource [Addresses: delete API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/delete}
66+ *
67+ * @param {function= } callback - The callback function.
68+ * @param {?error } callback.err - An error returned while making this request.
69+ * @param {module:compute/operation } callback.operation - An operation object
70+ * that can be used to check the status of the request.
71+ * @param {object } callback.apiResponse - The full API response.
7072 *
7173 * @example
72- * address.delete(function(err, operation) {
73- * // `operation` is an Operation object and can be used to check the status
74- * // of address deletion .
74+ * address.delete(function(err, operation, apiResponse ) {
75+ * // `operation` is an Operation object that can be used to check the status
76+ * // of the request .
7577 * });
7678 */
7779Address . prototype . delete = function ( callback ) {
7880 callback = callback || util . noop ;
81+
7982 var region = this . region ;
80- this . makeReq_ ( 'DELETE' , '' , null , true , function ( err , resp ) {
83+
84+ this . makeReq_ ( 'DELETE' , '' , null , null , function ( err , resp ) {
8185 if ( err ) {
82- callback ( err ) ;
86+ callback ( err , null , resp ) ;
8387 return ;
8488 }
89+
8590 var operation = region . operation ( resp . name ) ;
8691 operation . metadata = resp ;
87- callback ( null , operation ) ;
92+
93+ callback ( null , operation , resp ) ;
8894 } ) ;
8995} ;
9096
9197/**
92- * Get the address' metadata.
98+ * Get the metadata of this address.
99+ *
100+ * @resource [Address Resource]{@link https://cloud.google.com/compute/docs/reference/v1/addresses}
101+ * @resource [Addresses: get API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/addresses/get}
93102 *
94103 * @param {function= } callback - The callback function.
104+ * @param {?error } callback.err - An error returned while making this request
105+ * @param {object } callback.metadata - The address's metadata.
106+ * @param {object } callback.apiResponse - The full API response.
95107 *
96108 * @example
97109 * address.getMetadata(function(err, metadata, apiResponse) {});
98110 */
99111Address . prototype . getMetadata = function ( callback ) {
100112 callback = callback || util . noop ;
113+
101114 var self = this ;
115+
102116 this . makeReq_ ( 'GET' , '' , null , null , function ( err , resp ) {
103117 if ( err ) {
104- callback ( err ) ;
118+ callback ( err , null , resp ) ;
105119 return ;
106120 }
121+
107122 self . metadata = resp ;
123+
108124 callback ( null , self . metadata , resp ) ;
109125 } ) ;
110126} ;
@@ -126,4 +142,4 @@ Address.prototype.makeReq_ = function(method, path, query, body, callback) {
126142 this . region . makeReq_ ( method , path , query , body , callback ) ;
127143} ;
128144
129- module . exports = Address ;
145+ module . exports = Address ;
0 commit comments