7 use Data::Dump qw/dump/;
12 my $debug = $ENV{DEBUG} || 0;
18 # based on http://code.google.com/apis/books/docs/v1/using.html#PerformingSearch
20 # https://www.googleapis.com/books/v1/volumes?q=search+terms
22 # This request has a single required parameter:
24 # q - Search for volumes that contain this text string. There are special keywords you can specify in the search terms to search in particular fields, such as:
25 # intitle: Returns results where the text following this keyword is found in the title.
26 # inauthor: Returns results where the text following this keyword is found in the author.
27 # inpublisher: Returns results where the text following this keyword is found in the publisher.
28 # subject: Returns results where the text following this keyword is listed in the category list of the volume.
29 # isbn: Returns results where the text following this keyword is the ISBN number.
30 # lccn: Returns results where the text following this keyword is the Library of Congress Control Number.
31 # oclc: Returns results where the text following this keyword is the Online Computer Library Center number.
36 # Bib-1 @and @and @and @and @and @and @and @or
42 # @attr 1=21 subject-holding
43 # @attr 1=12 control-no
44 # @attr 1=1007 standard-id
50 8 => 'isbn:', # FIXME?
60 my ( $self, $query ) = @_;
62 die "need query" unless defined $query;
64 my $url = 'https://www.googleapis.com/books/v1/volumes?q=' . $query;
68 my $mech = $self->{mech} || die "no mech?";
71 my $json = decode_json $mech->content;
72 diag "# json = ", dump($json) if $debug;
76 if ( exists $json->{items} ) {
77 $hits = $#{ $json->{items} } + 1;
79 diag "get't find results in ", $mech->content;
83 diag "got $hits results, get first one";
85 $self->{_json} = $json;
86 $self->{_json_item} = 0;
88 return $self->{hits} = $hits;
95 my ($self,$format) = @_;
99 my $item = $self->{_json}->{items}->[ $self->{_json_item}++ ];
101 warn "# item = ",dump($item) if $debug;
103 $marc = MARC::Record->new;
104 $marc->encoding('utf-8');
106 $marc->add_fields( 856, ' ', ' ', 'u' => $item->{accessInfo}->{webReaderLink} );
107 $marc->add_fields( 520, ' ', ' ', 'a' => $item->{searchInfo}->{textSnippet} );
109 # diag "# hash ",dump($hash);
110 diag "# marc ", $marc->as_formatted;
112 my $id = $item->{id} || die "no id";
114 $self->save_marc( "$id.marc", $marc->as_usmarc );