/**
* Pixabay API fetch function.
* @see {@link http://pixabay.com/api/docs/}
* @function lib.fetch.pixabayApiFetch
* @param {object} queryData - Query data.
* @param {string} queryData.username - Pixabay user name.
* @param {string} queryData.key - Pixabay access key.
* @param {string} [queryData.id] - id, id_hash, or a comma separated list of values to retrieve details or high resolution URLs of specific images. In a comma separated list, ids and id_hashs cannot be used together.
Note: The number of id_hash queries for "response_group=image_details" is limited to 30 images per day and to 350 images in 30 days. The same limit aplies to id queries for "response_group=high_resolution". When over quota, the API tells you to slow down.
* @param {string} [queryData.search_term] - A URL encoded string to search for. If omitted, all images are returned in the selected order.
Example: "yellow+flower"
* @param {string} [queryData.lang="en"] - Language code of the language to be searched in.
Accepted values: id, cs, de, en, es, fr, it, nl, no, hu, ru, pl, pt, ro, fi, sv, tr, ja, ko, zh
Default: "en"
* @param {string} [queryData.image_type="all"] - A media type to search within.
Accepted values: "all", "photo", "clipart", "vector"
Default: "all"
* @param {string} [queryData.orientation="all"] - Whether an image is wider than it is tall, or taller than it is wide.
Accepted values: "all", "landscape", "portrait"
Default: "all"
* @param {string} [queryData.min_width="0"] - Minimum image width.
Default: "0"
* @param {string} [queryData.min_height="0"] - Minimum image height.
Default: "0"
* @param {string} [queryData.editors_choice] - Select images that have received an Editor's Choice award.
Accepted values: "true", "false"
Default: "false"
* @param {string} [queryData.order="popular"] - How the results should be ordered.
Accepted values: "popular", "latest"
Default: "popular"
* @param {string} [queryData.page=1] - Returned search results are paginated. Use this parameter to select the page number.
Default: 1
* @param {string} [queryData.per_page=20] - Determine the number of results per page.
Accepted values: 8 - 100
Default: 20
* @param {function} callback - Callback when done.
* @author Taka Okunishi
*/
var appendQuery = require('../url').appendQuery;
exports = module.exports = function (queryData, callback) {
if (!queryData.username) {
callback(new Error('Username is required.'));
return;
}
if (!queryData.key) {
callback(new Error('Key is required.'));
return;
}
var requestURL = appendQuery('http://pixabay.com/api/', queryData);
exports._getJSON(requestURL, function (err, data) {
callback(err, data);
});
};
exports._getJSON = function (url, callback) {
require('request').get({
url: url,
json: true
}, function (err, res, data) {
callback(err, data);
});
};