13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/gared/googlebooks.rb', line 13
def query_publications_by_person(person, ctx = nil)
url = "https://www.googleapis.com/books/v1/volumes?q=inauthor:#{uri_escape(person)}&filter=full&key=#{@options[:api_key]}&maxResults=#{@options[:maxResults]}"
resp = JSON.parse(RestClient.get(url))
total = resp['totalItems']
ret = []
if total > 0
start_at = 0
recs = resp['items']
while recs.length < total
start_at += @options[:maxResults]
resp = JSON.parse(RestClient.get(url+"&startIndex=#{start_at}"))
recs += resp['items']
sleep 2 end
recs.each do |r|
next unless r['accessInfo']['pdf']['isAvailable']
p = Publication.new(ctx)
p.source_id = r['id']
p.scanned = true
p.title = r['volumeInfo']['title']
h = Holding.new
h.source_id = r['id']
h.source_name = 'Google Books'
p.add_holding(h)
ret << p
end
end
return ret
end
|