 log = new Log logSettings
 
 
-# Map of resolution property names.
+# Array of resolution property names.
 resolutions = [
   'previewURL'
   'webformatURL'

]


isValidId = (id) -> !isNaN(id) && parseInt(id) >= 0


isValidResolution = (res) -> humanResolutions.indexOf(res) > -1


getResolutionCode = (res) -> humanResolutions.indexOf res



    
# Downloads an image.
#
# @param [String] id the Pixabay image ID
# @param [Number] resolution the resolution to download the image in
# @param [String] destination the path of the destination file
#
download = (id, resolution, destination) ->
  # Build URL for API request.
  url = buildUrl(user.apiKey, id, resolution)
  
  log.info 'Requesting information for image with ID ' \
    + id \
    + ' from ' \
    + url
    
  # Call out to Pixabay.
  options =
    url: url
    json: true
  request options, (error, response, body) ->
    if error || !body || !body.hits
      log.error 'Couldn\'t get information about image with ID \'' \
        + id \
        + '\''
    else
      url = body.hits[0][resolutions[resolution]];
      log.info 'Downloading file from ' \
        + url
      file = fs.createWriteStream destination
      req = https.get url, (response) ->
        response.pipe file

      
# Installs a single image.
