Skip to content

Commit

Permalink
Merge pull request #65 from PlayNetwork/v1.3.10
Browse files Browse the repository at this point in the history
v1.3.10 - Added getProfile and updateProfile commands to provision proxy
  • Loading branch information
tsmith1985 committed Aug 9, 2018
2 parents bb28962 + 593fd06 commit 8bd09a1
Show file tree
Hide file tree
Showing 4 changed files with 410 additions and 17 deletions.
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.3.10 - 2018/08/07

* Added getProfile and updateProfile commands to provision proxy

# v1.3.9 - 2018/08/01

* Added support for Music/findBroadcastsByStationId route
Expand Down
243 changes: 227 additions & 16 deletions lib/provision.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
req.on(EVENT_REQUEST, (data) => (self.emit(EVENT_REQUEST, data)));
req.on(EVENT_RESPONSE, (data) => (self.emit(EVENT_RESPONSE, data)));

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

let exec = co(function *() {

let headers = yield ensureAuthHeaders(options);

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

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

self.allOrders = (options, callback) => {
// handle any non-specified input params
if (typeof options === 'function') {
Expand All @@ -66,6 +88,26 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
return validation.promiseOrCallback(exec, callback);
};

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

let exec = co(function *() {
let headers = yield ensureAuthHeaders(options);

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

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

self.call = (options, callback) => {
if (typeof options === 'function') {
callback = options;
Expand Down Expand Up @@ -98,6 +140,55 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
return validation.promiseOrCallback(exec, callback);
};

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

let exec = co(function *() {

let headers = yield ensureAuthHeaders(options);

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

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

self.createDevice = (device, callback) => {
// handle any non-specified input params
if (typeof device === 'function') {
callback = device;
device = undefined;
}

let exec = co(function *() {
if (validation.isEmpty(device)) {
return yield Promise.reject(new Error('device is required'));
}

if (validation.isEmpty(device.deviceId)) {
return yield Promise.reject(new Error('deviceId is required'));
}

let headers = yield ensureAuthHeaders();

return yield req.post({
headers : headers,
pathname : '/v2/devices'
}, device);
});

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

self.createOrder = (order, callback) => {
// handle any non-specified input params
if (typeof order === 'function') {
Expand Down Expand Up @@ -137,57 +228,78 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
return validation.promiseOrCallback(exec, callback);
};

self.checkUpdate = (options, callback) => {
self.createProfile = (profile, callback) => {
// handle any non-specified input params
if (typeof options === 'function') {
callback = options;
options = undefined;
if (typeof profile === 'function') {
callback = profile;
profile = undefined;
}

let exec = co(function *() {
if (validation.isEmpty(profile)) {
return yield Promise.reject(new Error('profile is required'));
}

let headers = yield ensureAuthHeaders(options);
if (validation.isEmpty(profile.clientId)) {
return yield Promise.reject(new Error('clientId is required'));
}

return yield req.head({
if (validation.isEmpty(profile.applications)) {
return yield Promise.reject(new Error('applications are required'));
}

if (validation.isEmpty(profile.template)) {
return yield Promise.reject(new Error('template is required'));
}

let headers = yield ensureAuthHeaders();

return yield req.post({
headers : headers,
pathname : '/v2/applications',
query : options,
rawStream : true
});
pathname : '/v2/profiles'
}, profile);
});

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

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

let exec = co(function *() {
if (validation.isEmpty(deviceId)) {
return yield Promise.reject(new Error('deviceId is required'));
}

let headers = yield ensureAuthHeaders(options);

return yield req.get({
headers : headers,
pathname : '/v2/applications',
query : options,
rawStream : true
pathname : ['/v2/devices/', deviceId.replace(/\:/g, ''), '/activation'].join(''),
query : options
});
});

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

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

if (typeof deviceId === 'function') {
callback = deviceId;
deviceId = undefined;
options = undefined;
}

let exec = co(function *() {
if (validation.isEmpty(deviceId)) {
return yield Promise.reject(new Error('deviceId is required'));
Expand All @@ -197,7 +309,7 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {

return yield req.get({
headers : headers,
pathname : ['/v2/devices/', deviceId.replace(/\:/g, ''), '/activation'].join(''),
pathname : `/v2/devices/${deviceId}`,
query : options
});
});
Expand Down Expand Up @@ -235,8 +347,65 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
return validation.promiseOrCallback(exec, callback);
};

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

if (typeof profileAlias === 'function') {
callback = profileAlias;
profileAlias = undefined;
options = undefined;
}

let exec = co(function *() {
if (validation.isEmpty(profileAlias)) {
return yield Promise.reject(new Error('profileAlias is required'));
}

let headers = yield ensureAuthHeaders(options);

return yield req.get({
headers : headers,
pathname : `/v2/profiles/${profileAlias}`,
query : options
});
});

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

self.settings = () => (settings);

self.updateDevice = (device, callback) => {
// handle any non-specified input params
if (typeof device === 'function') {
callback = device;
device = undefined;
}

let exec = co(function *() {
if (validation.isEmpty(device)) {
return yield Promise.reject(new Error('device is required'));
}

if (validation.isEmpty(device.deviceId)) {
return yield Promise.reject(new Error('deviceId is required'));
}

let headers = yield ensureAuthHeaders();

return yield req.put({
headers : headers,
pathname : `/v2/devices/${device.deviceId}`
}, device);
});

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

self.updateOrder = (order, callback) => {
// handle any non-specified input params
if (typeof order === 'function') {
Expand Down Expand Up @@ -264,6 +433,48 @@ module.exports = function (provisionOptions, ensureAuthHeaders, self) {
return validation.promiseOrCallback(exec, callback);
};

self.updateProfile = (profileAlias, profile, callback) => {
// handle any non-specified input params
if (typeof profile === 'function') {
callback = profile;
profile = undefined;
}

if (typeof profileAlias === 'object') {
profile = profileAlias;
profileAlias = undefined;
}

if (typeof profileAlias === 'function') {
callback = profileAlias;
profileAlias = undefined;
profile = undefined;
}

let exec = co(function *() {
if (validation.isEmpty(profile)) {
return yield Promise.reject(new Error('profile is required'));
}

if (validation.isEmpty(profileAlias)) {
profileAlias = profile.profileId
}

if (validation.isEmpty(profileAlias)) {
return yield Promise.reject(new Error('profileAlias is required'));
}

let headers = yield ensureAuthHeaders();

return yield req.put({
headers : headers,
pathname : `/v2/profiles/${profileAlias}`
}, profile);
});

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

self.version = (callback) => {
let exec = co(function *() {
return yield req.get({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "playnetwork-sdk",
"version": "1.3.9",
"version": "1.3.10",
"contributors": [
{
"name": "Joshua Thomas",
Expand Down
Loading

0 comments on commit 8bd09a1

Please sign in to comment.