File Coverage

blib/lib/WebService/UPS/TrackRequest.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             #===============================================================================
2             # FILE: WebService::UPS::TrackRequest.pm
3             # DESCRIPTION: OO Module to track UPS packages using the XML UPS API.
4             # AUTHOR: Kyle Brandt (mn), kyle@kbrandt.com , http://www.kbrandt.com
5             #===============================================================================
6              
7             our $VERSION = '0.1';
8             package WebService::UPS::TrackRequest;
9 1     1   23474 use Mouse;
  1         935323  
  1         8  
10 1     1   2008 use LWP::UserAgent;
  1         892788  
  1         41  
11 1     1   408395 use HTTP::Request::Common;
  1         2131  
  1         74  
12 1     1   407 use XML::Simple;
  0            
  0            
13             use Data::Dumper;
14             use WebService::UPS::TrackedPackage;
15              
16             has 'License' => ( is => 'rw' );
17             has 'Username' => ( is => 'rw' );
18             has 'Password' => ( is => 'rw' );
19             has 'TrackingNumber' => ( is => 'rw' );
20             has 'debug' => ( is => 'rw' );
21             has 'URL' => ( is => 'rw',
22             default => 'https://wwwcie.ups.com/ups.app/xml/Track');
23             has 'Description' => ( is => 'rw',
24             default => 'A Package');
25              
26              
27             sub requestTrack {
28             my $self = shift;
29             my $_ups_xml_req = "
30            
31            
32             ${\$self->License}
33             ${\$self->Username}
34             ${\$self->Password}
35            
36            
37            
38            
39            
40             ${\$self->Description}
41            
42             Track
43             activity
44            
45             ${\$self->TrackingNumber}
46            
47             ";
48             #print $self->PackageName;
49             if (defined( $self->debug) ) { print $_ups_xml_req, "\n"; }
50             my $userAgent = LWP::UserAgent->new(agent => 'perl post');
51             my $response = $userAgent->request(POST $self->URL, Content_Type => 'text/xml',
52             Content => $_ups_xml_req);
53             if (defined( $self->debug) ) { print $response->decoded_content, "\n"; }
54             print $response->error_as_HTML unless $response->is_success;
55             my $xml = new XML::Simple;
56             my $processedXML = $xml->XMLin( $response->decoded_content);
57             #print Dumper($processedXML);
58             my $object = WebService::UPS::TrackedPackage->new();
59             $object->_returned_xml($processedXML);
60             return $object;
61             }
62              
63             1;
64              
65              
66             =head1 NAME
67              
68             WebService::UPS::TrackRequest - Generate a Request for Tracking Information
69              
70             =head1 SYNOPSIS
71              
72             my $Package = WebService::UPS::TrackRequest->new;
73             $Package->Username('kbrandt');
74             $Package->Password('topsecrent');
75             $Package->License('8C3D7EE8FZZZZZ4');
76             $Package->TrackingNumber('1ZA45Y5111111111');
77             print $Package->Username();
78             my $trackedpackage = $Package->requestTrack();
79              
80             =head1 License
81              
82             You will need to get a UPS Online Tools License and Account to use this module: http://www.ups.com/e_comm_access/gettools_index?loc=en_US
83              
84             =head1 Methods
85              
86             =head2 new()
87              
88             $package = WebService::UPS::TrackRequest->new( Username => 'kbrandt');
89              
90             The constructor method that creates a new Request Object.
91              
92             =over 1
93              
94             =item License
95            
96             You will need to register with UPS to get a developer key and then a License to access the XML Service
97              
98             =item Username
99              
100             Username for your UPS account
101              
102             =item Password
103              
104             Password for your UPS account
105              
106             =item TrackingNumber
107              
108             The Tracking number of your package
109              
110             =item debug
111            
112             Set this to something to make a lot of stuff appear
113              
114             =item URL
115            
116             The URL the request is set to, you shouldn't have to Touch this
117              
118             =item Description
119              
120             Optional, a human readable name for your package. Defaults to 'A Package'
121              
122             =back
123              
124              
125             =head2 requestTrack()
126              
127             my $trackedPackage = $package->requestTrack();
128              
129             Sumbits the request to UPS and returns a TrackedPackage Object
130              
131             =head1 AUTHOR
132              
133             Kyle Brandt, kyle@kbrandt.com
134             http://www.kbrandt.com
135              
136             =cut
137