| 1 | package WWW::PayPal::API::Products; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: PayPal Catalogs Products API (v1) | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use WWW::PayPal::Product; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | our $VERSION = '0.002'; | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | 2 | has client => ( | |||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | required => 1, | ||||||||||
| 16 | weak_ref => 1, | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | has openapi_operations => ( | ||||||||||
| 20 | is => 'lazy', | ||||||||||
| 21 | builder => sub { | ||||||||||
| 22 | return { | ||||||||||
| 23 | 1 | ▶ | 'catalogs.products.create' => { method => 'POST', path => '/v1/catalogs/products' }, | ||||||||
|
Subroutine
_build_openapi_operations: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 'catalogs.products.list' => { method => 'GET', path => '/v1/catalogs/products' }, | ||||||||||
| 25 | 'catalogs.products.get' => { method => 'GET', path => '/v1/catalogs/products/{id}' }, | ||||||||||
| 26 | 'catalogs.products.patch' => { method => 'PATCH', path => '/v1/catalogs/products/{id}' }, | ||||||||||
| 27 | }; | ||||||||||
| 28 | }, | ||||||||||
| 29 | 2 | ); | |||||||||
| 30 | |||||||||||
| 31 | 2 | with 'WWW::PayPal::Role::OpenAPI'; | |||||||||
| 32 | |||||||||||
| 33 | sub _wrap { | ||||||||||
| 34 | 0 | ▶ | my ($self, $data) = @_; | ||||||||
|
Subroutine
_wrap: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 0 | return WWW::PayPal::Product->new(client => $self->client, data => $data); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | sub create { | ||||||||||
| 39 | 0 | ▶ | my ($self, %args) = @_; | ||||||||
|
Subroutine
create: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 40 | 0 | ▶ | croak 'name required' unless $args{name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | ▶ | croak 'type required' unless $args{type}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | |||||||||||
| 43 | my %body = ( | ||||||||||
| 44 | name => $args{name}, | ||||||||||
| 45 | type => $args{type}, | ||||||||||
| 46 | 0 | ); | |||||||||
| 47 | 0 | for my $k (qw(description category image_url home_url id)) { | |||||||||
| 48 | 0 | ▶ | $body{$k} = $args{$k} if defined $args{$k}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | } | ||||||||||
| 50 | 0 | my $data = $self->call_operation('catalogs.products.create', body => \%body); | |||||||||
| 51 | 0 | return $self->_wrap($data); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | |||||||||||
| 55 | sub get { | ||||||||||
| 56 | 0 | ▶ | my ($self, $id) = @_; | ||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 57 | 0 | ▶ | croak 'product id required' unless $id; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | return $self->_wrap($self->call_operation('catalogs.products.get', path => { id => $id })); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | sub list { | ||||||||||
| 63 | 0 | ▶ | my ($self, %args) = @_; | ||||||||
|
Subroutine
list: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 64 | 0 | my %query; | |||||||||
| 65 | 0 | for my $k (qw(page_size page total_required)) { | |||||||||
| 66 | 0 | ▶ | $query{$k} = $args{$k} if defined $args{$k}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | } | ||||||||||
| 68 | 0 | ▶ | my $data = $self->call_operation('catalogs.products.list', | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | (%query ? (query => \%query) : ())); | ||||||||||
| 70 | 0 | ▶ | return [ map { $self->_wrap($_) } @{ $data->{products} || [] } ]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | 2 | 1; | |||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||