gared 0.0.23 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gared/googlebooks.rb +6 -2
- data/lib/gared/nli_api.rb +8 -4
- data/lib/gared/primo.rb +7 -3
- data/lib/gared.rb +0 -1
- data/test/test_gared.rb +28 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3857f28b69b7cd0d1080208215cbf1bfc57a30a3af5df8162a98aee5b7558939
|
4
|
+
data.tar.gz: a3cf8fbe5018b902db45f6d70c8223f32101c6eb747b070a7f7dc56a8a37c48c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69f3b46c6fa96f5bf2c2f440fbc9bf93bbe57ec8ac61e84a9621289e67b919342558a323a9b14008d58f7472e48651ee43bd584879b011d78741a6212b7e81b1
|
7
|
+
data.tar.gz: f822f3a7f95e6c4ca38f78843a4309b764a624d053234bc880b672ec57cf011b88b3089f5a40836f328a8e1a366cb6660500609449a11eed16d5b0c7a86ac64e
|
data/lib/gared/googlebooks.rb
CHANGED
@@ -5,9 +5,13 @@ module Gared
|
|
5
5
|
def initialize(api_key, page_size = '40')
|
6
6
|
@options = {api_key: api_key, maxResults: page_size}
|
7
7
|
end
|
8
|
-
|
8
|
+
def uri_escape(s)
|
9
|
+
p = URI::Parser.new
|
10
|
+
return p.escape(s)
|
11
|
+
end
|
12
|
+
|
9
13
|
def query_publications_by_person(person, ctx = nil)
|
10
|
-
url = "https://www.googleapis.com/books/v1/volumes?q=inauthor:#{
|
14
|
+
url = "https://www.googleapis.com/books/v1/volumes?q=inauthor:#{uri_escape(person)}&filter=full&key=#{@options[:api_key]}&maxResults=#{@options[:maxResults]}"
|
11
15
|
resp = JSON.parse(RestClient.get(url))
|
12
16
|
|
13
17
|
total = resp['totalItems']
|
data/lib/gared/nli_api.rb
CHANGED
@@ -5,7 +5,11 @@ module Gared
|
|
5
5
|
def initialize(url, api_key)
|
6
6
|
@options = {url: url, api_key: api_key}
|
7
7
|
end
|
8
|
-
|
8
|
+
def uri_escape(s)
|
9
|
+
p = URI::Parser.new
|
10
|
+
return p.escape(s)
|
11
|
+
end
|
12
|
+
|
9
13
|
def query_persons(q)
|
10
14
|
end
|
11
15
|
|
@@ -36,15 +40,15 @@ module Gared
|
|
36
40
|
ret = []
|
37
41
|
begin
|
38
42
|
# first run obtain counts for the query
|
39
|
-
escaped_person =
|
40
|
-
url = @options[:url]+"?api_key=#{@options[:api_key]}&query=creator,contains,#{escaped_person},AND;language,exact,heb&sort_field=title&material_type=
|
43
|
+
escaped_person = uri_escape(person)
|
44
|
+
url = @options[:url]+"?api_key=#{@options[:api_key]}&query=creator,contains,#{escaped_person},AND;language,exact,heb&sort_field=title&material_type=book&count_mode=true"
|
41
45
|
json = JSON.parse(RestClient::Resource.new(url,verify_ssl: OpenSSL::SSL::VERIFY_NONE).get)
|
42
46
|
total = json['countInfos']['total']
|
43
47
|
# then start loading the results
|
44
48
|
result_page = 1
|
45
49
|
recs = []
|
46
50
|
while recs.length < total
|
47
|
-
url = @options[:url]+"?api_key=#{@options[:api_key]}&query=creator,contains,#{escaped_person},AND;language,exact,heb&sort_field=title&material_type=
|
51
|
+
url = @options[:url]+"?api_key=#{@options[:api_key]}&query=creator,contains,#{escaped_person},AND;language,exact,heb&sort_field=title&material_type=book&result_page=#{result_page}"
|
48
52
|
puts "DBG: retrieving results page #{result_page}"
|
49
53
|
json = JSON.parse(RestClient::Resource.new(url,verify_ssl: OpenSSL::SSL::VERIFY_NONE).get)
|
50
54
|
recs += json
|
data/lib/gared/primo.rb
CHANGED
@@ -6,7 +6,11 @@ module Gared
|
|
6
6
|
def initialize(url, institution)
|
7
7
|
@options = {url: url, institution: institution}
|
8
8
|
end
|
9
|
-
|
9
|
+
def uri_escape(s)
|
10
|
+
p = URI::Parser.new
|
11
|
+
return p.escape(s)
|
12
|
+
end
|
13
|
+
|
10
14
|
def query_persons(q)
|
11
15
|
end
|
12
16
|
|
@@ -23,14 +27,14 @@ module Gared
|
|
23
27
|
def query_publications_by_person(person, ctx = nil)
|
24
28
|
ret = []
|
25
29
|
begin
|
26
|
-
url = @options[:url]+"?institution=#{@options[:institution]}&query=creator,contains,#{
|
30
|
+
url = @options[:url]+"?institution=#{@options[:institution]}&query=creator,contains,#{uri_escape(person)}&indx=1&bulkSize=50&query=facet_rtype,exact,books&json=true"
|
27
31
|
json = JSON.parse(RestClient.get(url))
|
28
32
|
total = json['SEGMENTS']['JAGROOT']['RESULT']['DOCSET']['@TOTALHITS'].to_i
|
29
33
|
start_at = 1
|
30
34
|
recs = json['SEGMENTS']['JAGROOT']['RESULT']['DOCSET']['DOC'] # stash the records
|
31
35
|
while recs.length < total
|
32
36
|
start_at += 50
|
33
|
-
url = @options[:url]+"?institution=#{@options[:institution]}&query=creator,contains,#{
|
37
|
+
url = @options[:url]+"?institution=#{@options[:institution]}&query=creator,contains,#{uri_escape(person)}&indx=#{start_at}&bulkSize=50&query=facet_rtype,exact,books&json=true"
|
34
38
|
json = JSON.parse(RestClient.get(url))
|
35
39
|
recs += json['SEGMENTS']['JAGROOT']['RESULT']['DOCSET']['DOC']
|
36
40
|
sleep 1 # respect the server and avoid flood-blocking
|
data/lib/gared.rb
CHANGED
data/test/test_gared.rb
CHANGED
@@ -12,36 +12,42 @@ class GaredTest < Minitest::Test
|
|
12
12
|
puts "Testing NLI API"
|
13
13
|
nli = Gared::Nli_Api.new('https://api.nli.org.il/openlibrary/search', ENV['NLI_API_KEY'])
|
14
14
|
refute_nil nli
|
15
|
-
recs = nli.query_publications_by_person('ביאליק')
|
16
|
-
|
15
|
+
#recs = nli.query_publications_by_person('ביאליק')
|
16
|
+
recs = nli.query_publications_by_person('אילנאה')
|
17
17
|
refute_nil recs
|
18
18
|
refute_empty(recs)
|
19
19
|
refute_empty(recs[0].title)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
refute_empty(recs
|
30
|
-
|
22
|
+
# temporarily disabled until we find another Primo server to test against
|
23
|
+
# def test_primo_query_publicatios_by_person
|
24
|
+
# puts "Testing Primo"
|
25
|
+
# primo = Gared::Primo.new('http://primo.nli.org.il/PrimoWebServices/xservice/search/brief', 'NNL')
|
26
|
+
# refute_nil primo
|
27
|
+
# recs = primo.query_publications_by_person('אילנאה')
|
28
|
+
# refute_nil recs
|
29
|
+
# refute_empty(recs)
|
30
|
+
# refute_empty(recs[0].title)
|
31
|
+
# end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
refute_empty(recs
|
40
|
-
|
33
|
+
# temporarily disabled until we find another Aleph server to test against
|
34
|
+
# def test_aleph_query_publicatios_by_person
|
35
|
+
# puts "Testing Aleph"
|
36
|
+
# aleph = Gared::Aleph.new('aleph.nli.org.il', 9991, 'NNL01')
|
37
|
+
# refute_nil aleph
|
38
|
+
# recs = aleph.query_publications_by_person('אילנאה')
|
39
|
+
# refute_nil recs
|
40
|
+
# refute_empty(recs)
|
41
|
+
# refute_empty(recs[0].title)
|
42
|
+
# end
|
41
43
|
|
42
44
|
def test_googlebooks_query_publicatios_by_person
|
45
|
+
if ENV['GOOGLE_API_KEY'].nil?
|
46
|
+
puts "skipping Google Books API test because GOOGLE_API_KEY envvar is not set"
|
47
|
+
return
|
48
|
+
end
|
43
49
|
puts "Testing Google Books"
|
44
|
-
gb = Gared::Googlebooks.new('
|
50
|
+
gb = Gared::Googlebooks.new(ENV['GOOGLE_API_KEY'])
|
45
51
|
refute_nil gb
|
46
52
|
recs = gb.query_publications_by_person('מנדלי')
|
47
53
|
refute_nil recs
|
@@ -74,4 +80,4 @@ class GaredTest < Minitest::Test
|
|
74
80
|
assert_empty(recs)
|
75
81
|
end
|
76
82
|
|
77
|
-
end
|
83
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asaf Bartov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zoom
|