Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rainforest QA challenge
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use English qw(-no_match_vars);
use JSON qw(decode_json);
use LWP::UserAgent;
# basically follow the url chain until you reach the end
# start url: http://letsrevolutionizetesting.com/challenge.json
my $base_url = "http://www.letsrevolutionizetesting.com/challenge.json?id=";
my $current_url = "http://www.letsrevolutionizetesting.com/challenge.json";
my $ua = LWP::UserAgent->new( agent => 'RainforestQAChallenge/Perl libperl');
while ( 1 ) {
my $json_response;
eval {
my $response = $ua->get($current_url);
$json_response = decode_json($response->decoded_content || '');
};
die $EVAL_ERROR
if $EVAL_ERROR;
my $id;
if ($json_response->{follow}) {
($id) = $json_response->{follow} =~ /id=(\d+)$/;
}
else { # at the end
print Dumper $json_response->{message};
last;
}
$current_url = "$base_url$id";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.