Pacific-Design.com

    
Home Index

1. Perl5

2. LWP Simple

Perl5 / LWP Simple /

Test JSON with LWP::Simple

#!/usr/bin/perl 
#-------------------------------------------------------------------------------------------------------------#
use strict;
use warnings;
use Data::Dumper;
use JSON;
use LWP::Simple;
require LWP::UserAgent;
$| = 1;
#-------------------------------------------------------------------------------------------------------------#
while (<DATA>) {
    test_resale_listing($_);
}

#-------------------------------------------------------------------------------------------------------------#
sub test_resale_listing {

    my $evenid = shift;

    my $url = 'http://pacific-design.com/json?cmd=get_listings&evenid=' . $evenid;
    my $ua  = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    $ua->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14');
    $ua->cookie_jar( { file => "$ENV{HOME}/.cookies.txt" } );

    my $response = $ua->get($url);
    $response    = $ua->get($url); # The same request must be called second time because of cookies                                                                                                               

    my $json_hash = decode_json( $response->{_content} );
    my $saleid = $json_hash->{listings}->[0]->{saleid};

    print $saleid;

    $url      = "http://pacific-design.com/order?v=$saleid";
    $response = $ua->get($url);

    print $response->{'_content'};

}

#-------------------------------------------------------------------------------------------------------------#
__DATA__
FF064A48F949952A
AF064A4869492528