Skip to content

Commit

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

Fixes: #19
  • Loading branch information
srl295 committed Dec 2, 2016
1 parent 597c1df commit 3264612
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
11 changes: 6 additions & 5 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 Expand Up @@ -551,21 +551,22 @@ Update some strings in a language.
<a name="Bundle..getInfoCallback"></a>

### Bundle~getInfoCallback : <code>function</code>
Callback returned by Bundle~getInfo().
NOTE: this will be changed to be an actual Bundle object - see https://github.com/IBM-Bluemix/gp-js-client/issues/19
Callback returned by Bundle~getInfo().

**Kind**: inner typedef of <code>[Bundle](#Bundle)</code>

| Param | Type | Description |
| --- | --- | --- |
| err | <code>object</code> | error, or null |
| bundle | <code>Object</code> | bundle object with additional data |
| bundle | <code>[Bundle](#Bundle)</code> | bundle object with additional data |
| bundle.updatedBy | <code>string</code> | userid that updated this bundle |
| bundle.updatedAt | <code>Date</code> | date when the bundle was last updated |
| bundle.sourceLanguage | <code>string</code> | bcp47 id of the source language |
| bundle.targetLanguages | <code>Array.&lt;string&gt;</code> | array of target langauge bcp47 ids |
| bundle.readOnly | <code>boolean</code> | true if this bundle can only be read |
| bundle.metadata | <code>Object.&lt;string, string&gt;</code> | array of user-editable metadata |
| bundle.translationStatusMetricsByLanguage | <code>Object</code> | additional metrics information |
| bundle.reviewStatusMetricsByLanguage | <code>Object</code> | additional metrics information |

<a name="User"></a>

Expand Down
20 changes: 13 additions & 7 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 All @@ -546,17 +551,18 @@ Bundle.prototype.getBundleInfo = Bundle.prototype.getInfo;

/**
* Callback returned by Bundle~getInfo().
* NOTE: this will be changed to be an actual Bundle object - see https://github.com/IBM-Bluemix/gp-js-client/issues/19
* @callback Bundle~getInfoCallback
* @param {object} err - error, or null
* @param {Object} bundle - bundle object with additional data
* @param {Bundle} bundle - bundle object with additional data
*
* @param {string} bundle.updatedBy - userid that updated this bundle
* @param {Date} bundle.updatedAt - date when the bundle was last updated
* @param {string} bundle.sourceLanguage - bcp47 id of the source language
* @param {string[]} bundle.targetLanguages - array of target langauge bcp47 ids
* @param {boolean} bundle.readOnly - true if this bundle can only be read
* @param {Object.<string,string>} bundle.metadata - array of user-editable metadata
* @param {Object} bundle.translationStatusMetricsByLanguage - additional metrics information
* @param {Object} bundle.reviewStatusMetricsByLanguage - additional metrics information
*/
/**
* Fetch one language's strings
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 3264612

Please sign in to comment.