| 1 | package Shipment::Sendle::API; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Mouse; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | with 'Web::API'; | |||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '0.1'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | has 'mode' => ( | |||||||||
| 10 | is => 'ro', | ||||||||||
| 11 | default => 'sandbox', | ||||||||||
| 12 | ); | ||||||||||
| 13 | |||||||||||
| 14 | has 'idempotency_key' => ( | ||||||||||
| 15 | is => 'rw', | ||||||||||
| 16 | lazy => 1, | ||||||||||
| 17 | 0 | ▶ | default => sub { return time }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 18 | 0 | ▶ | trigger => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | 0 | my ($self, $new_value) = @_; | |||||||||
| 20 | 0 | $self->header({'Idempotency-Key' => $new_value}); | |||||||||
| 21 | }, | ||||||||||
| 22 | 1 | ); | |||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub new_request { | ||||||||
|
Subroutine
new_request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 25 | 0 | my $self = shift; | |||||||||
| 26 | 0 | $self->idempotency_key(time); | |||||||||
| 27 | 0 | return; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | has 'commands' => ( | ||||||||||
| 31 | is => 'rw', | ||||||||||
| 32 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 33 | 0 | { ping => {method => 'GET'}, | |||||||||
| 34 | quote => { | ||||||||||
| 35 | method => 'GET', | ||||||||||
| 36 | default_attributes => { | ||||||||||
| 37 | pickup_country => 'US', | ||||||||||
| 38 | delivery_country => 'US', | ||||||||||
| 39 | weight_units => 'lb', | ||||||||||
| 40 | }, | ||||||||||
| 41 | mandatory => [ | ||||||||||
| 42 | 'pickup_postcode', 'pickup_suburb', | ||||||||||
| 43 | 'delivery_postcode', 'delivery_suburb', | ||||||||||
| 44 | 'weight_value', | ||||||||||
| 45 | ], | ||||||||||
| 46 | }, | ||||||||||
| 47 | create_order => { | ||||||||||
| 48 | method => 'POST', | ||||||||||
| 49 | path => 'orders', | ||||||||||
| 50 | default_attributes => { | ||||||||||
| 51 | first_mile_option => 'drop off', | ||||||||||
| 52 | 'sender.address.country' => 'United States', | ||||||||||
| 53 | 'receiver.address.country' => 'United States', | ||||||||||
| 54 | }, | ||||||||||
| 55 | mandatory => [ | ||||||||||
| 56 | 'description', | ||||||||||
| 57 | 'weight.value', | ||||||||||
| 58 | 'weight.units', | ||||||||||
| 59 | 'sender.contact.name', | ||||||||||
| 60 | 'sender.address.address_line1', | ||||||||||
| 61 | 'sender.address.suburb', | ||||||||||
| 62 | 'sender.address.postcode', | ||||||||||
| 63 | 'sender.address.state_name', | ||||||||||
| 64 | 'receiver.instructions', | ||||||||||
| 65 | 'receiver.contact.name', | ||||||||||
| 66 | 'receiver.address.address_line1', | ||||||||||
| 67 | 'receiver.address.suburb', | ||||||||||
| 68 | 'receiver.address.postcode', | ||||||||||
| 69 | 'receiver.address.state_name', | ||||||||||
| 70 | ], | ||||||||||
| 71 | }, | ||||||||||
| 72 | view_order => { | ||||||||||
| 73 | method => 'GET', | ||||||||||
| 74 | path => 'orders/:id', | ||||||||||
| 75 | }, | ||||||||||
| 76 | _label => { | ||||||||||
| 77 | method => 'GET', | ||||||||||
| 78 | path => 'orders/:id/labels/:type', | ||||||||||
| 79 | }, | ||||||||||
| 80 | track_order => { | ||||||||||
| 81 | method => 'GET', | ||||||||||
| 82 | path => 'tracking/:ref', | ||||||||||
| 83 | }, | ||||||||||
| 84 | cancel_order => { | ||||||||||
| 85 | method => 'DELETE', | ||||||||||
| 86 | path => 'orders/:id', | ||||||||||
| 87 | }, | ||||||||||
| 88 | |||||||||||
| 89 | }; | ||||||||||
| 90 | }, | ||||||||||
| 91 | 1 | ); | |||||||||
| 92 | |||||||||||
| 93 | 0 | ▶ | sub label { | ||||||||
|
Subroutine
label: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 94 | 0 | my ($self, %args) = @_; | |||||||||
| 95 | Shipment::Sendle::API->new( | ||||||||||
| 96 | user => $self->user, | ||||||||||
| 97 | api_key => $self->api_key, | ||||||||||
| 98 | mode => $self->mode, | ||||||||||
| 99 | debug => $self->debug, | ||||||||||
| 100 | 0 | ▶ | decoder => sub { {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 101 | 0 | )->_label(id => $args{id}, type => $args{type}); | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | sub commands { | ||||||||||
| 105 | my ($self) = @_; | ||||||||||
| 106 | return $self->commands; | ||||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | 0 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 110 | 0 | my ($self) = @_; | |||||||||
| 111 | |||||||||||
| 112 | 0 | $self->user_agent(__PACKAGE__ . ' ' . $VERSION); | |||||||||
| 113 | 0 | ▶ | if ($self->mode eq 'live') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | 0 | $self->base_url('https://api.sendle.com/api'); | |||||||||
| 115 | } | ||||||||||
| 116 | else { | ||||||||||
| 117 | 0 | $self->base_url('https://sandbox.sendle.com/api'); | |||||||||
| 118 | } | ||||||||||
| 119 | 0 | $self->content_type('application/json'); | |||||||||
| 120 | 0 | $self->auth_type('basic'); | |||||||||
| 121 | 0 | $self->header({'Idempotency-Key' => $self->idempotency_key}); | |||||||||
| 122 | |||||||||||
| 123 | 0 | return $self; | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | 1 | 1; | |||||||||
| 128 | |||||||||||
| 129 | __END__ | ||||||||||