File Coverage

blib/lib/Net/Braintree/AddressGateway.pm
Criterion Covered Total %
statement 15 31 48.3
branch 0 6 0.0
condition 0 3 0.0
subroutine 5 10 50.0
pod 0 4 0.0
total 20 54 37.0


line stmt bran cond sub pod time code
1             package Net::Braintree::AddressGateway;
2 1     1   4 use Moose;
  1         2  
  1         5  
3 1     1   5840 use Carp qw(confess);
  1         2  
  1         58  
4 1     1   488 use Net::Braintree::Validations qw(verify_params address_signature);
  1         2  
  1         58  
5 1     1   5 use Net::Braintree::Util qw(validate_id);
  1         2  
  1         31  
6 1     1   466 use Net::Braintree::Result;
  1         3  
  1         435  
7              
8             has 'gateway' => (is => 'ro');
9              
10             sub create {
11 0     0 0   my($self, $params) = @_;
12 0           my $customer_id = delete($params->{'customer_id'});
13 0 0         confess "ArgumentError" unless verify_params($params, address_signature());
14 0           $self->_make_request("/customers/$customer_id/addresses", "post", {address => $params});
15             }
16              
17             sub find {
18 0     0 0   my ($self, $customer_id, $address_id) = @_;
19 0 0 0       confess "NotFoundError" unless (validate_id($address_id) && validate_id($customer_id));
20 0           $self->_make_request("/customers/$customer_id/addresses/$address_id", "get")->address;
21             }
22              
23             sub update {
24 0     0 0   my ($self, $customer_id, $address_id, $params) = @_;
25 0 0         confess "ArgumentError" unless verify_params($params, address_signature());
26 0           $self->_make_request("/customers/$customer_id/addresses/$address_id", "put", {address => $params});
27             }
28              
29             sub delete {
30 0     0 0   my ($self, $customer_id, $address_id) = @_;
31 0           $self->_make_request("/customers/$customer_id/addresses/$address_id", "delete");
32             }
33              
34             sub _make_request {
35 0     0     my($self, $path, $verb, $params) = @_;
36 0           my $response = $self->gateway->http->$verb($path, $params);
37 0           my $result = Net::Braintree::Result->new(response => $response);
38 0           return $result;
39             }
40              
41              
42             1;