gared 0.0.29 → 0.1.0
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/primo.rb +35 -33
- data/test/test_gared.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae6b9daf5b73b6ff01acc3f098ad45ae0dccac12ea146f6966d58e25c3d8a74e
|
4
|
+
data.tar.gz: 19396d2e5e6701a22dd7d27e49491a9bd816a60d48278ca5562843c305f88282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c37a03e8f88f7c9b7d63761ced83736bfbedf55e3e94aee1c0fa9d53855d6d65a899a0e171d142ae46031dfd177fa3214e2cf8a4eb844f1f82db13b355ada1df
|
7
|
+
data.tar.gz: f4dd892a74e7fd1282e200f30ea1ab76bd87ebcd30629ec64a6c8c47a87d2d4eeef67481dd35454fe7f967a46b7a6da23bc3274ee7bf02c3fb87903a99720945
|
data/lib/gared/primo.rb
CHANGED
@@ -3,8 +3,8 @@ require 'rest-client'
|
|
3
3
|
|
4
4
|
module Gared
|
5
5
|
class Primo
|
6
|
-
def initialize(url,
|
7
|
-
@options = {url: url,
|
6
|
+
def initialize(url, vid, scope, apikey)
|
7
|
+
@options = {url: url, vid: vid, scope: scope, apikey: apikey}
|
8
8
|
end
|
9
9
|
def uri_escape(s)
|
10
10
|
p = URI::Parser.new
|
@@ -27,48 +27,50 @@ module Gared
|
|
27
27
|
def query_publications_by_person(person, ctx = nil)
|
28
28
|
ret = []
|
29
29
|
begin
|
30
|
-
|
31
|
-
json = JSON.parse(RestClient.get(
|
32
|
-
total = json['
|
33
|
-
start_at =
|
34
|
-
recs = json['
|
30
|
+
base_url = "#{@options[:url]}?vid=#{@options[:vid]}&scope=#{@options[:scope]}&q=creator,contains,#{uri_escape(person)}&qInclude=facet_rtype,exact,books&apikey=#{@options[:apikey]}&limit=50"
|
31
|
+
json = JSON.parse(RestClient.get(base_url))
|
32
|
+
total = json['info']['total'].to_i
|
33
|
+
start_at = 0
|
34
|
+
recs = json['docs'] # stash the records
|
35
35
|
while recs.length < total
|
36
36
|
start_at += 50
|
37
|
-
url =
|
37
|
+
url = base_url+"&offset=#{start_at}"
|
38
38
|
json = JSON.parse(RestClient.get(url))
|
39
|
-
recs += json['
|
40
|
-
sleep
|
39
|
+
recs += json['docs']
|
40
|
+
sleep 0.5 # respect the server and avoid flood-blocking
|
41
41
|
end
|
42
42
|
recs.each do |r|
|
43
43
|
begin
|
44
|
-
deets = r['
|
44
|
+
deets = r['pnx']['display'] # the fields inside are now always an array!
|
45
45
|
p = Publication.new(ctx)
|
46
|
-
p.title = deets['title']
|
47
|
-
p.author_line = deets['creator']
|
48
|
-
p.
|
49
|
-
p.
|
50
|
-
p.
|
51
|
-
p.
|
52
|
-
p.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
46
|
+
p.title = deets['title'].join('; ')
|
47
|
+
p.author_line = deets['creator'].join('; ')
|
48
|
+
p.author_line += deets['contributor'].join('; ') if deets['contributor']
|
49
|
+
p.language = deets['language'].join('; ')
|
50
|
+
p.notes = deets['format'].join('; ')+r['pnx']['search']['subject'].join('; ') # "#{deets['format']}\n#{deets['subject']}"
|
51
|
+
p.publisher_line = deets['publisher'].join('; ')
|
52
|
+
p.pub_year = deets['creationdate'].join('; ')
|
53
|
+
p.source_id = r['pnx']['control']['sourcerecordid'].join('; ')
|
54
|
+
## collect additional URLS from record, for clients to be able to determine whether a scanned object exists
|
55
|
+
# commented out for now, as it needs to be rewritten for the new Primo output structure
|
56
|
+
#additional_urls = []
|
57
|
+
#deets.keys.each do |key|
|
58
|
+
# if deets[key].class == Array
|
59
|
+
# deets[key].each do |kkey|
|
60
|
+
# additional_urls << kkey if kkey.class == String && kkey =~ /https?:[^\s]/
|
61
|
+
# end
|
62
|
+
# elsif deets[key].class == String
|
63
|
+
# additional_urls << deets[key] if deets[key] =~ /https?:[^\s]/
|
64
|
+
# end
|
65
|
+
#end
|
66
|
+
#p.additional_urls = additional_urls if additional_urls.length > 0
|
65
67
|
h = Holding.new
|
66
68
|
h.source_id = p.source_id
|
67
|
-
h.source_name = 'Primo:'+@options[:
|
69
|
+
h.source_name = 'Primo:'+@options[:vid]
|
68
70
|
|
69
71
|
begin
|
70
|
-
h.location = r['
|
71
|
-
rescue Exception
|
72
|
+
h.location = r['pnx']['search']['callnumber']
|
73
|
+
rescue Exception # We're skipping things without a callnumber, as they are not resources within the library itself.
|
72
74
|
puts $!
|
73
75
|
end
|
74
76
|
p.add_holding(h)
|
data/test/test_gared.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'minitest/byebug' if ENV['DEBUG']
|
2
1
|
require 'minitest/autorun'
|
3
2
|
require 'gared'
|
3
|
+
require 'minitest/debugger' if ENV['DEBUG']
|
4
4
|
|
5
5
|
class GaredTest < Minitest::Test
|
6
6
|
|
@@ -22,8 +22,8 @@ class GaredTest < Minitest::Test
|
|
22
22
|
|
23
23
|
# temporarily disabled until we find another Primo server to test against
|
24
24
|
def test_primo_query_publications_by_person
|
25
|
-
puts "Testing Primo"
|
26
|
-
primo = Gared::Primo.new('
|
25
|
+
puts "Testing Primo (did you remember to put a key in PRIMO_API_KEY?)"
|
26
|
+
primo = Gared::Primo.new('https://api-eu.hosted.exlibrisgroup.com/primo/v1/search', 'HAU', 'books_and_more', ENV['PRIMO_API_KEY'])
|
27
27
|
refute_nil primo
|
28
28
|
recs = primo.query_publications_by_person('אילנאה')
|
29
29
|
refute_nil recs
|
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.1.0
|
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: 2024-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: watir
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.5.1
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Scrape Hebrew bibliography sources
|