| 1 | package WWW::ShipStation; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.008_005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use URI::Escape qw/uri_escape/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | $args{user} or croak "user is required."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $args{pass} or croak "pass is required."; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | $args{ua} ||= LWP::UserAgent->new(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"ua"} ||= "LWP::UserAgent"->new
MC/DC0%0/2
$args{"ua"} ||= "LWP::UserAgent"->new
$args{"ua"}
"LWP::UserAgent"->new
Truth table0%0/3
A ||= B
A= $args{"ua"}B= "LWP::UserAgent"->new
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $args{json} ||= JSON->new->allow_nonref->utf8; | ||||||||||||||||||||||||||
|
Condition0%0/3
$args{"json"} ||= "JSON"->new->allow_nonref->utf8
MC/DC0%0/2
$args{"json"} ||= "JSON"->new->allow_nonref->utf8
$args{"json"}
"JSON"->new->allow_nonref->utf8
Truth table0%0/3
A ||= B
A= $args{"json"}B= "JSON"->new->allow_nonref->utf8
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $args{API_BASE} ||= 'https://ssapi.shipstation.com/'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"API_BASE"} ||= "https://ssapi.shipstation.com/"
MC/DC0%0/1
$args{"API_BASE"} ||= "https://ssapi.shipstation.com/"
$args{"API_BASE"}
Truth table0%0/2
A
A= $args{"API_BASE"}
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | bless \%args, $class; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub getCarriers { | ||||||||||||||||||||||||||
|
Subroutine
getCarriers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 0 | (shift)->request('carriers'); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub getCustomer { | ||||||||||||||||||||||||||
|
Subroutine
getCustomer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | my ($self, $customerId) = @_; | |||||||||||||||||||||||||||
| 34 | 0 | $self->request("customers/$customerId"); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub getCustomers { | ||||||||||||||||||||||||||
|
Subroutine
getCustomers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | $self->request('customers', %args); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub getOrder { | ||||||||||||||||||||||||||
|
Subroutine
getOrder: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 0 | my ($self, $orderId) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | $self->request("orders/$orderId"); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub getOrders { | ||||||||||||||||||||||||||
|
Subroutine
getOrders: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $self->request('orders', %args); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub getProduct { | ||||||||||||||||||||||||||
|
Subroutine
getProduct: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($self, $productId) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | $self->request("products/$productId"); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub getProducts { | ||||||||||||||||||||||||||
|
Subroutine
getProducts: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $self->request('products/', %args); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub getShipments { | ||||||||||||||||||||||||||
|
Subroutine
getShipments: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | $self->request('shipments', %args); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub getMarketplaces { | ||||||||||||||||||||||||||
|
Subroutine
getMarketplaces: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | $self->request('stores/marketplaces', %args); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub getStores { | ||||||||||||||||||||||||||
|
Subroutine
getStores: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | $self->request('stores', %args); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub getStore { | ||||||||||||||||||||||||||
|
Subroutine
getStore: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 0 | my ($self, $storeId) = @_; | |||||||||||||||||||||||||||
| 85 | 0 | $self->request("stores/$storeId"); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub getWarehouses { | ||||||||||||||||||||||||||
|
Subroutine
getWarehouses: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | $self->request('warehouses', %args); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub getWarehouse { | ||||||||||||||||||||||||||
|
Subroutine
getWarehouse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 0 | my ($self, $warehouseId) = @_; | |||||||||||||||||||||||||||
| 96 | 0 | $self->request("warehouses/$warehouseId"); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub request { | ||||||||||||||||||||||||||
|
Subroutine
request: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | my ($self, $url, %params) = @_; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (%params and keys %params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
%params and keys %params
MC/DC0%0/2
%params and keys %params
%params
keys %params
Truth table0%0/3
A and B
A= %paramsB= keys %params
| |||||||||||||||||||||||||||||
| 103 | 0 | $url .= '?' . join('&', map { join('=', $_, uri_escape($params{$_})) } keys %params); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my $req = HTTP::Request->new(GET => $self->{API_BASE} . $url); | |||||||||||||||||||||||||||
| 107 | 0 | $req->authorization_basic($self->{user}, $self->{pass}); | |||||||||||||||||||||||||||
| 108 | 0 | $req->header('Accept', 'application/json'); # JSON is better | |||||||||||||||||||||||||||
| 109 | 0 | my $res = $self->{ua}->request($req); | |||||||||||||||||||||||||||
| 110 | # use Data::Dumper; print STDERR Dumper(\$res); | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($res->header('Content-Type') =~ m{application/json}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | return $self->{json}->decode($res->decoded_content); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | unless ($res->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | return { | ||||||||||||||||||||||||||||
| 116 | 0 | 'error' => { | |||||||||||||||||||||||||||
| 117 | 'code' => '', | ||||||||||||||||||||||||||||
| 118 | 'message' => { | ||||||||||||||||||||||||||||
| 119 | 'lang' => 'en-US', | ||||||||||||||||||||||||||||
| 120 | 'value' => $res->status_line, | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | }; | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub createOrder { | ||||||||||||||||||||||||||
|
Subroutine
createOrder: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 128 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 129 | 0 | ▶ | my %args = @_ % 2 ? %{$_[0]} : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | $self->__request('POST', 'orders/createorder', $self->{json}->encode(\%args)); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub deleteOrder { | ||||||||||||||||||||||||||
|
Subroutine
deleteOrder: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 0 | my ($self, $orderID) = @_; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | $self->__request('DELETE', "orders/$orderID"); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub __request { | ||||||||||||||||||||||||||
|
Subroutine
__request: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 140 | 0 | my ($self, $method, $url, $content) = @_; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | my $req = HTTP::Request->new($method => $self->{API_BASE} . $url); | |||||||||||||||||||||||||||
| 143 | 0 | $req->authorization_basic($self->{user}, $self->{pass}); | |||||||||||||||||||||||||||
| 144 | 0 | $req->header('Accept', 'application/json'); # JSON is better | |||||||||||||||||||||||||||
| 145 | 0 | $req->header('Accept-Charset' => 'UTF-8'); | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ($method eq 'POST') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | $req->header('Content-Type' => 'application/json'); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | $req->content($content) if $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | my $res = $self->{ua}->request($req); | |||||||||||||||||||||||||||
| 152 | # use Data::Dumper; print STDERR Dumper(\$res); | ||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ($res->header('Content-Type') =~ m{application/json}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 0 | return $self->{json}->decode($res->decoded_content); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | unless ($res->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | return { | ||||||||||||||||||||||||||||
| 158 | 0 | 'error' => { | |||||||||||||||||||||||||||
| 159 | 'code' => '', | ||||||||||||||||||||||||||||
| 160 | 'message' => { | ||||||||||||||||||||||||||||
| 161 | 'lang' => 'en-US', | ||||||||||||||||||||||||||||
| 162 | 'value' => $res->status_line | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | }; | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 0 | return $res->decoded_content; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | 1; | |||||||||||||||||||||||||||
| 171 | __END__ | ||||||||||||||||||||||||||||