| 1 | =head1 NAME | ||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||
| 3 | Net::MBE - Perl library to access Mailboxes Etc (MBE) online webservices. | ||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||
| 7 | use Net::MBE; | ||||||||||||||||||||||||||
| 8 | use Net::MBE::DestinationInfo; | ||||||||||||||||||||||||||
| 9 | use Net::MBE::ShippingParameters; | ||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||
| 11 | my $mbe = Net::MBE->new({ | ||||||||||||||||||||||||||
| 12 | system => 'IT', | ||||||||||||||||||||||||||
| 13 | Username => 'XXXXX', | ||||||||||||||||||||||||||
| 14 | Passphrase => 'YYYYYYYY', | ||||||||||||||||||||||||||
| 15 | }); | ||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||
| 17 | my $dest = Net::MBE::DestinationInfo->new({ | ||||||||||||||||||||||||||
| 18 | zipCode => '33085', | ||||||||||||||||||||||||||
| 19 | country => 'IT', | ||||||||||||||||||||||||||
| 20 | state => 'PN' | ||||||||||||||||||||||||||
| 21 | }); | ||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||
| 23 | my $shipparams = Net::MBE::ShippingParameters->new({ | ||||||||||||||||||||||||||
| 24 | destinationInfo => $dest, | ||||||||||||||||||||||||||
| 25 | shipType => 'EXPORT', | ||||||||||||||||||||||||||
| 26 | packageType => 'GENERIC', | ||||||||||||||||||||||||||
| 27 | }); | ||||||||||||||||||||||||||
| 28 | $shipparams->addItem({ | ||||||||||||||||||||||||||
| 29 | weight => 1, | ||||||||||||||||||||||||||
| 30 | length => 10, | ||||||||||||||||||||||||||
| 31 | width => 10, | ||||||||||||||||||||||||||
| 32 | height => 10, | ||||||||||||||||||||||||||
| 33 | }); | ||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||
| 35 | my $response = $mbe->ShippingOptions({ | ||||||||||||||||||||||||||
| 36 | internalReferenceID => '48147184XTST', | ||||||||||||||||||||||||||
| 37 | shippingParameters => $shipparams, | ||||||||||||||||||||||||||
| 38 | }); | ||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||
| 40 | use Data::Dump qw/dump/; die dump($response); | ||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||
| 44 | Mailboxes Etc (MBE), formerly a UPS-owned chain of shipping service outlets, is now an Italian | ||||||||||||||||||||||||||
| 45 | independent company which operated in several european countries. | ||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||
| 47 | This library is for accessing their various web services for getting rates, etc. | ||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||
| 49 | Currently, ONLY getting shipping rates is implemented. | ||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||
| 51 | =head1 AUTHOR | ||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||
| 53 | Michele Beltrame, C<arthas@cpan.org> | ||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||
| 55 | =head1 LICENSE | ||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||
| 57 | This library is free software under the Mozilla Public License 2.0. | ||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||
| 61 | 1 | package Net::MBE { | |||||||||||||||||||||||||
| 62 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 63 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 64 | 1 | ▶ | use SOAP::Lite; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 65 | #use SOAP::Lite +trace => [ qw/all -objects/ ]; | ||||||||||||||||||||||||||
| 66 | 1 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 67 | 1 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 68 | 1 | ▶ | use Arthas::Defaults::536; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 69 | 1 | ▶ | use version; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||
| 71 | 1 | our $VERSION = qv("v0.2.0"); | |||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||
| 73 | #$SOAP::Constants::DEFAULT_HTTP_CONTENT_TYPE = 'text/xml'; | ||||||||||||||||||||||||||
| 74 | #$SOAP::Constants::DO_NOT_USE_CHARSET = 1; | ||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||
| 76 | 1 | has system => ( is => 'rw' ); | |||||||||||||||||||||||||
| 77 | 1 | has endpoint => ( is => 'rw' ); | |||||||||||||||||||||||||
| 78 | 1 | has credentials => ( is => 'rw' ); | |||||||||||||||||||||||||
| 79 | 1 | has soapClient => ( is => 'rw' ); | |||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||
| 81 | # Creates a new instance of WSMBEOnline to access OnlineMBE web services. | ||||||||||||||||||||||||||
| 82 | # ---------------------------------------------------------------------- | ||||||||||||||||||||||||||
| 83 | # Parameters: | ||||||||||||||||||||||||||
| 84 | # $system -> one of 'IT', 'ES', 'DE', 'FR', AT'. Allows correct | ||||||||||||||||||||||||||
| 85 | # selection of OnlineMBE instance and endpoint. | ||||||||||||||||||||||||||
| 86 | # $username -> as supplied by MBE franchise. | ||||||||||||||||||||||||||
| 87 | # $passphrase -> as supplied by MBE franchise. | ||||||||||||||||||||||||||
| 88 | ▶ | sub BUILD($class, $args) { | |||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($args->{system} eq 'IT') { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 90 | 0 | $class->endpoint( 'https://api.mbeonline.it/ws/e-link.wsdl' ); | |||||||||||||||||||||||||
| 91 | } elsif ($args->{system} eq 'ES') { | ||||||||||||||||||||||||||
| 92 | 0 | $class->endpoint( 'https://api.mbeonline.es/ws/e-link.wsdl' ); | |||||||||||||||||||||||||
| 93 | } elsif ($args->{system} eq 'DE') { | ||||||||||||||||||||||||||
| 94 | 0 | $class->endpoint( 'https://api.mbeonline.de/ws/e-link.wsdl' ); | |||||||||||||||||||||||||
| 95 | } elsif ($args->{system} eq 'FR') { | ||||||||||||||||||||||||||
| 96 | 0 | $class->endpoint( 'https://api.mbeonline.fr/ws/e-link.wsdl' ); | |||||||||||||||||||||||||
| 97 | } elsif ($args->{system} eq 'PL') { | ||||||||||||||||||||||||||
| 98 | 0 | $class->endpoint( 'https://api.mbeonline.pl/ws/e-link.wsdl' ); | |||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||
| 101 | #use Data::Dump qw/dump/; die dump($args->{Username}, $args->{Passphrase}); | ||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||
| 103 | 0 | my $proxy = $class->{endpoint} =~ s/(\/e-link\.wsdl)$//xsr; | |||||||||||||||||||||||||
| 104 | my $soapClient = SOAP::Lite->new( | ||||||||||||||||||||||||||
| 105 | readable => 0, | ||||||||||||||||||||||||||
| 106 | proxy => [ | ||||||||||||||||||||||||||
| 107 | $proxy, | ||||||||||||||||||||||||||
| 108 | # credentials => [ | ||||||||||||||||||||||||||
| 109 | # 'api.mbeonline.it:443', | ||||||||||||||||||||||||||
| 110 | # undef, | ||||||||||||||||||||||||||
| 111 | # $args->{Username}, | ||||||||||||||||||||||||||
| 112 | # $args->{Passphrase}, | ||||||||||||||||||||||||||
| 113 | # ], | ||||||||||||||||||||||||||
| 114 | default_headers => HTTP::Headers->new( | ||||||||||||||||||||||||||
| 115 | 'Content-type', 'text/xml; charset=utf-8', # MBE won't accept application/soap | ||||||||||||||||||||||||||
| 116 | 'Authorization', 'Basic '.encode_base64($args->{Username} . ':' . $args->{Passphrase}) | ||||||||||||||||||||||||||
| 117 | 0 | ), | |||||||||||||||||||||||||
| 118 | ], | ||||||||||||||||||||||||||
| 119 | #wsdl => $args->{endpoint}, | ||||||||||||||||||||||||||
| 120 | ); | ||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||
| 122 | # Server seems to only support 1.1, or at least only text/xml as content type | ||||||||||||||||||||||||||
| 123 | 0 | $soapClient->soapversion('1.1'); | |||||||||||||||||||||||||
| 124 | 0 | $soapClient->serializer->soapversion('1.1'); | |||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||
| 126 | 0 | $soapClient->ns('http://schemas.xmlsoap.org/soap/envelope/', 'SOAP-ENV'); | |||||||||||||||||||||||||
| 127 | 0 | $soapClient->ns('http://www.onlinembe.eu/ws/','ns1'); | |||||||||||||||||||||||||
| 128 | 0 | $soapClient->envprefix('SOAP-ENV'); | |||||||||||||||||||||||||
| 129 | 0 | $soapClient->autotype(0); | |||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||
| 131 | 0 | $class->soapClient($soapClient); | |||||||||||||||||||||||||
| 132 | 0 | $class->credentials({'Username' => '', Passphrase => ''}); | |||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||
| 136 | # ShippingOptionsRequest | ||||||||||||||||||||||||||
| 137 | # ---------------------- | ||||||||||||||||||||||||||
| 138 | # Gets shipping options for an indicated shipment parameters. | ||||||||||||||||||||||||||
| 139 | # $internalReferenceID -> string that is returned as is by the server. | ||||||||||||||||||||||||||
| 140 | # $shippingParameters -> object of type ShippingParameters with all | ||||||||||||||||||||||||||
| 141 | # the required info. | ||||||||||||||||||||||||||
| 142 | ▶ | sub ShippingOptions($self, $args) { | |||||||||||||||||||||||||
|
Subroutine
ShippingOptions: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||
| 143 | 0 | ▶ | croak 'Invalid-internalReferenceID' if !$args->{internalReferenceID}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||
| 145 | my $params = SOAP::Data->name('RequestContainer' => \SOAP::Data->value( | ||||||||||||||||||||||||||
| 146 | SOAP::Data->name('System' => $self->system), | ||||||||||||||||||||||||||
| 147 | SOAP::Data->name('Credentials' => \SOAP::Data->value( | ||||||||||||||||||||||||||
| 148 | SOAP::Data->name('Username' => ''), | ||||||||||||||||||||||||||
| 149 | SOAP::Data->name('Passphrase' => ''), | ||||||||||||||||||||||||||
| 150 | )), | ||||||||||||||||||||||||||
| 151 | SOAP::Data->name('InternalReferenceID', $args->{internalReferenceID}), | ||||||||||||||||||||||||||
| 152 | 0 | SOAP::Data->name('ShippingParameters' => $args->{shippingParameters}->getSoapParams()), | |||||||||||||||||||||||||
| 153 | )); | ||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||
| 155 | 0 | my $som = $self->soapClient->call("ShippingOptionsRequest", $params); | |||||||||||||||||||||||||
| 156 | 0 | ▶ | croak 'Invalid-request' if !$som; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 157 | 0 | ▶ | croak 'Request error: '.$som->fault->{ faultstring } if $som->fault; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 158 | 0 | return $som->body->{ShippingOptionsRequestResponse}->{RequestContainer}; | |||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||
| 162 | 1 | 1; | |||||||||||||||||||||||||