diff --git a/lib/ludumdare/index.js b/lib/ludumdare/index.js index 96f23b9..9584fe5 100644 --- a/lib/ludumdare/index.js +++ b/lib/ludumdare/index.js @@ -3,7 +3,6 @@ import deb from 'debug' import {compact} from 'lodash'; import axios from 'axios' -import LudumDareById from './ludumDateAPIs' const debug = deb('ldstats:new-api') @@ -20,6 +19,13 @@ class LudumDareAPI { getUrl = () => `${this.ssl ? 'https' : 'http'}://api.ldjam.com/v${this.version}` getLDId = response => response.data.node[0].parent + getLDName = id => axios + .get(`${this.getUrl()}/node/get/${id}`) + .then(({data}) => parseInt(data.node[0].slug)); + //make sure the ludum dare competition is not finished + getLDFinished = id => axios + .get(`${this.getUrl()}/node/get/${id}`) + .then(({data}) => data.node[0].meta['event-finished']) parseUser = username => ({data}) => { let {path, extra, node} = data @@ -33,11 +39,27 @@ class LudumDareAPI { return node // user id } - setConfig = response => ({ - config: LudumDareById[this.getLDId(response)], - response - }) - + setConfig = response => axios + //gets what this ludum dare is called + .all([this.getLDName(this.getLDId(response))]) + .then(data => ({ + config: { + ludum: data[0], + //grades are always like this, for every ludum dare + grades: { + 'grade-01': 'Overall', + 'grade-02': 'Fun', + 'grade-03': 'Innovation', + 'grade-04': 'Theme', + 'grade-05': 'Graphics', + 'grade-06': 'Audio', + 'grade-07': 'Humor', + 'grade-08': 'Mood' + } + }, + response + })); + parseEntry = ({response, config}) => { let {ludum, grades} = config let [entry] = response.data.node @@ -79,12 +101,13 @@ class LudumDareAPI { // resolves an entry by id entry = id => axios .get(`${this.getUrl()}/node/get/${id}`) - .then(res => LudumDareById[this.getLDId(res)] ? res : Promise.reject(new Error('UNKNOWN-LUDUM-DARE'))) + //if it is not finished, then the ratings won't be available yet + .then(res => this.getLDFinished(this.getLDId(res)) ? res : Promise.reject(new Error('UNFINSHED-LUDUM-DARE'))) .then(this.setConfig) .then(this.parseEntry) .catch(error => { - if (error.message === 'UNKNOWN-LUDUM-DARE') { - debug('Unexpected LD'); + if (error.message === 'UNFINSHED-LUDUM-DARE') { + debug('Unfinished Ludum Dare'); return; } diff --git a/lib/ludumdare/ludumDateAPIs.js b/lib/ludumdare/ludumDateAPIs.js deleted file mode 100644 index e27ba19..0000000 --- a/lib/ludumdare/ludumDateAPIs.js +++ /dev/null @@ -1,73 +0,0 @@ -// TODO: improve this hardcode into a fetch from the api - -// Data fetched by calling https://api.ldjam.com/vx/node/get/[ludum id] -// More info of LD API at https://github.com/pjnovas/ldstats/issues/11#issuecomment-305979066 -// For getting stats: https://api.ldjam.com/vx/stats/[ludum id] - -export default { - '9405': { - ludum: 38, - grades: { - 'grade-01': 'Overall', - 'grade-02': 'Fun', - 'grade-03': 'Innovation', - 'grade-04': 'Theme', - 'grade-05': 'Graphics', - 'grade-06': 'Audio', - 'grade-07': 'Humor', - 'grade-08': 'Mood' - } - }, - '32802': { - ludum: 39, - grades: { - 'grade-01': 'Overall', - 'grade-02': 'Fun', - 'grade-03': 'Innovation', - 'grade-04': 'Theme', - 'grade-05': 'Graphics', - 'grade-06': 'Audio', - 'grade-07': 'Humor', - 'grade-08': 'Mood' - } - }, - '49883': { - ludum: 40, - grades: { - 'grade-01': 'Overall', - 'grade-02': 'Fun', - 'grade-03': 'Innovation', - 'grade-04': 'Theme', - 'grade-05': 'Graphics', - 'grade-06': 'Audio', - 'grade-07': 'Humor', - 'grade-08': 'Mood' - } - }, - '73256': { - ludum: 41, - grades: { - 'grade-01': 'Overall', - 'grade-02': 'Fun', - 'grade-03': 'Innovation', - 'grade-04': 'Theme', - 'grade-05': 'Graphics', - 'grade-06': 'Audio', - 'grade-07': 'Humor', - 'grade-08': 'Mood' - } - }, - '97793': { - ludum: 42, - grades: { - 'grade-01': 'Overall', - 'grade-02': 'Fun', - 'grade-03': 'Innovation', - 'grade-04': 'Theme', - 'grade-05': 'Graphics', - 'grade-06': 'Audio', - 'grade-07': 'Humor', - 'grade-08': 'Mood' - } - } -}