File Coverage

blib/lib/WWW/PayPal/API/Products.pm
Criterion Covered Total %
statement 13 34 38.2
branch 0 14 0.0
condition n/a
subroutine 5 9 55.5
pod 3 3 100.0
total 21 60 35.0


line stmt bran cond sub pod time code
1             package WWW::PayPal::API::Products;
2              
3             # ABSTRACT: PayPal Catalogs Products API (v1)
4              
5 2     2   15 use Moo;
  2         4  
  2         13  
6 2     2   919 use Carp qw(croak);
  2         4  
  2         176  
7 2     2   1155 use WWW::PayPal::Product;
  2         10  
  2         85  
8 2     2   14 use namespace::clean;
  2         5  
  2         12  
9              
10             our $VERSION = '0.002';
11              
12              
13             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     1   26 'catalogs.products.create' => { method => 'POST', path => '/v1/catalogs/products' },
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             );
30              
31             with 'WWW::PayPal::Role::OpenAPI';
32              
33             sub _wrap {
34 0     0     my ($self, $data) = @_;
35 0           return WWW::PayPal::Product->new(client => $self->client, data => $data);
36             }
37              
38             sub create {
39 0     0 1   my ($self, %args) = @_;
40 0 0         croak 'name required' unless $args{name};
41 0 0         croak 'type required' unless $args{type};
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 0         $body{$k} = $args{$k} if defined $args{$k};
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     0 1   my ($self, $id) = @_;
57 0 0         croak 'product id required' unless $id;
58 0           return $self->_wrap($self->call_operation('catalogs.products.get', path => { id => $id }));
59             }
60              
61              
62             sub list {
63 0     0 1   my ($self, %args) = @_;
64 0           my %query;
65 0           for my $k (qw(page_size page total_required)) {
66 0 0         $query{$k} = $args{$k} if defined $args{$k};
67             }
68 0 0         my $data = $self->call_operation('catalogs.products.list',
69             (%query ? (query => \%query) : ()));
70 0 0         return [ map { $self->_wrap($_) } @{ $data->{products} || [] } ];
  0            
  0            
71             }
72              
73              
74             1;
75              
76             __END__