X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FMisc%2FGeo.pm;fp=FS%2FFS%2FMisc%2FGeo.pm;h=73122fa6667e98b9c450a80bc1882b3a1b4337e7;hb=9faa6b1e007238ea1d953dfffa5c9089253b420c;hp=aa4e55e36761d469521d77897fb1989a0359ac8b;hpb=fad183c519f7d8b7c905708efc984c571b2c2990;p=freeside.git diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm index aa4e55e36..73122fa66 100644 --- a/FS/FS/Misc/Geo.pm +++ b/FS/FS/Misc/Geo.pm @@ -642,6 +642,42 @@ sub standardize_melissa { } } +sub standardize_freeside { + my $class = shift; + my $location = shift; + + my $url = 'https://ws.freeside.biz/normalize'; + + #free freeside.biz normalization only for US + if ( $location->{country} ne 'US' ) { + # soft failure + #why? something else could have cleaned it $location->{addr_clean} = ''; + return $location; + } + + my $ua = LWP::UserAgent->new( 'ssl_opts' => { 'verify_hostname'=>0 }); + my $response = $ua->request( POST $url, [ + 'support-key' => scalar($conf->config('support-key')), + %$location, + ]); + + die "Address normalization error: ". $response->message + unless $response->is_success; + + local $@; + my $content = eval { decode_json($response->content) }; + die "Address normalization JSON error : $@\n" if $@; + + die $content->{error}."\n" + if $content->{error}; + + { 'addr_clean' => 'Y', + map { $_ => $content->{$_} } + qw( address1 address2 city state zip country ) + }; + +} + =back =cut