Image Downloader is a command-line tool that allows you to download a list of images from a plain text file. It is designed to fulfill the requirements set by "The Big Picture Corp" for downloading images from URLs and storing them on the local hard drive.
Here's a quick explanation of why this approach was chosen:
-
Modular Structure: The code is organized into modules (
Images::Downloader
andImages::Validator
), promoting modularity and separation of concerns. This structure allows for easy maintenance, extensibility, and reuse of code. -
Error Handling: The code incorporates error handling by raising custom exceptions (
Errors::FILE_NOT_FOUND
,Errors::FILE_EMPTY
,Errors::URL_INVALID_CONTENT_TYPE
). This ensures that errors are properly handled and appropriate error messages are provided to users. -
File Validation: The
check_file
method validates the existence and non-empty nature of the input file. This ensures that the code can handle different file scenarios and provides meaningful feedback when the file is invalid. -
URL Validation: The
check_url
method validates the URL and its content type. It checks if the URL is accessible and verifies if the content type is an image. This validation helps filter out invalid URLs and ensures that only images are downloaded. -
Batch Processing: The implementation supports batch processing of image URLs from the plain text file. It iterates through each URL, validates it, and downloads the valid images. The code maintains a count of the downloaded images and collects any encountered errors for reporting purposes.
-
Logging and Reporting: The implementation incorporates logging using
ActiveSupport::Logger
. It logs the start and end time of the task, the number of images downloaded, and any encountered errors. This facilitates tracking and analysis of the image download process. -
Command-Line Interface: The solution can be executed through a command-line interface by utilizing the provided Rake task
images:download_batch
. This allows users to invoke the image download functionality easily and efficiently. -
Testing: The implementation includes RSpec tests to verify the behavior of the
Images::Downloader
andImages::Validator
. The tests cover different scenarios such as file validation, URL validation, error handling, and successful image downloads. -
Docker: Docker provides an isolated development environment that ensures reproducibility and simplifies dependency management.
By following this implementation approach, the code provides a structured, maintainable, and extensible solution for downloading images from a plain text file.
- Docker version 24.0.2
- Docker Compose version v2.18.1
- Clone repo
- Fill out the .env file based on the .env.sample provided
- Run
sudo docker compose build
docker compose run web rake images:download_batch\["file/path"\]
sudo docker compose run web rspec spec
- Follow the steps in Installation
- Create a new branch
- Create a new PR