Go to https://letsrevolutionizetesting.com/challenge (this page is not broken!) and follow the instructions. Put the program you used to solve the challenge below. If you do not solve it your application will be rejected
Last active
September 7, 2023 09:11
-
-
Save rodrigovirgilio/4ec2140b78b6bfde844bc3ae5f5872d2 to your computer and use it in GitHub Desktop.
Challenge Rainforest
This file contains 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
class Challenge | |
require "json" | |
require "net/http" | |
URL = "https://www.letsrevolutionizetesting.com/challenge.json".freeze | |
MAX_ITERATIONS = 100 | |
def self.call | |
# Initialize id_value with nil to start the loop | |
id_value = nil | |
MAX_ITERATIONS.times do | |
begin | |
response = extract_parameter(id_value) | |
body = JSON.parse(response.body) | |
puts body | |
follow_body = body["follow"] | |
if follow_body.nil? | |
puts body["message"] || "not found" | |
break | |
end | |
id_value = extract_id(follow_body) | |
puts URI("#{URL}?id=#{id_value}") | |
rescue StandardError => e | |
puts "An error occurred: #{e.message}" | |
break | |
end | |
end | |
end | |
private | |
# Define a method to extract the id from the follow_body | |
def self.extract_id(follow_body) | |
follow_body.match(/id=(\d+)/)[1] if follow_body | |
end | |
# Define a method to extract the parameter from the id_value | |
def self.extract_parameter(id_value) | |
id_value.nil? ? Net::HTTP.get_response(URI(URL)) : Net::HTTP.get_response(URI("#{URL}?id=#{id_value}")) | |
end | |
end | |
Challenge.call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Log in local environment