func DownloadPhoto()

in cobra/aid/unsplash.go [77:105]


func DownloadPhoto(params model.UnsplashRandomPhotoParameters, cred model.Credential, photoSizes []string) error {
	response, err := RequestRandomPhoto(params, cred)
	if err != nil {
		return err
	}

	dumpUnsplashRandomPhotoResponse(response)

	dirPath, err := helper.CreateDirectoryNamedPath("downloads/unsplash/" + params.Query)
	if err != nil {
		return err
	}

	if params.Size == "all" {
		for _, pSize := range photoSizes {
			if pSize != "all" {
				params.Size = pSize
				err = helper.DownloadFile(getPhotoURLBySize(params, response), dirPath, response.ID+"-"+pSize+".jpeg")
				if err != nil {
					return err
				}
			}
		}
	} else {
		err = helper.DownloadFile(getPhotoURLBySize(params, response), dirPath, response.ID+".jpeg")
	}

	return err
}