File Coverage

blib/lib/PayProp/API/Public/Client/Request/Export/Tenants.pm
Criterion Covered Total %
statement 43 43 100.0
branch 3 4 75.0
condition 4 8 50.0
subroutine 11 11 100.0
pod 1 1 100.0
total 62 67 92.5


line stmt bran cond sub pod time code
1             package PayProp::API::Public::Client::Request::Export::Tenants;
2              
3 3     3   651605 use strict;
  3         8  
  3         123  
4 3     3   19 use warnings;
  3         8  
  3         181  
5              
6 3     3   19 use Mouse;
  3         6  
  3         60  
7             with qw/ PayProp::API::Public::Client::Role::APIRequest /;
8              
9 3     3   3468 use PayProp::API::Public::Client::Response::Export::Tenant;
  3         318  
  3         176  
10 3     3   1505 use PayProp::API::Public::Client::Response::Export::Tenant::Address;
  3         198  
  3         110  
11 3     3   1250 use PayProp::API::Public::Client::Response::Export::Tenant::Property;
  3         194  
  3         2155  
12              
13              
14             has '+url' => (
15             default => sub {
16             my ( $self ) = @_;
17             return $self->abs_domain . '/api/agency/' . $self->api_version . '/export/tenants';
18             },
19             );
20              
21              
22             sub list_p {
23 1     1 1 26 my ( $self, $args ) = @_;
24              
25 1   50     16 $args //= {};
26 1         2 my $params = $args->{params};
27              
28             return $self
29             ->api_request_p({
30             params => $params,
31 1     1   13 handle_response_cb => sub { $self->_get_tenants( @_ ) },
32             })
33 1         44 ;
34             }
35              
36             sub _get_tenants {
37 1     1   3 my ( $self, $response_json ) = @_;
38              
39 1         6 my @tenants;
40 1   50     3 for my $tenant ( @{ $response_json->{items} // [] } ) {
  1         8  
41             my $Tenant = PayProp::API::Public::Client::Response::Export::Tenant->new(
42             id => $tenant->{id},
43             status => $tenant->{status},
44             comment => $tenant->{comment},
45             reference => $tenant->{reference},
46             last_name => $tenant->{last_name},
47             first_name => $tenant->{first_name},
48             notify_sms => $tenant->{notify_sms},
49             id_reg_no => $tenant->{id_reg_no},
50             id_type_id => $tenant->{id_type_id},
51             vat_number => $tenant->{vat_number},
52             customer_id => $tenant->{customer_id},
53             notify_email => $tenant->{notify_email},
54             email_address => $tenant->{email_address},
55             display_name => $tenant->{display_name},
56             mobile_number => $tenant->{mobile_number},
57             id_reg_number => $tenant->{id_reg_number},
58             business_name => $tenant->{business_name},
59             date_of_birth => $tenant->{date_of_birth},
60             email_cc_address => $tenant->{email_cc_address},
61             invoice_lead_days => $tenant->{invoice_lead_days},
62              
63             address => $self->_build_address( $tenant->{address} ),
64 25         101 properties => $self->_build_properties( $tenant->{properties} ),
65             );
66              
67 25         890 push( @tenants, $Tenant );
68             }
69              
70 1         12 return \@tenants;
71             }
72              
73             sub _build_properties {
74 25     25   39 my ( $self, $properties_ref ) = @_;
75              
76 25 100 50     29 return [] unless @{ $properties_ref // [] };
  25         218  
77              
78 6         11 my @properties;
79              
80 6         16 foreach my $property ( $properties_ref->@* ) {
81              
82             my $Property = PayProp::API::Public::Client::Response::Export::Tenant::Property->new(
83             id => $property->{id},
84             balance => $property->{balance},
85             comment => $property->{comment},
86             listed_from => $property->{listed_from},
87             listed_until => $property->{listed_until},
88             property_name => $property->{property_name},
89             allow_payments => $property->{allow_payments},
90             account_balance => $property->{account_balance},
91             approval_required => $property->{approval_required},
92             responsible_agent => $property->{responsible_agent},
93             customer_reference => $property->{customer_reference},
94             hold_all_owner_funds => $property->{hold_all_owner_funds},
95             last_processing_info => $property->{last_processing_info},
96             property_account_minimum_balance => $property->{property_account_minimum_balance},
97              
98 6         70 address => $self->_build_address( $property->{address} ),
99             );
100              
101 6         316 push( @properties, $Property );
102             }
103              
104 6         67 return \@properties;
105             }
106              
107             sub _build_address {
108 31     31   43 my ( $self, $addres_ref ) = @_;
109              
110 31 50 50     36 return undef unless %{ $addres_ref // {} };
  31         74  
111              
112             my $Address = PayProp::API::Public::Client::Response::Export::Tenant::Address->new(
113             id => $addres_ref->{id},
114             fax => $addres_ref->{fax},
115             city => $addres_ref->{city},
116             email => $addres_ref->{email},
117             phone => $addres_ref->{phone},
118             state => $addres_ref->{state},
119             created => $addres_ref->{created},
120             zip_code => $addres_ref->{zip_code},
121             modified => $addres_ref->{modified},
122             latitude => $addres_ref->{latitude},
123             longitude => $addres_ref->{longitude},
124             third_line => $addres_ref->{third_line},
125             first_line => $addres_ref->{first_line},
126             second_line => $addres_ref->{second_line},
127             country_code => $addres_ref->{country_code},
128 31         635 );
129              
130 31         419 return $Address;
131             }
132              
133             __PACKAGE__->meta->make_immutable;
134              
135             __END__