-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generators index.js): Add random generator to the api
Add random generator endpoint call to the api wrapper
- Loading branch information
1 parent
c9cb9a1
commit 778fd78
Showing
6 changed files
with
59 additions
and
36 deletions.
There are no files selected for viewing
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,41 @@ | ||
const { | ||
queryApi | ||
} = require('../utils/urlUtils') | ||
|
||
const DEFAULT_PARAMS = { | ||
prop: 'info', | ||
inprop: 'url', | ||
format: 'json', | ||
action: 'query' | ||
} | ||
|
||
function doSearch(searchTerm, lang = "en", options = {}) { | ||
const params = _getParams(options, { | ||
gsrsearch: searchTerm, | ||
generator: 'search' | ||
}) | ||
|
||
return queryApi(lang, params).then((response) => { | ||
return response | ||
}) | ||
} | ||
|
||
function doRandom(lang = "en", options = {}) { | ||
const params = _getParams(options, { | ||
generator: 'random' | ||
}) | ||
|
||
return queryApi(lang, params).then((response) => { | ||
return response | ||
}) | ||
} | ||
|
||
function _getParams(queryOptions = {}, generatorOptions = {}) { | ||
return Object.assign({}, DEFAULT_PARAMS, queryOptions, generatorOptions) | ||
} | ||
|
||
|
||
module.exports = { | ||
doSearch, | ||
doRandom | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
const { | ||
doSearch | ||
} = require('./generators/search') | ||
doSearch, | ||
doRandom | ||
} = require('./generators/index') | ||
|
||
function search(searchTerm, lang = "en", options) { | ||
return doSearch(searchTerm, lang, options) | ||
} | ||
|
||
function random(lang = "en", options) { | ||
return doRandom(lang, options) | ||
} | ||
|
||
module.exports = { | ||
search | ||
search, | ||
random | ||
}; |