Skip to content

Commit

Permalink
Update getSubject function
Browse files Browse the repository at this point in the history
Provide optional array of field names to limit the fields returned.
  • Loading branch information
iamigo committed Sep 20, 2018
1 parent 88fff68 commit 166292d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions docs/api/subjects.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ Returns a Bluebird Promise which resolves to the hierarchy json.


## getSubject
`getSubject(absolutePath)` => `Promise`
`getSubject(absolutePath, fields)` => `Promise`

Retrieve the specified Subject.
Retrieve the specified Subject. Limit the fields returned by providing an optional array of field names.

| Param | Type | Description |
| --- | --- | --- |
| absolutePath | `String` | The absolutePath of the Subject to retrieve. |
| fields | `Array` | Optional array of field names to return. |

Returns a Bluebird `Promise` which resolves to the specified Subject.

Expand Down
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,21 @@ class RefocusClient {
} // getSubjects

/**
* Retrieve the specified subject.
* Retrieve the specified subject. Limit the fields returned by providing an
* optional array of field names.
*
* @param {String} absolutePath - The absolutePath of the subject to
* retrieve.
* @param {Array} fields - Optional array of field names to return.
* @returns {Promise} a Bluebird Promise which resolves to the specified
* subject.
*/
getSubject(absolutePath) {
return req.get(this.token,
`${this.url}/${this.version}/subjects/${absolutePath}`);
getSubject(absolutePath, fields = []) {
let u = `${this.url}/${this.version}/subjects/${absolutePath}`;
if (Array.isArray(fields) && fields.length > 0) {
u += `?fields=${fields.join()}`;
}
return req.get(this.token, u);
} // getSubject

/**
Expand Down

0 comments on commit 166292d

Please sign in to comment.