# ERDL: External Reports Downloader

[![Build Status](https://travis-ci.org/smoll/erdl.svg?branch=master)](https://travis-ci.org/smoll/erdl) [![Test Coverage](https://codeclimate.com/github/smoll/erdl/badges/coverage.svg)](https://codeclimate.com/github/smoll/erdl) [![Code Climate](https://codeclimate.com/github/smoll/erdl/badges/gpa.svg)](https://codeclimate.com/github/smoll/erdl)

Experimental project using watir-webdriver and a full browser (chromedriver or phantomjs) to retrieve files from 3rd party sites, e.g. YouTube CMS.

By leveraging the [PageObject pattern](https://github.com/cheezy/page-object/wiki/page-object), and the gem's [#wait_until](http://www.rubydoc.info/github/cheezy/page-object/PageObject:wait_until) [methods](https://github.com/cheezy/page-object/wiki/Ajax-Calls) for AJAX and asynchronous events, it should be :sparkles:**extremely**:sparkles: easy to fix the downloader even if YouTube, for example, drastically alters their site/frontend.

## Usage

0. Ensure ruby version is 2.5.3

0. Install dependencies:

	```
	bundle install
	```

0. Build the gem:

	```
	gem build erdl.gemspec
	```

0. Install the gem:

	```
	gem install erdl
	```

0. Run the executable, ensuring there is either a .env in the current working directory, or specify the path to it using the environment variable ERDL_DOTENV (relative OR absolute):

	```
	ERDL_DOTENV=/secrets/.env.erdl erdl ftp
	```

0. If you don't want to install the gem, you can also run the binary in the repo's bin/ dir:

	```
	$ bin/erdl -d ftp
	```

	(Still need to ensure that the .env exists or ALL the env vars listed in [.env.example](./.env.example) have been exported to shell, or the application will raise a RuntimeError at bootstrap!)

## Options

0. The CLI takes a number of options, including `--dry-run` (aliased as `-d`). For the latest options available view `--help`:

	```
	$ erdl --help
	```

0. To get help on specific subcommands, append `--help` to the end of the command:

	```
	$ erdl ftp --help
	```

## Debugging

- Use `byebug` to set breakpoints anywhere in the code.

- Run the executable with `--trace` to view full stacktraces.

- To build and install your working copy of the gem (while developing), do `rake install`. See all rake tasks with `rake -T`.

## Tests

- Run unit tests locally with `bundle exec rspec`

- Run acceptance tests locally with `bundle exec cucumber`

- Run the precommit hook (default rake task) with `bundle exec rake`

## TODO

1. Figure out how to better unit test the page classes -- [WatirSpec](https://github.com/watir/watirspec) perhaps? [This](./spec/pages/youtube/login_page_spec.rb) may not be the right approach. Also refer to how [watir-webdriver tests itself](https://github.com/watir/watir-webdriver#specs).
