forked from drewthoennes/Bored-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds API v2 which includes a bulkier activities API and facts, riddle…
…s, and websites APIs
- Loading branch information
1 parent
5919645
commit d1d0577
Showing
54 changed files
with
2,429 additions
and
585 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"fact":"The first computer was invented in the 1940s.","source":"https://bestlifeonline.com/random-fun-facts","key":"8929851"} | ||
{"fact":"The unicorn is the national animal of Scotland.","source":"https://bestlifeonline.com/random-fun-facts/","key":"4920184"} | ||
{"fact":"Playing the accordion was once required for teachers in North Korea.","source":"https://bestlifeonline.com/random-fun-facts/","key":"1848104"} | ||
{"fact":"Water makes different pouring sounds depending on its temperature.","source":"https://bestlifeonline.com/random-fun-facts/","key":"2562345"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"question":"You live in a one story house made entirely of redwood. What color would the stairs be?","answer":"What stairs? You live in a one-story house.","difficulty":"easy","source":"https://www.riddles.com/","key":"3684252"} | ||
{"question":"What has six faces, but does not wear makeup, has twenty-one eyes, but cannot see? What is it?","answer":"A die.","difficulty":"easy","source":"https://www.riddles.com/","key":"7643252"} | ||
{"question":"What can you catch but never throw?","answer":"A cold.","difficulty":"normal","source":"https://www.riddles.com/","key":"7974324"} | ||
{"question":"Who is that with a neck and no head, two arms and no hands? What is it?","answer":"A shirt.","difficulty":"hard","source":"https://www.riddles.com/","key":"2347324"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{"url":"https://weirdorconfusing.com","description":"Random random being sold.","key":"4298747"} | ||
{"url":"http://eelslap.com","description":"Eel slap.","key":"8738873"} | ||
{"url":"https://heeeeeeeey.com","description":"Hey there.","key":"9723037"} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Activity = require('@b/models/Activity'); | ||
|
||
exports.findActivity = params => { | ||
return Activity.findOne(params).then(activity => { | ||
if (!activity) { | ||
throw new Error('No activities found with the specified parameters'); | ||
} | ||
|
||
return activity; | ||
}); | ||
}; | ||
|
||
exports.findRandomActivity = params => { | ||
return Activity.countDocuments(params).then(count => { | ||
if (!count || count === 0) throw new Error('No activity found with the specified parameters'); | ||
|
||
return Activity.findOne(params).skip(Math.floor(Math.random() * count)); | ||
}).then(activity => { | ||
if (!activity) throw new Error('No activity found with the specified parameters'); | ||
|
||
return activity; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Fact = require('@b/models/Fact'); | ||
|
||
exports.findFactByKey = key => { | ||
return Fact.findOne({'key': key}).then(fact => { | ||
if (!fact) { | ||
throw new Error('No facts found with the specified parameters'); | ||
} | ||
|
||
return fact; | ||
}); | ||
}; | ||
|
||
exports.findRandomFact = () => { | ||
return Fact.countDocuments().then(count => { | ||
if (!count || count === 0) throw new Error('No facts found'); | ||
|
||
return Fact.findOne().skip(Math.floor(Math.random() * count)); | ||
}).then(fact => { | ||
if (!fact) throw new Error('No facts found'); | ||
|
||
return fact; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Riddle = require('@b/models/Riddle'); | ||
|
||
exports.findRiddle = params => { | ||
return Riddle.findOne(params).then(riddle => { | ||
if (!riddle) { | ||
throw new Error('No riddles found with the specified parameters'); | ||
} | ||
|
||
return riddle; | ||
}); | ||
}; | ||
|
||
exports.findRandomRiddle = params => { | ||
return Riddle.countDocuments(params).then(count => { | ||
if (!count || count === 0) throw new Error('No riddles found with the specified query'); | ||
|
||
return Riddle.findOne(params).skip(Math.floor(Math.random() * count)); | ||
}).then(riddle => { | ||
if (!riddle) throw new Error('No riddles found with the specified query'); | ||
|
||
return riddle; | ||
}); | ||
}; |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const Website = require('@b/models/Website'); | ||
|
||
exports.findWebsiteByKey = key => { | ||
return Website.findOne({'key': key}).then(website => { | ||
if (!website) { | ||
throw new Error('No websites found with the specified parameters'); | ||
} | ||
|
||
return website; | ||
}); | ||
}; | ||
|
||
exports.findRandomWebsite = () => { | ||
return Website.countDocuments().then(count => { | ||
if (!count || count === 0) throw new Error('No websites found'); | ||
|
||
return Website.findOne().skip(Math.floor(Math.random() * count)); | ||
}).then(website => { | ||
if (!website) throw new Error('No websites found'); | ||
|
||
return website; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = function(router) { | ||
// Add res.error method for error reporting | ||
router.use((req, res, next) => { | ||
res.error = function(err) { | ||
res.json({'error': err}); | ||
}; | ||
|
||
next(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const expressMiddleware = require('./express'); | ||
|
||
exports.validate = (schema) => { | ||
return (req, res, next) => { | ||
let err = schema.validate(req.body).error; | ||
if (err != null) { | ||
res.error(`Invalid fields: ${err}`); | ||
return; | ||
} | ||
|
||
next(); | ||
}; | ||
} | ||
|
||
exports.express = function(router) { | ||
// Add res.error method for error reporting | ||
router.use((req, res, next) => { | ||
res.error = function(err) { | ||
res.json({'error': err}); | ||
}; | ||
|
||
next(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
var ActivitySchema = new mongoose.Schema({ | ||
const activitySchema = new mongoose.Schema({ | ||
activity: { | ||
type: String, | ||
trim: true, | ||
required: true | ||
}, | ||
accessibility: { // 0.0 - 1.0 | ||
type: Number | ||
}, | ||
type: { // Sport, education, entertainment, social, ... | ||
type: String | ||
type: { | ||
type: String, | ||
enum: ['charity', 'cooking', 'music', 'diy', 'education', 'social', 'busywork', 'recreational', 'relaxation'], | ||
required: true | ||
}, | ||
participants: { // 1 - n | ||
type: Number | ||
type: Number, | ||
required: true | ||
}, | ||
price: { // 0.0 - 1.0 | ||
type: Number | ||
type: Number, | ||
required: true | ||
}, | ||
link: { // URL to resource | ||
type: String | ||
availability: { // 0.0 - 1.0 | ||
type: Number, | ||
required: true | ||
}, | ||
key: { | ||
accessibility: { | ||
type: String, | ||
enum: ['Few to no challenges', 'Minor challenges', 'Major challenges'] | ||
}, | ||
duration: { | ||
type: String, | ||
enum: ['minutes', 'hours', 'days', 'weeks'], | ||
default: 'minutes', | ||
required: true | ||
}, | ||
enabled: { | ||
kidFriendly: { | ||
type: Boolean, | ||
default: false, | ||
required: true | ||
}, | ||
link: { // URL to resource | ||
type: String | ||
}, | ||
key: { | ||
type: String, | ||
required: true | ||
} | ||
}, { | ||
collection: 'activities' | ||
}); | ||
|
||
module.exports = mongoose.model('Activity', ActivitySchema); | ||
module.exports = mongoose.model('Activity', activitySchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const factSchema = new mongoose.Schema({ | ||
fact: { | ||
type: String, | ||
required: true | ||
}, | ||
source: { | ||
type: String | ||
}, | ||
key: { | ||
type: String, | ||
required: true | ||
} | ||
}, { | ||
collection: 'facts' | ||
}); | ||
|
||
module.exports = mongoose.model('Fact', factSchema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const riddleSchema = new mongoose.Schema({ | ||
question: { | ||
type: String, | ||
required: true | ||
}, | ||
answer: { | ||
type: String, | ||
required: true | ||
}, | ||
difficulty: { | ||
type: String, | ||
enum: ['easy', 'normal', 'hard'], | ||
default: 'normal', | ||
required: true | ||
}, | ||
source: { | ||
type: String | ||
}, | ||
key: { | ||
type: String, | ||
required: true | ||
} | ||
}, { | ||
collection: 'riddles' | ||
}); | ||
|
||
module.exports = mongoose.model('Riddle', riddleSchema); |
Oops, something went wrong.