Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions lib/ludumdare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
73 changes: 0 additions & 73 deletions lib/ludumdare/ludumDateAPIs.js

This file was deleted.