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

View file

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

View file

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

View file

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

View file

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