File Coverage

lib/Business/Fixflo.pm
Criterion Covered Total %
statement 41 43 95.3
branch n/a
condition n/a
subroutine 18 19 94.7
pod 0 14 0.0
total 59 76 77.6


line stmt bran cond sub pod time code
1             package Business::Fixflo;
2              
3             =head1 NAME
4              
5             Business::Fixflo - Perl library for interacting with the Fixflo API
6             (https://www.fixflo.com)
7              
8             =head1 VERSION
9              
10             0.47
11              
12             =head1 DESCRIPTION
13              
14             Business::Fixflo is a library for easy interface to the fixflo property
15             repair service, it implements all of the functionality currently found
16             in the service's API documentation: https://api-docs.fixflo.com/
17              
18             B
19             B, as the official API documentation explains in more depth
20             some of the functionality including required / optional parameters for certain
21             methods.
22              
23             Please note this library is a work in progress
24              
25             =head1 SYNOPSIS
26              
27             # agency API:
28             my $ff = Business::Fixflo->new(
29             custom_domain => $domain,
30             api_key => $api_key,
31              
32             # if api_key is not supplied:
33             username => $username,
34             password => $password,
35             );
36              
37             my $issues = $ff->issues,
38             my $agencies = $ff->agencies,
39              
40             while ( my @issues = @{ $issues->next // [] } ) {
41             foreach my $issue ( @issues ) {
42             $issue->get;
43             ...
44             }
45             }
46              
47             my $issue = $ff->issue( $id );
48             my $json = $issue->to_json;
49              
50             # third party API:
51             my $ff = Business::Fixflo->new(
52             api_key => $third_party_api_key,
53             username => $third_party_username,
54             password => $third_party_password,
55             );
56              
57             my $agency = Business::Fixflo::Agency->new(
58             client => $ff->client,
59             AgencyName => 'foo',
60             );
61              
62             $agency->create;
63             $agency->delete;
64              
65             =head1 ERROR HANDLING
66              
67             Any problems or errors will result in a Business::Fixflo::Exception
68             object being thrown, so you should wrap any calls to the library in the
69             appropriate error catching code (ideally using a module from CPAN):
70              
71             try {
72             ...
73             }
74             catch ( Business::Fixflo::Exception $e ) {
75             # error specific to Business::Fixflo
76             ...
77             say $e->message; # error message
78             say $e->code; # HTTP status code
79             say $e->response; # HTTP status message
80              
81             # ->request may not always be present
82             say $e->request->{path} if $e->request
83             say $e->request->{params} if $e->request
84             say $e->request->{headers} if $e->request
85             say $e->request->{content} if $e->request
86             }
87             catch ( $e ) {
88             # some other failure?
89             ...
90             }
91              
92             You can view some useful debugging information by setting the FIXFLO_DEBUG
93             env varible, this will show the calls to the Fixflo endpoints as well as a
94             stack trace in the event of exceptions:
95              
96             $ENV{FIXFLO_DEBUG} = 1;
97              
98             =cut
99              
100 16     16   128378 use strict;
  16         51  
  16         555  
101 16     16   85 use warnings;
  16         36  
  16         445  
102              
103 16     16   1826 use Moo;
  16         15030  
  16         115  
104             with 'Business::Fixflo::Version';
105              
106             $Business::Fixflo::VERSION = '0.47';
107              
108 16     16   8838 use Carp qw/ confess /;
  16         69  
  16         1205  
109              
110 16     16   1011 use Business::Fixflo::Client;
  16         44  
  16         15484  
111              
112             =head1 ATTRIBUTES
113              
114             =head2 username
115              
116             Your Fixflo username (required if api_key not supplied)
117              
118             =head2 password
119              
120             Your Fixflo password (required if api_key not supplied)
121              
122             =head2 api_key
123              
124             Your Fixflo API Key (required if username and password not supplied)
125              
126             =head2 custom_domain
127              
128             Your Fixflo custom domain, defaults to "api" (which will in fact call
129             the third party Fixflo API)
130              
131             =head2 url_suffix
132              
133             The url suffix to use after the custom domain, defaults to fixflo.com
134              
135             =head2 client
136              
137             A Business::Fixflo::Client object, this will be constructed for you so
138             you shouldn't need to pass this
139              
140             =cut
141              
142             has [ qw/ username password api_key / ] => (
143             is => 'ro',
144             required => 0,
145             );
146              
147             has custom_domain => (
148             is => 'ro',
149             required => 0,
150             default => sub { 'api' },
151             );
152              
153             has url_suffix => (
154             is => 'ro',
155             required => 0,
156             default => sub { 'fixflo.com' },
157             );
158              
159             has url_scheme => (
160             is => 'ro',
161             required => 0,
162             default => sub { 'https' },
163             );
164              
165             has client => (
166             is => 'ro',
167             isa => sub {
168             confess( "$_[0] is not a Business::Fixflo::Client" )
169             if ref $_[0] ne 'Business::Fixflo::Client';
170             },
171             required => 0,
172             lazy => 1,
173             default => sub {
174             my ( $self ) = @_;
175              
176             if ( $self->url_suffix =~ /\Qtest.fixflo.com\E/ ) {
177             $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
178             }
179              
180             return Business::Fixflo::Client->new(
181             api_key => $self->api_key,
182             username => $self->username,
183             password => $self->password,
184             custom_domain => $self->custom_domain,
185             url_suffix => $self->url_suffix,
186             url_scheme => $self->url_scheme,
187             );
188             },
189             );
190              
191             =head1 METHODS
192              
193             issues
194             agencies
195             landlords
196             properties
197             property_addresses
198             issue
199             issue_draft
200             issue_draft_media
201             landlord
202             landlord_property
203             agency
204             property
205             property_address
206             quick_view_panels
207              
208             Get a [list of] issue(s) / agenc(y|ies) / propert(y|ies) / property address(es) / landlord(s) / landlord_property:
209              
210             my $paginator = $ff->issues( %query_params );
211              
212             my $issue = $ff->issue( $id );
213              
214             Will return a L object (when calling endpoints
215             that return lists of items) or a Business::Fixflo:: object for the Issue,
216             Agency, etc.
217              
218             %query_params refers to the possible query params as shown in the currency
219             Fixflo API documentation. For example: page=[n]. You can pass DateTime objects
220             through and these will be correctly changed into strings when calling the API:
221              
222             # issues raised in the previous month
223             my $paginator = $ff->issues(
224             CreatedSince => DateTime->now->subtract( months => 1 ),
225             );
226              
227             # properties in given postal code
228             my $paginator = $ff->properties(
229             Keywords => 'NW1',
230             );
231              
232             Refer to the L documentation for what to do with
233             the returned paginator object.
234              
235             Note the property method can take a flag to indicate that the passed $id is an
236             external reference:
237              
238             my $Property = $ff->property( 'P123',1 );
239              
240             Note the landlord method can take a flag to indicate that the passed $id is an
241             email address
242              
243             my $Landlord = $ff->landlord( 'leejo@cpan.org',1 );
244              
245             Note the landlord_property method can take two arguments, it only one is passed
246             this is taken as the LandlordPropertyId, if two arguments are passed they are
247             taken as the LandlordId and the PropertyId:
248              
249             my $LandlordProperty = $ff->landlord_property( $landlord_property_id );
250              
251             my $LandlordProperty = $ff->landlord_property( $landlord_id,$property_id );
252              
253             =cut
254              
255             sub issues {
256 1     1 0 1004 my ( $self,%params ) = @_;
257 1         24 return $self->client->_get_issues( \%params );
258             }
259              
260             sub agencies {
261 1     1 0 17409 my ( $self,%params ) = @_;
262 1         27 return $self->client->_get_agencies( \%params );
263             }
264              
265             sub properties {
266 1     1 0 4517 my ( $self,%params ) = @_;
267 1         26 return $self->client->_get_properties( \%params );
268             }
269              
270             sub landlords {
271 1     1 0 3 my ( $self,%params ) = @_;
272 1         24 return $self->client->_get_landlords( \%params );
273             }
274              
275             sub property_addresses {
276 1     1 0 3445 my ( $self,%params ) = @_;
277 1         26 return $self->client->_get_property_addresses( \%params );
278             }
279              
280             sub issue {
281 2     2 0 2383 my ( $self,$id ) = @_;
282 2         51 return $self->client->_get_issue( $id );
283             }
284              
285             sub issue_draft {
286 2     2 0 540 my ( $self,$id ) = @_;
287 2         80 return $self->client->_get_issue_draft( $id );
288             }
289              
290             sub issue_draft_media {
291 2     2 0 537 my ( $self,$id ) = @_;
292 2         49 return $self->client->_get_issue_draft_media( $id );
293             }
294              
295             sub agency {
296 2     2 0 531 my ( $self,$id ) = @_;
297 2         49 return $self->client->_get_agency( $id );
298             }
299              
300             sub property {
301 2     2 0 545 my ( $self,$id,$is_external_id ) = @_;
302 2         47 return $self->client->_get_property( $id,$is_external_id );
303             }
304              
305             sub landlord {
306 2     2 0 519 my ( $self,$id,$is_external_id ) = @_;
307 2         48 return $self->client->_get_landlord( $id,$is_external_id );
308             }
309              
310             sub landlord_property {
311 0     0 0 0 my ( $self,$id_or_landlord_id,$property_id ) = @_;
312 0         0 return $self->client->_get_landlord_property( $id_or_landlord_id,$property_id );
313             }
314              
315             sub property_address {
316 2     2 0 542 my ( $self,$id ) = @_;
317 2         47 return $self->client->_get_property_address( $id );
318             }
319              
320             sub quick_view_panels {
321 1     1 0 3351 my ( $self ) = @_;
322 1         26 return $self->client->_get_quick_view_panels;
323             }
324              
325             =head1 EXAMPLES
326              
327             See the t/002_end_to_end.t test included with this distribution. you can run
328             this test against the fixflo test server (requires ENV variables to set the
329             Fixflo credentials)
330              
331             =head1 SEE ALSO
332              
333             L
334              
335             L
336              
337             L
338              
339             L
340              
341             L
342              
343             L
344              
345             L
346              
347             L
348              
349             L
350              
351             L
352              
353             L
354              
355             L
356              
357             L
358              
359             =head1 AUTHOR
360              
361             Lee Johnson - C
362              
363             =head1 LICENSE
364              
365             This library is free software; you can redistribute it and/or modify it under
366             the same terms as Perl itself. If you would like to contribute documentation,
367             features, bug fixes, or anything else then please raise an issue / pull request:
368              
369             https://github.com/Humanstate/business-fixflo
370              
371             =cut
372              
373             1;
374              
375             # vim: ts=4:sw=4:et