Created
April 29, 2014 16:25
-
-
Save mcmillhj/11405268 to your computer and use it in GitHub Desktop.
Rainforest QA challenge
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
#!/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