Skip to content

Commit

Permalink
Make Bundle.getinfo() return another Bundle
Browse files Browse the repository at this point in the history
* update docs

Fixes: #19
  • Loading branch information
srl295 committed Dec 2, 2016
1 parent 597c1df commit aa1ddda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ the bundle is not created.
<a name="Bundle+getInfo"></a>

### bundle.getInfo(opts, cb)
Get bundle info
Get bundle info. Returns a new Bundle object with additional fields populated.

**Kind**: instance method of <code>[Bundle](#Bundle)</code>

Expand All @@ -477,7 +477,7 @@ Get bundle info
| opts.translationStatusMetricsByLanguage | <code>Boolean</code> | Optional field (false by default) |
| opts.reviewStatusMetricsByLanguage | <code>Boolean</code> | Optional field (false by default) |
| opts.partnerStatusMetricsByLanguage | <code>Boolean</code> | Optional field (false by default) |
| cb | <code>[getInfoCallback](#Bundle..getInfoCallback)</code> | callback (err, { updatedBy, updatedAt, sourceLanguage, targetLanguages, readOnly, metadata, partner} ) |
| cb | <code>[getInfoCallback](#Bundle..getInfoCallback)</code> | callback (err, Bundle ) |

<a name="Bundle+getStrings"></a>

Expand Down
15 changes: 10 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,13 @@ Bundle.prototype.getInfoFields = new utils.Fields(["translationStatusMetricsByLa
"reviewStatusMetricsByLanguage",
"partnerStatusMetricsByLanguage"]);
/**
* Get bundle info
* Get bundle info. Returns a new Bundle object with additional fields populated.
* @param {Object} opts - Options object
* @param {String} opts.fields - Comma separated list of fields
* @param {Boolean} opts.translationStatusMetricsByLanguage - Optional field (false by default)
* @param {Boolean} opts.reviewStatusMetricsByLanguage - Optional field (false by default)
* @param {Boolean} opts.partnerStatusMetricsByLanguage - Optional field (false by default)
* @param {Bundle~getInfoCallback} cb - callback (err, { updatedBy, updatedAt, sourceLanguage, targetLanguages, readOnly, metadata, partner} )
* @param {Bundle~getInfoCallback} cb - callback (err, Bundle )
*/
Bundle.prototype.getInfo = function getBundleInfo(opts, cb) {
if(!opts) opts = {};
Expand All @@ -528,12 +528,17 @@ Bundle.prototype.getInfo = function getBundleInfo(opts, cb) {
// if we are given an update date, but no metadata, assume {}.
data.bundle.metadata = {};
}
// Make this a date object and not a string.
if(data.bundle.updatedAt) {
data.bundle.updatedAt = new Date(data.bundle.updatedAt);
}
// NOTE: this should be a Bundle object. https://github.com/IBM-Bluemix/gp-js-client/issues/19
// var b = that.gp.bundle(that, data.bundle);
cb(null, data.bundle, data);
// Copy these fields over. The REST getInfo call will not set them.
data.bundle.id = data.bundle.id || that.id;
data.bundle.serviceInstance = data.bundle.serviceInstance || that.serviceInstance;

var b = that.gp.bundle(data.bundle);

cb(null, b, data);
}
});
};
Expand Down
7 changes: 7 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ describe('gaasClient.bundle()', function() {
expect(bundle2.updatedBy).to.be.a('string');
expect(bundle2.updatedAt).to.be.a('date');
expect(bundle2.sourceLanguage).to.equal(gaasTest.SOURCES[0]);
expect(bundle2.readOnly).to.be.a('boolean');
expect(bundle2.readOnly).to.equal(false);
expect(bundle2.metadata).to.be.an('object');
expect(bundle2.metadata).to.deep.equal({});
expect(bundle2.id).to.equal(projectId);
// bundle2 is itself a bundle object.
expect(bundle2.getBundleInfo).to.be.a('function');
done();
});
});
Expand Down

0 comments on commit aa1ddda

Please sign in to comment.