+ } elsif ( $method =~ m{/sip2/(\w+)/(.+)} ) {
+ my ( $method, $args ) = ( $1, $2 );
+ warn "SIP2: $method [$args]";
+
+ my $ts = strftime('%Y%m%d %H%M%S', localtime());
+ my $loc = $sip2->{loc} || die "missing sip->{loc}";
+ my $password = $sip2->{password} || die "missing sip->{password}";
+
+ my $hash;
+
+ if ( $method eq 'patron_info' ) {
+ my $patron = $args;
+ $hash = sip2_message("63000${ts} AO$loc|AA$patron|AC$password|");
+
+ } elsif ( $method eq 'checkout' ) {
+ my ($patron,$barcode,$sid) = split(/\//, $args, 3);
+ $hash = sip2_message("11YN${ts} AO$loc|AA$patron|AB$barcode|AC$password|BON|BIN|");
+ if ( substr( $hash->{fixed}, 2, 1 ) == 1 ) {
+ $rfid->write_afi( $sid => chr( $afi->{unsecure} ) );
+ }
+
+ } elsif ( $method eq 'checkin' ) {
+ my ($patron,$barcode,$sid) = split(/\//, $args, 3);
+ $hash = sip2_message("09N${ts}${ts}AP|AO${loc}|AB$barcode|AC|BIN|");
+ if ( substr( $hash->{fixed}, 2, 1 ) == 1 ) {
+ $rfid->write_afi( $sid => chr( $afi->{secure} ) );
+ }
+ } else {
+ print $client "HTTP/1.0 501 $method not implemented\r\n\r\n";
+ warn "ERROR 501 $request\n";
+ }
+
+ if ( $hash ) {
+ print $client "HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n",
+ encode_json( $hash );
+ }
+
+ } elsif ( $method =~ m{/beep/(.*)} ) {
+ my $error = uri_unescape($1);
+ system "beep -f 800 -r 2 -l 100";
+ print $client "HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n{ beep: '$error' }\n";
+ print "BEEP $error\n";