File Coverage

lib/Business/Fixflo/Agency.pm
Criterion Covered Total %
statement 27 27 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 9 9 100.0
pod 3 3 100.0
total 45 45 100.0


line stmt bran cond sub pod time code
1             package Business::Fixflo::Agency;
2              
3             =head1 NAME
4              
5             Business::Fixflo::Agency
6              
7             =head1 DESCRIPTION
8              
9             A class for a fixflo agency, extends L
10              
11             =cut
12              
13 16     16   100 use strict;
  16         27  
  16         438  
14 16     16   68 use warnings;
  16         29  
  16         344  
15              
16 16     16   65 use Moo;
  16         28  
  16         119  
17 16     16   4807 use Business::Fixflo::Exception;
  16         38  
  16         408  
18 16     16   83 use Business::Fixflo::Envelope;
  16         36  
  16         4709  
19              
20             extends 'Business::Fixflo::Resource';
21              
22             =head1 ATTRIBUTES
23              
24             AgencyName
25             Created
26             CustomDomain
27             EmailAddress
28             FeatureType
29             Id
30             IsDeleted
31             IssueTreeRoot
32             SiteBaseUrl
33             DefaultTimeZoneId
34             Locale
35             Password
36             ApiKey
37             TermsAcceptanceUrl
38             TermsAcceptanceDate
39             UpdateDate
40              
41             =cut
42              
43             has [ qw/
44             AgencyName
45             Created
46             CustomDomain
47             EmailAddress
48             FeatureType
49             Id
50             IsDeleted
51             IssueTreeRoot
52             SiteBaseUrl
53             DefaultTimeZoneId
54             Locale
55             Password
56             ApiKey
57             TermsAcceptanceUrl
58             TermsAcceptanceDate
59             UpdateDate
60             / ] => (
61             is => 'rw',
62             );
63              
64             =head1 Operations on an agency
65              
66             =head2 create
67              
68             Creates an agency in the Fixflo API - will throw an exception if the Id
69             is already set
70              
71             =head2 update
72              
73             Updates an agency in the Fixflo API - will throw an exception if the Id
74             is not set
75              
76             =head2 delete
77              
78             Deletes an agency in the Fixflo API - will throw an exception if the Id
79             is not set
80              
81             =head2 undelete
82              
83             Undeletes an agency in the Fixflo API - will throw an exception if the Id
84             is not set
85              
86             =cut
87              
88             sub create {
89 4     4 1 58 my ( $self,$update ) = @_;
90              
91             $self->SUPER::_create( $update,'Agency',sub {
92             return { shift->to_hash },
93 4     2   21 } );
  2         36  
94             }
95              
96             sub delete {
97 3     3 1 34 my ( $self,$undelete ) = @_;
98              
99 3   100     12 $undelete //= 'delete';
100              
101 3 100       9 if ( ! $self->Id ) {
102 1         6 Business::Fixflo::Exception->throw({
103             message => "Can't $undelete Agency if Id is not set",
104             });
105             }
106              
107             $self->_parse_envelope_data(
108             # implemented as POST rather than DELETE as DELETE with content
109             # is a contentious issue in API design (and also webservers).
110             # the fixflo API says call to DELETE Agency/{Id} should include
111             # a content body with an Id matching the Id in the URL, but they
112             # also offer delete via POST - so we are using the POST here
113 2         42 $self->client->api_post( $self->url_no_id . "/$undelete",{ $self->to_hash } )
114             );
115              
116 2 100       9 $self->IsDeleted( $undelete eq 'undelete' ? 0 : 1 );
117              
118 2         8 return $self;
119             }
120              
121             sub undelete {
122 1     1 1 2 my ( $self ) = @_;
123 1         3 return $self->delete( 'undelete' );
124             }
125              
126             =head1 AUTHOR
127              
128             Lee Johnson - C
129              
130             This library is free software; you can redistribute it and/or modify it under
131             the same terms as Perl itself. If you would like to contribute documentation,
132             features, bug fixes, or anything else then please raise an issue / pull request:
133              
134             https://github.com/Humanstate/business-fixflo
135              
136             =cut
137              
138             1;
139              
140             # vim: ts=4:sw=4:et