Skip to content

Instantly share code, notes, and snippets.

@kga
Created March 24, 2009 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kga/84089 to your computer and use it in GitHub Desktop.
Save kga/84089 to your computer and use it in GitHub Desktop.
package App::SocialSKK::Plugin::ZipCode;
use strict;
use warnings;
use URI;
use URI::QueryParam;
use URI::Escape;
use JSON::Syck;
use base qw(App::SocialSKK::Plugin);
sub get_candidates {
my ($self, $text) = @_;
return if ($text || '') eq '';
if ($text =~ /\d{3}(?:-?\d{1,4})?/) {
my $uri = URI->new('http://groovetechnology.co.jp/ZipSearchService/v1/zipsearch');
$uri->query_param(zipcode => $text);
$uri->query_param(ie => 'EUC-JP');
$uri->query_param(oe => 'EUC-JP');
$uri->query_param(format => 'json');
my $res = $self->ua->get($uri);
if ($res->is_success) {
my $json = JSON::Syck::Load($res->content);
my @candidates;
for my $data (values %{$json->{zipcode}}) {
my $candidate = sprintf "%s%s%s;%s%s%s",
$data->{prefecture}, $data->{city}, $data->{town},
$data->{prefecture_yomi}, $data->{city_yomi}, $data->{town_yomi};
push @candidates, $candidate;
}
return @candidates;
}
}
}
1;
__END__
=head1 NAME
App::SocialSKK::Plugin::ZipCode - Retrieves Candidates from
zipcode search API
=head1 SYNOPSIS
# Add a line like below into your .socialskk:
plugins:
- name: ZipCode
=head1 DESCRIPTION
App::SocialSKK::Plugin::ZipCode performs retrieval of candidates
from zipcode search API.
=head1 SEE ALSO
=over 4
=item * Zipcode search api
GROOVE Technology Web Service
http://groovetechnology.co.jp/webservice/
=back
=head1 AUTHOR
Wataru TOYA E<lt>watrty@gmail.comE<gt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment