 # @param [Number] res the resolution code of the image to get
 #
 buildUrl = (apiKey, id, res) ->
-  "https://pixabay.com/api/?key=#{user.apiKey}" \
+  "https://pixabay.com/api/?key=#{apiKey}" \
     + (if res > 1 then '&response_group=high_resolution' else '') \
     + "&id=#{id}"
 

persistUser = (obj, callback) ->
  if obj then user = obj # Replace loaded user.
  persist USER_PATH, user, callback


# Returns true if a request to the Pixabay API was successful.
#
# @param [Object] error any error returned with the response
# @param [Object] body the body of the response
#
isSuccessful = (error, body) ->
  !error \
  && body \
  && body.hits \
  && body.hits instanceof Array \
  && body.hits.length > 0


# Downloads an image.

                  + ' in to source control.' # Project setup success!


# Validates that an API key works with Pixabay.
#
# @param [String] key the API key to validate
# @param [Function] callback the function to call back on
#
validateApiKey = (key, callback) ->
  url = buildUrl key, '195893', 0 # We know this image exists.
  options =
    url: url
    json: true
  request url, (error, response, body) -> # Request image JSON using API key.
    callback(!error && response.statusCode == 200)


# Walks the user through initializing their user file.
#
auth = () ->
