Update deps, refactor rdio for 3.1

This commit is contained in:
Jonathan Cremin 2015-08-20 00:23:42 +01:00
parent 24b17261aa
commit cb711ea510
6 changed files with 84 additions and 88 deletions

View file

@ -1 +0,0 @@
https://github.com/kudos/heroku-buildpack-nodejs-jspm.git

View file

@ -1,32 +1,34 @@
'use strict'; import { parse } from 'url';
var parse = require('url').parse; import bluebird from 'bluebird';
var Promise = require('bluebird'); import rdioInit from 'rdio';
import { match as urlMatch } from './url';
module.exports.id = 'rdio'; export let id = 'rdio';
if (!process.env.RDIO_CLIENT_ID || !process.env.RDIO_CLIENT_SECRET || !process.env.RDIO_REFRESH_TOKEN) { if (!process.env.RDIO_CLIENT_ID || !process.env.RDIO_CLIENT_SECRET || !process.env.RDIO_REFRESH_TOKEN) {
console.warn('RDIO_CLIENT_ID, RDIO_REFRESH_TOKEN or RDIO_CLIENT_SECRET environment variables not found, deactivating Rdio.'); console.warn('RDIO_CLIENT_ID, RDIO_REFRESH_TOKEN or RDIO_CLIENT_SECRET environment constiables not found, deactivating Rdio.');
} else { }
var Rdio = require('rdio'); const Rdio = rdioInit({
var rdio = new Rdio({ rdio: {
clientId: process.env.RDIO_CLIENT_ID, clientId: process.env.RDIO_CLIENT_ID,
clientSecret: process.env.RDIO_CLIENT_SECRET, clientSecret: process.env.RDIO_CLIENT_SECRET,
refreshToken: process.env.RDIO_REFRESH_TOKEN }
}); });
var rdio = Promise.promisifyAll(rdio); const rdio = bluebird.promisifyAll(new Rdio());
module.exports.match = require('./url').match; export const match = urlMatch;
module.exports.lookupId = function*(id) { export function* lookupId(id) {
yield rdio.loginAsync(); yield rdio.getClientTokenAsync();
var result = yield rdio.callAsync('getObjectFromShortCode', {'short_code': id}); const response = yield rdio.requestAsync({method: 'getObjectFromShortCode', short_code: id}, false);
var parsedShortUrl = parse(result.shortUrl); const result = response.result;
var rid = parsedShortUrl.path.replace('/x/', '').replace('/', ''); const parsedShortUrl = parse(result.shortUrl);
var type = result.album ? 'track' : 'album'; const rid = parsedShortUrl.path.replace('/x/', '').replace('/', '');
const type = result.album ? 'track' : 'album';
var item = { const item = {
service: 'rdio', service: 'rdio',
type: type, type: type,
id: rid, id: rid,
@ -49,30 +51,34 @@ module.exports.lookupId = function*(id) {
return item; return item;
}; };
module.exports.parseUrl = function *(url) { export function* parseUrl(url) {
var parsedUrl = parse(url); const parsedUrl = parse(url);
var method; let query, args;
var args;
if (parsedUrl.host === 'rd.io') { if (parsedUrl.host === 'rd.io') {
method = 'getObjectFromShortCode'; query = {
args = {'short_code': parsedUrl.path.replace('/x/', '').replace('/', '')}; method: 'getObjectFromShortCode',
short_code: parsedUrl.path.replace('/x/', '').replace('/', '')
};
} else if (parsedUrl.host.match(/rdio\.com$/)) { } else if (parsedUrl.host.match(/rdio\.com$/)) {
method = 'getObjectFromUrl'; query = {
args = {url: parsedUrl.path}; method: 'getObjectFromUrl',
url: parsedUrl.path
};
} else { } else {
var error = new Error('Not Found'); const error = new Error('Not Found');
error.status = 404; error.status = 404;
throw error; throw error;
} }
yield rdio.loginAsync(); yield rdio.getClientTokenAsync();
var result = yield rdio.callAsync(method, args); const response = yield rdio.requestAsync(query, false);
var parsedShortUrl = parse(result.shortUrl); const result = response.result;
var id = parsedShortUrl.path.replace('/x/', '').replace('/', ''); const parsedShortUrl = parse(result.shortUrl);
var type = result.album ? 'track' : 'album'; const id = parsedShortUrl.path.replace('/x/', '').replace('/', '');
var item = { const type = result.album ? 'track' : 'album';
const item = {
service: 'rdio', service: 'rdio',
type: type, type: type,
id: id, id: id,
@ -95,9 +101,9 @@ module.exports.parseUrl = function *(url) {
return item; return item;
}; };
module.exports.search = function *(data) { export function* search(data) {
var query, albumClean; let query, albumClean;
var type = data.type; const type = data.type;
if (type === 'album') { if (type === 'album') {
query = data.artist.name + ' ' + data.name; query = data.artist.name + ' ' + data.name;
@ -111,9 +117,9 @@ module.exports.search = function *(data) {
} }
} }
yield rdio.loginAsync(); yield rdio.getClientTokenAsync();
var response = yield rdio.callAsync('search', {query: query, types: type}); const response = yield rdio.requestAsync({method: 'search', query: query, types: type}, false);
var result = response.results.filter(function(item) { const result = response.result.results.filter(function(item) {
if (type === 'album' && item.name.match(/([^\(\[]+)/)[0] === albumClean) { if (type === 'album' && item.name.match(/([^\(\[]+)/)[0] === albumClean) {
return item; return item;
} else if (type === 'track' && (item.album.match(/([^\(\[]+)/)[0] === albumClean || !albumClean)) { } else if (type === 'track' && (item.album.match(/([^\(\[]+)/)[0] === albumClean || !albumClean)) {
@ -122,9 +128,9 @@ module.exports.search = function *(data) {
}).shift(); }).shift();
if (!result) { if (!result) {
var matches = albumClean.match(/^[^\(\[]+/); const matches = albumClean.match(/^[^\(\[]+/);
if (matches && matches[0] && matches[0] !== albumClean) { if (matches && matches[0] && matches[0] !== albumClean) {
var cleanedData = JSON.parse(JSON.stringify(data)); const cleanedData = JSON.parse(JSON.stringify(data));
if (type === 'album') { if (type === 'album') {
cleanedData.name = matches[0].trim(); cleanedData.name = matches[0].trim();
} else if (type === 'track') { } else if (type === 'track') {
@ -135,9 +141,9 @@ module.exports.search = function *(data) {
return {service: 'rdio'}; return {service: 'rdio'};
} }
} else { } else {
var parsedShortUrl = parse(result.shortUrl); const parsedShortUrl = parse(result.shortUrl);
var id = parsedShortUrl.path.replace('/x/', '').replace('/', ''); const id = parsedShortUrl.path.replace('/x/', '').replace('/', '');
var item = { const item = {
service: 'rdio', service: 'rdio',
type: type, type: type,
id: id, id: id,
@ -160,5 +166,3 @@ module.exports.search = function *(data) {
return item; return item;
} }
}; };
}

View file

@ -1,7 +1,6 @@
"use strict"; import { parse } from 'url';
var parse = require('url').parse;
module.exports.match = function(url) { export function match(url) {
var parsed = parse(url); var parsed = parse(url);
if (!parsed.host.match(/rd\.io$/) && !parsed.host.match(/rdio\.com$/)) { if (!parsed.host.match(/rd\.io$/) && !parsed.host.match(/rdio\.com$/)) {
return false; return false;

View file

@ -11,11 +11,11 @@
"test": "mocha --require co-mocha --compilers js:babel/register test/**/*.js --timeout=10000", "test": "mocha --require co-mocha --compilers js:babel/register test/**/*.js --timeout=10000",
"watch": "parallelshell \"npm run watch-js\" \"npm run watch-server\"", "watch": "parallelshell \"npm run watch-js\" \"npm run watch-server\"",
"watch-js": "babel --modules system -wd public/views views", "watch-js": "babel --modules system -wd public/views views",
"watch-server": "nodemon -x \"node -r babel/register\" -e js,jsx -i public/ app.js" "watch-server": "nodemon -x \"babel-node\" -e js,jsx -i public/ app.js"
}, },
"engines": { "engines": {
"iojs": "^2.4.0", "iojs": "^2.5.0",
"npm": "^3.2.0" "npm": "^3.3.0"
}, },
"dependencies": { "dependencies": {
"babel": "~5.8.3", "babel": "~5.8.3",
@ -24,7 +24,7 @@
"browserify": "~11.0.0", "browserify": "~11.0.0",
"co": "~4.6.0", "co": "~4.6.0",
"debug": "~2.2.0", "debug": "~2.2.0",
"jspm": "~0.16.0-beta.3", "jspm": "~0.16.0",
"koa": "~0.21.0", "koa": "~0.21.0",
"koa-bodyparser": "~2.0.0", "koa-bodyparser": "~2.0.0",
"koa-compress": "~1.0.8", "koa-compress": "~1.0.8",
@ -36,25 +36,25 @@
"mongodb-promisified": "~1.0.2", "mongodb-promisified": "~1.0.2",
"node-uuid": "~1.4.2", "node-uuid": "~1.4.2",
"playmusic": "~2.0.0", "playmusic": "~2.0.0",
"rdio": "~2.0.0", "rdio": "^3.1.0",
"react": "~0.13.3", "react": "~0.13.3",
"react-google-analytics": "~0.2.0", "react-google-analytics": "~0.2.0",
"react-router": "~0.13.3", "react-router": "~0.13.3",
"reactify": "~1.1.1", "reactify": "~1.1.1",
"spotify": "~0.3.0", "spotify": "~0.3.0",
"superagent": "~1.2.0", "superagent": "~1.3.0",
"superagent-bluebird-promise": "~2.0.2" "superagent-bluebird-promise": "~2.0.2"
}, },
"devDependencies": { "devDependencies": {
"co-mocha": "~1.1.0", "co-mocha": "~1.1.0",
"eslint": "~0.24.0", "eslint": "~1.2.0",
"eslint-plugin-react": "~3.0.0", "eslint-plugin-react": "~3.2.3",
"istanbul": "^0.3.17", "istanbul": "^0.3.17",
"mocha": "~2.2.5", "mocha": "~2.2.5",
"nodemon": "~1.3.8", "nodemon": "~1.4.1",
"parallelshell": "~1.2.0", "parallelshell": "~2.0.0",
"should": "~7.0.1", "should": "~7.0.1",
"spdy": "~1.32.4" "spdy": "~2.0.4"
}, },
"jspm": { "jspm": {
"directories": { "directories": {

View file

@ -1,15 +1,13 @@
System.config({ System.config({
"baseURL": "/", baseURL: "/",
"defaultJSExtensions": true, defaultJSExtensions: true,
"transpiler": "none", transpiler: "none",
"paths": { paths: {
"github:*": "jspm_packages/github/*", "github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*" "npm:*": "jspm_packages/npm/*"
} },
});
System.config({ depCache: {
"depCache": {
"npm:react@0.13.3/lib/PooledClass.js": [ "npm:react@0.13.3/lib/PooledClass.js": [
"npm:react@0.13.3/lib/invariant.js", "npm:react@0.13.3/lib/invariant.js",
"github:jspm/nodelibs-process@0.1.1.js" "github:jspm/nodelibs-process@0.1.1.js"
@ -1082,11 +1080,9 @@ System.config({
"views/head.js", "views/head.js",
"views/error.js" "views/error.js"
] ]
} },
});
System.config({ map: {
"map": {
"react": "npm:react@0.13.3", "react": "npm:react@0.13.3",
"react-google-analytics": "npm:react-google-analytics@0.2.0", "react-google-analytics": "npm:react-google-analytics@0.2.0",
"react-router": "npm:react-router@0.13.3", "react-router": "npm:react-router@0.13.3",
@ -1095,7 +1091,7 @@ System.config({
"assert": "npm:assert@1.3.0" "assert": "npm:assert@1.3.0"
}, },
"github:jspm/nodelibs-buffer@0.1.0": { "github:jspm/nodelibs-buffer@0.1.0": {
"buffer": "npm:buffer@3.3.1" "buffer": "npm:buffer@3.4.2"
}, },
"github:jspm/nodelibs-constants@0.1.0": { "github:jspm/nodelibs-constants@0.1.0": {
"constants-browserify": "npm:constants-browserify@0.0.1" "constants-browserify": "npm:constants-browserify@0.0.1"
@ -1169,7 +1165,7 @@ System.config({
"path": "github:jspm/nodelibs-path@0.1.0", "path": "github:jspm/nodelibs-path@0.1.0",
"process": "github:jspm/nodelibs-process@0.1.1" "process": "github:jspm/nodelibs-process@0.1.1"
}, },
"npm:asn1.js@2.1.3": { "npm:asn1.js@2.2.0": {
"assert": "github:jspm/nodelibs-assert@0.1.0", "assert": "github:jspm/nodelibs-assert@0.1.0",
"bn.js": "npm:bn.js@2.2.0", "bn.js": "npm:bn.js@2.2.0",
"buffer": "github:jspm/nodelibs-buffer@0.1.0", "buffer": "github:jspm/nodelibs-buffer@0.1.0",
@ -1184,7 +1180,7 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.1", "process": "github:jspm/nodelibs-process@0.1.1",
"systemjs-json": "github:systemjs/plugin-json@0.1.0" "systemjs-json": "github:systemjs/plugin-json@0.1.0"
}, },
"npm:browserify-aes@1.0.2": { "npm:browserify-aes@1.0.3": {
"buffer": "github:jspm/nodelibs-buffer@0.1.0", "buffer": "github:jspm/nodelibs-buffer@0.1.0",
"buffer-xor": "npm:buffer-xor@1.0.2", "buffer-xor": "npm:buffer-xor@1.0.2",
"create-hash": "npm:create-hash@1.1.1", "create-hash": "npm:create-hash@1.1.1",
@ -1201,7 +1197,7 @@ System.config({
"crypto": "github:jspm/nodelibs-crypto@0.1.0", "crypto": "github:jspm/nodelibs-crypto@0.1.0",
"randombytes": "npm:randombytes@2.0.1" "randombytes": "npm:randombytes@2.0.1"
}, },
"npm:browserify-sign@3.0.2": { "npm:browserify-sign@3.0.3": {
"bn.js": "npm:bn.js@2.2.0", "bn.js": "npm:bn.js@2.2.0",
"browserify-rsa": "npm:browserify-rsa@2.0.1", "browserify-rsa": "npm:browserify-rsa@2.0.1",
"buffer": "github:jspm/nodelibs-buffer@0.1.0", "buffer": "github:jspm/nodelibs-buffer@0.1.0",
@ -1211,8 +1207,7 @@ System.config({
"elliptic": "npm:elliptic@3.1.0", "elliptic": "npm:elliptic@3.1.0",
"inherits": "npm:inherits@2.0.1", "inherits": "npm:inherits@2.0.1",
"parse-asn1": "npm:parse-asn1@3.0.1", "parse-asn1": "npm:parse-asn1@3.0.1",
"stream": "github:jspm/nodelibs-stream@0.1.0", "stream": "github:jspm/nodelibs-stream@0.1.0"
"systemjs-json": "github:systemjs/plugin-json@0.1.0"
}, },
"npm:browserify-zlib@0.1.4": { "npm:browserify-zlib@0.1.4": {
"assert": "github:jspm/nodelibs-assert@0.1.0", "assert": "github:jspm/nodelibs-assert@0.1.0",
@ -1226,7 +1221,7 @@ System.config({
"buffer": "github:jspm/nodelibs-buffer@0.1.0", "buffer": "github:jspm/nodelibs-buffer@0.1.0",
"systemjs-json": "github:systemjs/plugin-json@0.1.0" "systemjs-json": "github:systemjs/plugin-json@0.1.0"
}, },
"npm:buffer@3.3.1": { "npm:buffer@3.4.2": {
"base64-js": "npm:base64-js@0.0.8", "base64-js": "npm:base64-js@0.0.8",
"ieee754": "npm:ieee754@1.1.6", "ieee754": "npm:ieee754@1.1.6",
"is-array": "npm:is-array@1.0.1" "is-array": "npm:is-array@1.0.1"
@ -1266,8 +1261,8 @@ System.config({
"stream": "github:jspm/nodelibs-stream@0.1.0" "stream": "github:jspm/nodelibs-stream@0.1.0"
}, },
"npm:crypto-browserify@3.9.14": { "npm:crypto-browserify@3.9.14": {
"browserify-aes": "npm:browserify-aes@1.0.2", "browserify-aes": "npm:browserify-aes@1.0.3",
"browserify-sign": "npm:browserify-sign@3.0.2", "browserify-sign": "npm:browserify-sign@3.0.3",
"create-ecdh": "npm:create-ecdh@2.0.1", "create-ecdh": "npm:create-ecdh@2.0.1",
"create-hash": "npm:create-hash@1.1.1", "create-hash": "npm:create-hash@1.1.1",
"create-hmac": "npm:create-hmac@1.1.3", "create-hmac": "npm:create-hmac@1.1.3",
@ -1386,8 +1381,8 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.1" "process": "github:jspm/nodelibs-process@0.1.1"
}, },
"npm:parse-asn1@3.0.1": { "npm:parse-asn1@3.0.1": {
"asn1.js": "npm:asn1.js@2.1.3", "asn1.js": "npm:asn1.js@2.2.0",
"browserify-aes": "npm:browserify-aes@1.0.2", "browserify-aes": "npm:browserify-aes@1.0.3",
"buffer": "github:jspm/nodelibs-buffer@0.1.0", "buffer": "github:jspm/nodelibs-buffer@0.1.0",
"create-hash": "npm:create-hash@1.1.1", "create-hash": "npm:create-hash@1.1.1",
"pbkdf2": "npm:pbkdf2@3.0.4", "pbkdf2": "npm:pbkdf2@3.0.4",
@ -1518,4 +1513,3 @@ System.config({
} }
} }
}); });

View file

@ -1,5 +1,5 @@
import 'should'; import 'should';
import rdio from '../../lib/services/rdio'; import * as rdio from '../../lib/services/rdio';
describe('Rdio', function(){ describe('Rdio', function(){
describe('lookupId', function(){ describe('lookupId', function(){