Skip to content

Instantly share code, notes, and snippets.

@mcmillhj
Created April 29, 2014 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcmillhj/11405268 to your computer and use it in GitHub Desktop.
Save mcmillhj/11405268 to your computer and use it in GitHub Desktop.
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