Create a local git repo and commit every exercise to this repo.
If necessary install ruby and then:
- Write a
Hello World!
example - Write the Hello World example using a class. Use a class method (instead of an instance method)
greeting
to outputHello, World!
:
[classname].greeting
-> "Hello, World!"
JSONPlaceholder - Fake online REST API for developers is a free online REST API that you can use whenever you need some fake data.
Write a Ruby class to download a single post from JSONPlaceholder. The usage of your class should look like this:
ruby_downloader = RubyDownloader.new
ruby_downloader.show_post(3)
The commands above should output the post to stdout in the following format:
<post-title>
<post-body>
Refactor your class so that it saves the downloaded post to a specific directory. It should be possible to use it like this:
ruby_downloader = RubyDownloader.new('/tmp')
ruby_downloader.download_post(3)
After the execution, there should be a post3.txt
file in the /tmp
directory.
Note: It doesn't have to output the post in stdout, instead it should write the same string into the file.
Refactor the script to be usable in bash. It should be possible to call it to show a post and to download a post.
$ ./ruby_downloader.rb show 3
<post-title>
<post-body>
$ ./ruby_downloader.rb download 3 "tmp"
$ Saved post to /tmp/post3.txt !
Write a bash script that uses your ruby script to download a range of posts to ./posts
.
./download.sh 1 100
Also generate with the bash script a index.csv
file, that contains the post ID, the post title, the post body and the full path to the file.
1;<post-title>;<post-body>;/Users/.../posts/post1.txt
...
100;<post-title>;<post-body>;/Users/.../posts/post100.txt
Think about your implementation.
Let's say you had more time and we were in a production environment ...
What would you improve or change ?