Skip to content

Instantly share code, notes, and snippets.

@Diego-Thomaz
Created July 10, 2023 10:19
Show Gist options
  • Select an option

  • Save Diego-Thomaz/d9ec06f1da86152bd9e8aa73426058cf to your computer and use it in GitHub Desktop.

Select an option

Save Diego-Thomaz/d9ec06f1da86152bd9e8aa73426058cf to your computer and use it in GitHub Desktop.
Rainforest Test
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