WWW::Datafinder - Perl API for Datafinder http://datafinder.com API for marketing data append
Version 0.03
use WWW::Datafinder; use Text::CSV_XS; use Data::Dumper; my $csv = Text::CSV_XS->new; my $df = WWW::Datafinder->new( { api_key => '456', # place a real API key here cache_dir => '/var/tmp/datafinder', cache_time => 3600 * 24 * 14 }) or die 'Cannot create Datafinder object'; # process a CSV file with 6 columns: # First Name, Last Name, Address, City, State, ZIP while(<>) { chomp; my $status = $csv->parse($_); unless ($status) { warn qq{Cannot parse '$_':}.$csv->error_diag(); next; } my ($name, $surname, $addr, $city, $state, $zip) = $csv->fields(); my $data = { d_first => $name, d_last => $surname, d_fulladdr => $addr, d_city => $city, d_state => $state, d_zip => $zip }; my $res = $df->append_email($data); if ($res) { if ( $res->{'num-results'} ) { # there is a match! print "Got a match for $name $surname: " . Dumper( $res->{results} ); } } }
Creates a new object, acceptable parameters are:
api_key
retries
cache_time
cache_dir
Attempts to append customer's email based on his/her name and address (or phone number). Please see https://datafinder.com/api/docs-demo for more info regarding the parameter names and format of their values in $data. Returns a reference to a hash, which contains the response received from the server. Returns undef on failure, application then may call error_message() method to get the detailed info about the error.
$data
undef
error_message()
my $res = $df->append_email( { d_fulladdr => $cust->{Address}, d_city => $cust->{City}, d_state => $cust->{State}, d_zip => $cust->{ZIP}, d_first => $cust->{Name}, d_last => $cust->{Surname} } ); if ( $res ) { if ( $res->{'num-results'} ) { # there is a match! print "Got a match: " . Dumper( $res->{results} ); } } else { warn 'Something went wrong ' . $df->error_message(); }
Attempts to append customer's phone number based on his/her name and address Please see https://datafinder.com/api/docs-demo for more info regarding the parameter names and format of their values in $data. Returns a reference to a hash, which contains the response received from the server. Returns undef on failure, application then may call error_message() method to get the detailed info about the error.
my $res = $df->append_phone( { d_fulladdr => $cust->{Address}, d_city => $cust->{City}, d_state => $cust->{State}, d_zip => $cust->{ZIP}, d_first => $cust->{Name}, d_last => $cust->{Surname} } ); if ( $res ) { if ( $res->{'num-results'} ) { # there is a match! print "Got a match: " . Dumper( $res->{results} ); } } else { warn 'Something went wrong ' . $df->error_message(); }
Attempts to append customer's demographic data on his/her name and address Please see https://datafinder.com/api/docs-demo for more info regarding the parameter names and format of their values in $data. Returns a reference to a hash, which contains the response received from the server. Returns undef on failure, application then may call error_message() method to get the detailed info about the error.
my $res = $df->append_demograph( { d_fulladdr => $cust->{Address}, d_city => $cust->{City}, d_state => $cust->{State}, d_zip => $cust->{ZIP}, d_first => $cust->{Name}, d_last => $cust->{Surname} } ); if ( $res ) { if ( $res->{'num-results'} ) { # there is a match! print "Got a match: " . Dumper( $res->{results} ); } } else { warn 'Something went wrong ' . $df->error_message(); }
Returns the detailed explanation of the last error. Empty string if everything went fine.
my $res = $df->append_email($cust_data); unless ($res) { warn 'Something went wrong '.$df->error_message(); }
If you want to troubleshoot the data being sent between the client and the server - set environment variable DEBUG to a positive value.
The returned results can be cached in a local file, so the next time you want to retrieve the data for the same person, you get a faster response and do not have to spend money. Negative results (no match) are cached as well to speed things up.
The hash key for a request is calculated as MD5 of all request parameters (including API key). The result is stored in a file (via Storable). Files are organized in the two-level directory structure (so fea5ffd3d65ee4d8bdf630677c0c5ff6.stor goes into /var/tmp/datafinder-cache/fe/a5/) to accommodate potentially large amount of files.
When a result is returned from the cache instead of the real server, it has the cached key set to the timestamp of the original data retrieval and cache_object set to the filename of the cache file.
cached
cache_object
Andrew Zhilenko, <perl at putinhuylo.org> (c) Putin Huylo LLC, 2017
<perl at putinhuylo.org>
Please report any bugs or feature requests to bug-www-datafinder at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Datafinder. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-www-datafinder at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc WWW::Datafinder
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Datafinder
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/WWW-Datafinder
Copyright 2017 Putin Huylo LLC
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:
http://www.perlfoundation.org/artistic_license_2_0
Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install WWW::Datafinder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Datafinder
CPAN shell
perl -MCPAN -e shell install WWW::Datafinder
For more information on module installation, please visit the detailed CPAN module installation guide.