X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=scripts%2FRFID-JSONP-server.pl;h=08258d1a4c0817ceb2942f3b26db89b0456d443d;hb=b87d39334a83098104ec6be7da9adbefb7b1f998;hp=1c464056c88f461b906013f831bc4343bea9a176;hpb=3dba159608abc6b4d3ba147d8f8bb44dc3cbfa25;p=Biblio-RFID.git diff --git a/scripts/RFID-JSONP-server.pl b/scripts/RFID-JSONP-server.pl index 1c46405..08258d1 100755 --- a/scripts/RFID-JSONP-server.pl +++ b/scripts/RFID-JSONP-server.pl @@ -17,9 +17,12 @@ use Data::Dump qw/dump/; use JSON::XS; use IO::Socket::INET; +use LWP::UserAgent; +use URI; my $debug = 1; my $listen = '127.0.0.1:9000'; +$listen = ':9000'; my $reader; use Getopt::Long; @@ -30,6 +33,31 @@ GetOptions( 'reader=s', => \$reader, ) || die $!; +our $rfid_sid_cache; + +sub rfid_borrower { + my $hash = shift; + if ( my $json = $rfid_sid_cache->{ $hash->{sid} } ) { + return $json; + } + my $ua = LWP::UserAgent->new; + my $url = URI->new('http://ffzg.koha-dev.rot13.org:8080/cgi-bin/koha/ffzg/rfid-borrower.pl'); + $url->query_form( + RFID_SID => $hash->{sid} + , OIB => $hash->{OIB} + , JMBAG => $hash->{JMBAG} + ); + warn "GET ",$url->as_string; + my $response = $ua->get($url); + if ( $response->is_success ) { + my $json = decode_json $response->decoded_content; + $rfid_sid_cache->{ $hash->{sid} } = $json; + return $json; + } else { + warn "ERROR ", $response->status_line; + } +} + use lib 'lib'; use Biblio::RFID::RFID501; use Biblio::RFID::Reader; @@ -99,7 +127,16 @@ sub http_server { foreach my $tag ( @tags ) { my $hash = $rfid->to_hash( $tag ); $hash->{sid} = $tag; - $hash->{security} = uc unpack 'H*', $rfid->afi( $tag ) if $hash->{tag_type} ne 'SmartX'; + if ( $hash->{tag_type} eq 'SmartX' ) { + my $borrower = rfid_borrower $hash; + if ( exists $borrower->{error} ) { + warn "ERROR ", dump($borrower); + } else { + $hash->{borrower} = $borrower->{borrower}; + } + } else { + $hash->{security} = uc unpack 'H*', $rfid->afi( $tag ); + } push @{ $json->{tags} }, $hash; }; warn "#### ", encode_json($json); @@ -203,15 +240,19 @@ function got_visible_tags(data,textStatus) { html = '