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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd1e7f535a0650e0251fec57b3572e49dda88b189b96fe1d1b630acc5e147bb4
4
- data.tar.gz: b606f6169bdf2cac88f5d29cec6bf4e5464a639bc73b655a24c61aecf7593cd1
3
+ metadata.gz: 3857f28b69b7cd0d1080208215cbf1bfc57a30a3af5df8162a98aee5b7558939
4
+ data.tar.gz: a3cf8fbe5018b902db45f6d70c8223f32101c6eb747b070a7f7dc56a8a37c48c
5
5
  SHA512:
6
- metadata.gz: b5c082ab85a8a7fb4cf5c23af7ebc35584751ebcaf88defc1b4f8c8d808d5cb3ff5d213db4b07687bfae49fda11b12f6963c9c6d2bd2e6b1d2e5edcc487e6e4b
7
- data.tar.gz: a4415463242669077a504252094c2e93f63469fe6fcd4faeeee7a5cceb852b5325608dd5255991c79f04d725856ac61296023301c39af0a4f48288dbe1ddad70
6
+ metadata.gz: 69f3b46c6fa96f5bf2c2f440fbc9bf93bbe57ec8ac61e84a9621289e67b919342558a323a9b14008d58f7472e48651ee43bd584879b011d78741a6212b7e81b1
7
+ data.tar.gz: f822f3a7f95e6c4ca38f78843a4309b764a624d053234bc880b672ec57cf011b88b3089f5a40836f328a8e1a366cb6660500609449a11eed16d5b0c7a86ac64e
@@ -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:#{URI.escape(person)}&filter=full&key=#{@options[:api_key]}&maxResults=#{@options[:maxResults]}"
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 = URI.escape(person)
40
- url = @options[:url]+"?api_key=#{@options[:api_key]}&query=creator,contains,#{escaped_person},AND;language,exact,heb&sort_field=title&material_type=books&count_mode=true"
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=books&result_page=#{result_page}"
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,#{URI.escape(person)}&indx=1&bulkSize=50&query=facet_rtype,exact,books&json=true"
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,#{URI.escape(person)}&indx=#{start_at}&bulkSize=50&query=facet_rtype,exact,books&json=true"
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
@@ -9,5 +9,4 @@ module Gared
9
9
  require 'gared/googlebooks'
10
10
  require 'gared/nli_api'
11
11
  # ...
12
-
13
12
  end
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
- #recs = nli.query_publications_by_person('אילנאה')
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
- def test_primo_query_publicatios_by_person
23
- puts "Testing Primo"
24
- primo = Gared::Primo.new('http://primo.nli.org.il/PrimoWebServices/xservice/search/brief', 'NNL')
25
- refute_nil primo
26
- recs = primo.query_publications_by_person('אילנאה')
27
- refute_nil recs
28
- refute_empty(recs)
29
- refute_empty(recs[0].title)
30
- end
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
- def test_aleph_query_publicatios_by_person
33
- puts "Testing Aleph"
34
- aleph = Gared::Aleph.new('aleph.nli.org.il', 9991, 'NNL01')
35
- refute_nil aleph
36
- recs = aleph.query_publications_by_person('אילנאה')
37
- refute_nil recs
38
- refute_empty(recs)
39
- refute_empty(recs[0].title)
40
- end
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('AIzaSyCE2WFqTPdxAz1wv2f33hMfPWIF4tcocgM') # a key I made just for testing this gem. Please do not abuse.
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.23
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: 2021-05-13 00:00:00.000000000 Z
11
+ date: 2022-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zoom