Skip to content

Commit

Permalink
feat(featuredfeed): Add featured feed to api
Browse files Browse the repository at this point in the history
Add featured feed to api available endpoints
  • Loading branch information
maximodleon committed Jan 21, 2018
1 parent 778fd78 commit 85f74d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"homepage": "https://github.com/maximodleon/wikipediajs#readme",
"dependencies": {
"axios": "0.17.1"
"axios": "0.17.1",
"xml-js": "1.6.2"
},
"devDependencies": {
"chai": "4.1.2",
Expand All @@ -38,4 +39,4 @@
"czConfig": {
"path": "node_modules/cz-conventional-changelog"
}
}
}
27 changes: 22 additions & 5 deletions src/wiki.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {
doSearch,
doRandom
} = require('./generators/index')
const { doSearch, doRandom } = require('./generators/index')
const { queryApi } = require('./utils/urlUtils')
const convert = require('xml-js')

function search(searchTerm, lang = "en", options) {
return doSearch(searchTerm, lang, options)
Expand All @@ -11,7 +10,25 @@ function random(lang = "en", options) {
return doRandom(lang, options)
}

function featured(options = { feed: "potd"}) {
const params = Object.assign({}, options, {
action: 'featuredfeed'
})

return queryApi("en", params)
.then((response) => {
if (response){
const json = convert.xml2js(response, {compact: false})
if (json.elements && json.elements.length) {
return json.elements[0]
}
}
}
)
}

module.exports = {
search,
random
random,
featured
};

0 comments on commit 85f74d4

Please sign in to comment.