radio4000-sdk
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -39,17 +39,2 @@ 'use strict'; | ||
// Returns a the newest image in the form of a "src" string. | ||
// Expects a channel model object. | ||
var findChannelImage = function (channel) { | ||
if (!channel || !channel.images) { | ||
return Promise.reject(new Error('Channel does not have an image')); | ||
} | ||
var url = "images.json?orderBy=\"channel\"&startAt=\"" + (channel.id) + "\"&endAt=\"" + (channel.id) + "\"&limitToLast=1"; | ||
return fetchAndParse(url).then(toArray).then(function (arr) { return arr[0]; }).then(function (img) { | ||
var rootURL = 'https://res.cloudinary.com/radio4000/image/upload'; | ||
var transforms = "q_auto,w_56,h_56,c_thumb,c_fill,fl_lossy"; | ||
img.url = rootURL + "/" + transforms + "/" + (img.src); | ||
return img; | ||
}); | ||
}; | ||
var findTrack = function (id) { | ||
@@ -75,10 +60,2 @@ var url = "tracks/" + id + ".json"; | ||
return findChannelBySlug(slug).then(function (channel) { | ||
// Add a new "image" property from the latest image | ||
return findChannelImage(channel).then(function (img) { | ||
channel.image = { cloudinaryId: img.src, url: img.url }; | ||
return channel; | ||
}) | ||
// Allow it to continue without an image. | ||
.catch(function () { return channel; }); | ||
}).then(function (channel) { | ||
// Clean up | ||
@@ -92,2 +69,7 @@ delete channel.images; | ||
if (channel.image) { | ||
var url = "https://res.cloudinary.com/radio4000/image/upload/"; | ||
channel.imageUrl = url + "/w_500,h_500,c_thumb,fl_lossy/" + (channel.image); | ||
} | ||
// Save current state of backup. | ||
@@ -111,5 +93,4 @@ backup = channel; | ||
exports.findChannelBySlug = findChannelBySlug; | ||
exports.findChannelImage = findChannelImage; | ||
exports.findTrack = findTrack; | ||
exports.findTracksByChannel = findTracksByChannel; | ||
exports.createBackup = createBackup; |
@@ -33,17 +33,2 @@ import fetch from 'isomorphic-unfetch'; | ||
// Returns a the newest image in the form of a "src" string. | ||
// Expects a channel model object. | ||
var findChannelImage = function (channel) { | ||
if (!channel || !channel.images) { | ||
return Promise.reject(new Error('Channel does not have an image')); | ||
} | ||
var url = "images.json?orderBy=\"channel\"&startAt=\"" + (channel.id) + "\"&endAt=\"" + (channel.id) + "\"&limitToLast=1"; | ||
return fetchAndParse(url).then(toArray).then(function (arr) { return arr[0]; }).then(function (img) { | ||
var rootURL = 'https://res.cloudinary.com/radio4000/image/upload'; | ||
var transforms = "q_auto,w_56,h_56,c_thumb,c_fill,fl_lossy"; | ||
img.url = rootURL + "/" + transforms + "/" + (img.src); | ||
return img; | ||
}); | ||
}; | ||
var findTrack = function (id) { | ||
@@ -69,10 +54,2 @@ var url = "tracks/" + id + ".json"; | ||
return findChannelBySlug(slug).then(function (channel) { | ||
// Add a new "image" property from the latest image | ||
return findChannelImage(channel).then(function (img) { | ||
channel.image = { cloudinaryId: img.src, url: img.url }; | ||
return channel; | ||
}) | ||
// Allow it to continue without an image. | ||
.catch(function () { return channel; }); | ||
}).then(function (channel) { | ||
// Clean up | ||
@@ -86,2 +63,7 @@ delete channel.images; | ||
if (channel.image) { | ||
var url = "https://res.cloudinary.com/radio4000/image/upload/"; | ||
channel.imageUrl = url + "/w_500,h_500,c_thumb,fl_lossy/" + (channel.image); | ||
} | ||
// Save current state of backup. | ||
@@ -102,2 +84,2 @@ backup = channel; | ||
export { findChannel, findChannels, findChannelBySlug, findChannelImage, findTrack, findTracksByChannel, createBackup }; | ||
export { findChannel, findChannels, findChannelBySlug, findTrack, findTracksByChannel, createBackup }; |
@@ -39,17 +39,2 @@ (function (global, factory) { | ||
// Returns a the newest image in the form of a "src" string. | ||
// Expects a channel model object. | ||
var findChannelImage = function (channel) { | ||
if (!channel || !channel.images) { | ||
return Promise.reject(new Error('Channel does not have an image')); | ||
} | ||
var url = "images.json?orderBy=\"channel\"&startAt=\"" + (channel.id) + "\"&endAt=\"" + (channel.id) + "\"&limitToLast=1"; | ||
return fetchAndParse(url).then(toArray).then(function (arr) { return arr[0]; }).then(function (img) { | ||
var rootURL = 'https://res.cloudinary.com/radio4000/image/upload'; | ||
var transforms = "q_auto,w_56,h_56,c_thumb,c_fill,fl_lossy"; | ||
img.url = rootURL + "/" + transforms + "/" + (img.src); | ||
return img; | ||
}); | ||
}; | ||
var findTrack = function (id) { | ||
@@ -75,10 +60,2 @@ var url = "tracks/" + id + ".json"; | ||
return findChannelBySlug(slug).then(function (channel) { | ||
// Add a new "image" property from the latest image | ||
return findChannelImage(channel).then(function (img) { | ||
channel.image = { cloudinaryId: img.src, url: img.url }; | ||
return channel; | ||
}) | ||
// Allow it to continue without an image. | ||
.catch(function () { return channel; }); | ||
}).then(function (channel) { | ||
// Clean up | ||
@@ -92,2 +69,7 @@ delete channel.images; | ||
if (channel.image) { | ||
var url = "https://res.cloudinary.com/radio4000/image/upload/"; | ||
channel.imageUrl = url + "/w_500,h_500,c_thumb,fl_lossy/" + (channel.image); | ||
} | ||
// Save current state of backup. | ||
@@ -111,3 +93,2 @@ backup = channel; | ||
exports.findChannelBySlug = findChannelBySlug; | ||
exports.findChannelImage = findChannelImage; | ||
exports.findTrack = findTrack; | ||
@@ -114,0 +95,0 @@ exports.findTracksByChannel = findTracksByChannel; |
@@ -1,2 +0,2 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("isomorphic-unfetch")):"function"==typeof define&&define.amd?define(["exports","isomorphic-unfetch"],e):e(n.radio4000Sdk={},n.fetch)}(this,function(n,e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t=function(n,t){return void 0===t&&(t="https://radio4000.firebaseio.com"),e(t+"/"+n).then(function(n){return n.json()}).then(function(n){if(0===Object.keys(n).length)throw new Error("Not found");return n})},r=function(n,e){return Object.assign(n,{id:e})},o=function(n){return Object.keys(n).map(function(e){return r(n[e],e)})};var i=function(n){return t('channels.json?orderBy="slug"&startAt="'+n+'"&endAt="'+n+'"').then(o).then(function(n){return n[0]})},u=function(n){if(!n||!n.images)return Promise.reject(new Error("Channel does not have an image"));var e='images.json?orderBy="channel"&startAt="'+n.id+'"&endAt="'+n.id+'"&limitToLast=1';return t(e).then(o).then(function(n){return n[0]}).then(function(n){return n.url="https://res.cloudinary.com/radio4000/image/upload/q_auto,w_56,h_56,c_thumb,c_fill,fl_lossy/"+n.src,n})},c=function(n){if("string"!=typeof n)throw new Error("Pass a string with a valid channel id");return t('tracks.json?orderBy="channel"&startAt="'+n+'"&endAt="'+n+'"').then(o).then(function(n){return n.sort(function(n,e){return n.created-e.created})})};n.findChannel=function(n){return t("channels/"+n+".json").then(function(e){return r(e,n)})},n.findChannels=function(n){var e="channels.json";return n&&(e+='?orderBy="created"&limitToFirst='+n),t(e).then(o)},n.findChannelBySlug=i,n.findChannelImage=u,n.findTrack=function(n){return t("tracks/"+n+".json").then(function(e){return r(e,n)})},n.findTracksByChannel=c,n.createBackup=function(n){if(!n)throw new Error("Can not export channel without a `slug`");var e;return i(n).then(function(n){return u(n).then(function(e){return n.image={cloudinaryId:e.src,url:e.url},n}).catch(function(){return n})}).then(function(n){return delete n.images,delete n.channelPublic,delete n.favoriteChannels,delete n.isFeatured,delete n.isPremium,delete n.tracks,e=n,n}).then(function(n){return c(n.id)}).then(function(n){return e.tracks=n.map(function(n){return delete n.channel,n}),e}).catch(function(){return Promise.reject(new Error("Could not export your radio, sorry."))})},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("isomorphic-unfetch")):"function"==typeof define&&define.amd?define(["exports","isomorphic-unfetch"],e):e(n.radio4000Sdk={},n.fetch)}(this,function(n,e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var t=function(n,t){return void 0===t&&(t="https://radio4000.firebaseio.com"),e(t+"/"+n).then(function(n){return n.json()}).then(function(n){if(0===Object.keys(n).length)throw new Error("Not found");return n})},r=function(n,e){return Object.assign(n,{id:e})},o=function(n){return Object.keys(n).map(function(e){return r(n[e],e)})};var i=function(n){return t('channels.json?orderBy="slug"&startAt="'+n+'"&endAt="'+n+'"').then(o).then(function(n){return n[0]})},u=function(n){if("string"!=typeof n)throw new Error("Pass a string with a valid channel id");return t('tracks.json?orderBy="channel"&startAt="'+n+'"&endAt="'+n+'"').then(o).then(function(n){return n.sort(function(n,e){return n.created-e.created})})};n.findChannel=function(n){return t("channels/"+n+".json").then(function(e){return r(e,n)})},n.findChannels=function(n){var e="channels.json";return n&&(e+='?orderBy="created"&limitToFirst='+n),t(e).then(o)},n.findChannelBySlug=i,n.findTrack=function(n){return t("tracks/"+n+".json").then(function(e){return r(e,n)})},n.findTracksByChannel=u,n.createBackup=function(n){if(!n)throw new Error("Can not export channel without a `slug`");var e;return i(n).then(function(n){return delete n.images,delete n.channelPublic,delete n.favoriteChannels,delete n.isFeatured,delete n.isPremium,delete n.tracks,n.image&&(n.imageUrl="https://res.cloudinary.com/radio4000/image/upload//w_500,h_500,c_thumb,fl_lossy/"+n.image),e=n,n}).then(function(n){return u(n.id)}).then(function(n){return e.tracks=n.map(function(n){return delete n.channel,n}),e}).catch(function(){return Promise.reject(new Error("Could not export your radio, sorry."))})},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=radio4000-sdk.min.js.map |
{ | ||
"name": "radio4000-sdk", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -21,6 +21,6 @@ "main": "dist/radio4000-sdk.cjs.js", | ||
"devDependencies": { | ||
"ava": "^1.0.0-beta.3", | ||
"ava": "^0.25.0", | ||
"bili": "^2.2.7", | ||
"release-it": "^7.3.0", | ||
"xo": "0.20.3" | ||
"xo": "0.23.0" | ||
}, | ||
@@ -27,0 +27,0 @@ "xo": { |
@@ -18,3 +18,2 @@ # Radio4000 JavaScript SDK | ||
findChannelBySlug(channelSlug) | ||
findChannelImage(channelObject) | ||
findTrack(id) | ||
@@ -25,2 +24,4 @@ findTracksByChannel(channelId) | ||
> Note: the `findChannelImage(channelObject)` method was removed in 0.1.0 | ||
## Usage if you can `import` or `require` | ||
@@ -27,0 +28,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64
17961
230