Created
July 10, 2023 10:19
-
-
Save Diego-Thomaz/d9ec06f1da86152bd9e8aa73426058cf to your computer and use it in GitHub Desktop.
Rainforest Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'uri' | |
| require 'net/http' | |
| require 'json' | |
| class RainforestTest | |
| URL = 'https://www.letsrevolutionizetesting.com/challenge' | |
| def call | |
| execute | |
| end | |
| private | |
| def execute(uri = URL) | |
| uri = URI(uri) | |
| request = Net::HTTP::Get.new(uri) | |
| request['Accept'] = 'application/json' | |
| response = JSON.parse(make_request(uri, request)) | |
| # uncomment this line to check the outputs, if needed | |
| # p response | |
| execute(response['follow']) unless is_the_end?(response) | |
| end | |
| def make_request(uri, request) | |
| Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }.body | |
| end | |
| def is_the_end?(response) | |
| response['message'] != 'This is not the end' | |
| end | |
| end | |
| RainforestTest.new.call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment