Skip to content

Commit

Permalink
respnod to CR
Browse files Browse the repository at this point in the history
  • Loading branch information
cmerchant committed Oct 23, 2017
1 parent 9ab6dd4 commit 1ca4158
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 103 deletions.
26 changes: 8 additions & 18 deletions lib/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,13 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
return validation.promiseOrCallback(exec, callback);
};

self.getApplicationsStream = (options) => {
let exec = co(function *() {
let headers = yield ensureAuthHeaders(options);

return yield req.get({
headers : headers,
pathname : '/v2/devices',
query : options,
rawStream : true
});
});

return exec;
};
self.getClientCredentials = (deviceId, options, callback) => {
// handle any non-specified input params
if (typeof options === 'function') {
callback = options;
options = undefined;
}

self.getClientCredentialsStream = (deviceId, options) => {
let exec = co(function *() {
if (validation.isEmpty(deviceId)) {
return yield Promise.reject(new Error('deviceId is required'));
Expand All @@ -163,12 +154,11 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
return yield req.get({
headers : headers,
pathname : ['/v2/devices/', deviceId.replace(/\:/g, ''), '/activation'].join(''),
query : options,
rawStream : true
query : options
});
});

return exec;
return validation.promiseOrCallback(exec, callback);
};

self.getOrder = (orderId, options, callback) => {
Expand Down
65 changes: 0 additions & 65 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ This module can be used to interact with Playnetwork's socket-io service, https:
* [emit](#emit)


- - -

### Provision

This module can be used to interact with the [Provision API](https://provision-api.apps.playnetwork.com/v1/docs) to get activation information such as clientId/sharedSecret and a list of apps needed for installation or update.

* [getApplicationsStream](#getApplicationsStream)
* [getClientCredentialsStream](#getClientCredentialsStream)

- - -

### Settings
Expand Down Expand Up @@ -1454,62 +1445,6 @@ client

- - -

### Provision Module

The provision module is designed to simplify interaction with the [PlayNetwork Playback API](https://provision-api.apps.playnetwork.com/v1/docs). This module supports the following methods:


#### #getApplicationsStream

This method can be used to retrieve a stream that when read will contain a yml files that can be consumed by docker compose

**Usage:** `client.provision.getApplicationsStream(options)`

* `options` - _(optional)_ - can be used to supply authorization headers such as clientId/secret i.e. can override defaults

```javascript
client
.provision
.getApplicationsStream({
'x-client-id': 'test',
'x-authentication-token': 'test'
})
.then((applicaitonsYmlStream) => {
// read applications stream
}).catch((err) => {
console.error(err);
});
```

[back to top](#usage)

#### #getClientCredentialsStream

This method can be used to retrieve a stream that when read will contain a client ID and shared secret that the device can use to interact with Playnetwork APIs. The provision module will use a default credential set initially if there are no actual credentials defined.

**Usage:** `client.provision.getClientCredentialsStream(deviceId, options)`

* `deviceId` - _(required)_ - defines the device identifier, in most cases, the mac address of the device
* `options` - _(optional)_ - can be used to supply authorization headers such as clientId/secret i.e. can override defaults

```javascript
client
.provision
.getClientCredentialsStream({
'x-client-id': 'test',
'x-authentication-token': 'test'
})
.then((credentialsStream) => {
// read credentials stream
}).catch((err) => {
console.error(err);
});
```

[back to top](#usage)

- - -

### Settings Module

The settings module is designed to simplify interaction with the [PlayNetwork Settings API](https://curio-settings-api.apps.playnetwork.com/v0/docs). This module supports the following methods:
Expand Down
42 changes: 22 additions & 20 deletions test/lib/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ describe('provision', () => {
});
});

describe('#getClientCredentialsStream', () => {
describe('#getClientCredentials', () => {
it('should properly retrieve credentials (promise)', (done) => {
// intercept outbound request
nock('https://provision-api.apps.playnetwork.com')
.get('/v2/devices/5/activation')
.reply(200, {} );

provision.getClientCredentialsStream('5')
provision.getClientCredentials('5')
.then((result) => {
should.exist(result);
should.exist(requestInfo);
Expand All @@ -383,37 +383,39 @@ describe('provision', () => {
.catch((err) => (done(err)));
});

it('should reject with error without device id ', (done) => {
it('should properly retrieve credentials (callback)', (done) => {
// intercept outbound request
nock('https://provision-api.apps.playnetwork.com')
.get('/v2/devices/5/activation')
.reply(200, {} );

provision.getClientCredentialsStream()
.then((result) => {
return done(new Error('should have rejected'))
})
.catch((err) => {
err.message.should.equals('deviceId is required');
return done();
})
provision.getClientCredentials('5', function(err, result) {
if (err) {
console.log(err);
return done(err);
}

should.exist(result);
should.exist(requestInfo);

return done();
});
});
});

describe('#getApplicationsStream', () => {
it('should return a list of apps', (done) => {
it('should reject with error without device id ', (done) => {
// intercept outbound request
nock('https://provision-api.apps.playnetwork.com')
.get('/v2/devices')
.reply(200, ['app1', 'app2', 'app3'] );
.get('/v2/devices/5/activation')
.reply(200, {} );

provision.getApplicationsStream()
provision.getClientCredentials()
.then((result) => {
should.exist(result);

return done(new Error('should have rejected'))
})
.catch((err) => {
err.message.should.equals('deviceId is required');
return done();
})
.catch((err) => (done(err)));
});
});

Expand Down

0 comments on commit 1ca4158

Please sign in to comment.