line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::PostalMethods; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1167
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
50
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
569
|
use SOAP::Lite; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use MIME::Base64; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.01; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
WWW::PostalMethods - Interface to the PostalMethods API |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $pm = WWW::PostalMethods->new( |
18
|
|
|
|
|
|
|
username => 'emperorzurg', |
19
|
|
|
|
|
|
|
password => 'buzzmustdie', |
20
|
|
|
|
|
|
|
work_mode => 'Development', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$pm->send_letter( |
24
|
|
|
|
|
|
|
description => 'Reminder to buy beer', |
25
|
|
|
|
|
|
|
extension => 'html', |
26
|
|
|
|
|
|
|
data => qq| |
27
|
|
|
|
|
|
|
Hello! |
28
|
|
|
|
|
|
|
This is an automated notification that you should buy beer. |
29
|
|
|
|
|
|
|
|, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 new |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Returns a new WWW::PostalMethods object. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Takes the following required parameters: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
username - Your PostalMethods.com username |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
password - Your PostalMethods.com password |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
and the following optional parameters: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
work_mode - The work mode to use (Development or Production) - defaults to Development |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
|
|
|
|
|
|
my ($class, %params) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $self = \%params; |
54
|
|
|
|
|
|
|
bless $self, $class; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 send_letter |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Sends a new letter via PostalMethods. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Takes the following required parameters: |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
description - Describes the letter |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
extension - File extension |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
And one of the following parameters: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
data - The data to be passed |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
base64_data - The data to be passed, base64-encoded |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub send_letter |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
my ($self, %params) = @_; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $res = $self->api_call('SendLetter', { |
82
|
|
|
|
|
|
|
MyDescription => $params{description}, |
83
|
|
|
|
|
|
|
FileExtension => $params{extension}, |
84
|
|
|
|
|
|
|
FileBinaryData => $params{base64_data} || encode_base64($params{data}), |
85
|
|
|
|
|
|
|
WorkMode => $self->{work_mode}, |
86
|
|
|
|
|
|
|
}); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return $res; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 api_call |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Direct all to make a PostalPathods API call. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Takes the call and a hash reference of parameters as an API call. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
The username and password will be auto-filled, the rest is up to you. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub api_call |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
my ($self, $call, $params) = @_; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$params->{Username} = $self->{username}; |
106
|
|
|
|
|
|
|
$params->{Password} = $self->{password}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my @params = map { SOAP::Data->new(name => $_, value => $params->{$_})->uri('PostalMethods') } |
109
|
|
|
|
|
|
|
keys %$params; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$self->_soap->$call(@params); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _soap |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
my $self = shift; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$self->{_soap} ||= SOAP::Lite |
119
|
|
|
|
|
|
|
->uri('PostalMethods') |
120
|
|
|
|
|
|
|
->on_action( sub { join '/', 'PostalMethods', $_[1] } ) |
121
|
|
|
|
|
|
|
->proxy('https://api.postalmethods.com/2009-02-26/PostalWS.asmx'); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
return $self->{_soap}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 TO DO |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This is a very simplistic implementation. Native support of more complex queries would be neat. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
More to come, patches also welcome. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
SOAP::Lite, MIME::Base64 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHORS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
OHPA Software (http://ohpasw.com) |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Copyright (C) 2013 OHPA Software. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|