purl_fetcher-client 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +27 -0
- data/lib/purl_fetcher/client/public_xml_record.rb +66 -8
- data/lib/purl_fetcher/client/reader.rb +8 -0
- data/lib/purl_fetcher/client/version.rb +1 -1
- data/purl_fetcher-client.gemspec +3 -1
- metadata +41 -13
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97df63e9b1a234a5c89c948ca110180d6d9a620042e5280b036c15259a79d8ea
|
4
|
+
data.tar.gz: 50fd0e88ef00cc1da27d75c71fedffaac1a8beaf5d930280255bc878321e4c7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72ac95809823377fa72cbb2f5b52fb11a4c3f69de2a17c250491a54b2b74549ddc1563cc0d5aa7170b07824a57c53afb348c4d29c03f771442dab64a7a87443
|
7
|
+
data.tar.gz: 41b9ef57041248734ff4f31e0bdd262e01018a618a4231f9f0b3c6b11dd65e8caa443a54b0ba48458b44fc7d17fba128d726f0d7e85935067021303ee85d4509
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
tests:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 3.0
|
18
|
+
- uses: actions/cache@v2
|
19
|
+
with:
|
20
|
+
path: vendor/bundle
|
21
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
|
22
|
+
restore-keys: |
|
23
|
+
${{ runner.os }}-gems-
|
24
|
+
- name: Bundle install
|
25
|
+
run: bundle install
|
26
|
+
- name: Run tests
|
27
|
+
run: bundle exec rake
|
@@ -1,15 +1,28 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'stanford-mods'
|
3
|
+
require 'mods_display'
|
4
|
+
require 'dor/rights_auth'
|
3
5
|
|
4
6
|
module PurlFetcher::Client
|
5
7
|
class PublicXmlRecord
|
8
|
+
include ModsDisplay::ModelExtension
|
9
|
+
include ModsDisplay::ControllerExtension
|
10
|
+
|
11
|
+
mods_xml_source do |model|
|
12
|
+
model.mods.to_s
|
13
|
+
end
|
14
|
+
configure_mods_display do
|
15
|
+
end
|
16
|
+
|
6
17
|
attr_reader :druid, :options
|
7
18
|
|
8
19
|
def self.fetch(url)
|
9
|
-
if defined?(
|
10
|
-
Manticore.get(url)
|
20
|
+
if defined?(JRUBY_VERSION)
|
21
|
+
response = Manticore.get(url)
|
22
|
+
response.body if response.code == 200
|
11
23
|
else
|
12
|
-
HTTP.get(url)
|
24
|
+
response = HTTP.get(url)
|
25
|
+
response.body if response.status.ok?
|
13
26
|
end
|
14
27
|
end
|
15
28
|
|
@@ -42,10 +55,18 @@ module PurlFetcher::Client
|
|
42
55
|
end
|
43
56
|
end
|
44
57
|
|
58
|
+
def mods_display
|
59
|
+
@mods_display ||= render_mods_display(self)
|
60
|
+
end
|
61
|
+
|
45
62
|
def public_xml
|
46
63
|
@public_xml ||= self.class.fetch(purl_base_url + "/#{druid}.xml")
|
47
64
|
end
|
48
65
|
|
66
|
+
def public_xml?
|
67
|
+
!!public_xml
|
68
|
+
end
|
69
|
+
|
49
70
|
def public_xml_doc
|
50
71
|
@public_xml_doc ||= Nokogiri::XML(public_xml)
|
51
72
|
end
|
@@ -54,7 +75,7 @@ module PurlFetcher::Client
|
|
54
75
|
@mods ||= if public_xml_doc.xpath('/publicObject/mods:mods', mods: 'http://www.loc.gov/mods/v3').any?
|
55
76
|
public_xml_doc.xpath('/publicObject/mods:mods', mods: 'http://www.loc.gov/mods/v3').first
|
56
77
|
else
|
57
|
-
self.class.fetch(purl_base_url + "
|
78
|
+
self.class.fetch(purl_base_url + "/#{druid}.mods")
|
58
79
|
end
|
59
80
|
end
|
60
81
|
|
@@ -111,16 +132,22 @@ module PurlFetcher::Client
|
|
111
132
|
|
112
133
|
def collections
|
113
134
|
@collections ||= predicate_druids('isMemberOfCollection').map do |druid|
|
114
|
-
PublicXmlRecord.new(druid,
|
135
|
+
PublicXmlRecord.new(druid, options)
|
115
136
|
end
|
116
137
|
end
|
117
138
|
|
118
139
|
def constituents
|
119
140
|
@constituents ||= predicate_druids('isConstituentOf').map do |druid|
|
120
|
-
PublicXmlRecord.new(druid,
|
141
|
+
PublicXmlRecord.new(druid, options)
|
121
142
|
end
|
122
143
|
end
|
123
144
|
|
145
|
+
def items(&block)
|
146
|
+
return [] unless is_collection
|
147
|
+
|
148
|
+
purl_fetcher_client.collection_members(druid, &block)
|
149
|
+
end
|
150
|
+
|
124
151
|
# the thumbnail in publicXML properly URI encoded, including the slash separator
|
125
152
|
# @return [String] thumb filename with druid prepended, e.g. oo000oo0001%2Ffilename%20withspace.jp2
|
126
153
|
def encoded_thumb
|
@@ -128,7 +155,7 @@ module PurlFetcher::Client
|
|
128
155
|
return unless thumb
|
129
156
|
thumb_druid=thumb.split('/').first # the druid (before the first slash)
|
130
157
|
thumb_filename=thumb.split(/[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}[0-9]{4}[\/]/).last # everything after the druid
|
131
|
-
"#{thumb_druid}%2F#{
|
158
|
+
"#{thumb_druid}%2F#{ERB::Util.url_encode(thumb_filename)}"
|
132
159
|
end
|
133
160
|
|
134
161
|
# get the druids from predicate relationships in rels-ext from public_xml
|
@@ -142,8 +169,39 @@ module PurlFetcher::Client
|
|
142
169
|
end
|
143
170
|
end
|
144
171
|
|
172
|
+
def druid_tree
|
173
|
+
druid.match(/(..)(...)(..)(....)/).captures.join('/')
|
174
|
+
end
|
175
|
+
|
176
|
+
def rights_xml
|
177
|
+
@rights_xml ||= public_xml_doc.xpath('//rightsMetadata').to_s
|
178
|
+
end
|
179
|
+
|
180
|
+
def rights
|
181
|
+
@rights ||= ::Dor::RightsAuth.parse(rights_xml)
|
182
|
+
end
|
183
|
+
|
184
|
+
def public?
|
185
|
+
rights.world_unrestricted?
|
186
|
+
end
|
187
|
+
|
188
|
+
def stanford_only?
|
189
|
+
rights.stanford_only_unrestricted?
|
190
|
+
end
|
191
|
+
|
145
192
|
def purl_base_url
|
146
|
-
options[:purl_url] || 'https://purl.stanford.edu'
|
193
|
+
options[:purl_url]&.sub(%r{/$}, '') || 'https://purl.stanford.edu'
|
194
|
+
end
|
195
|
+
|
196
|
+
def purl_fetcher_api_endpoint
|
197
|
+
options[:purl_fetcher_url] || 'https://purl-fetcher.stanford.edu'
|
198
|
+
end
|
199
|
+
|
200
|
+
def purl_fetcher_client
|
201
|
+
@purl_fetcher_client ||= PurlFetcher::Client::Reader.new(
|
202
|
+
nil,
|
203
|
+
'purl_fetcher.api_endpoint' => purl_fetcher_api_endpoint
|
204
|
+
)
|
147
205
|
end
|
148
206
|
end
|
149
207
|
end
|
@@ -20,6 +20,14 @@ class PurlFetcher::Client::Reader
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def collection_members(druid)
|
24
|
+
return to_enum(:collection_members, druid) unless block_given?
|
25
|
+
|
26
|
+
paginated_get("/collections/druid:#{druid.sub(/^druid:/, '')}/purls", 'purls').each do |obj, _meta|
|
27
|
+
yield PurlFetcher::Client::PublicXmlRecord.new(obj['druid'].sub('druid:', ''), settings), obj, self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
23
31
|
private
|
24
32
|
|
25
33
|
def first_modified
|
data/purl_fetcher-client.gemspec
CHANGED
@@ -23,8 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'http'
|
24
24
|
spec.add_dependency 'nokogiri'
|
25
25
|
spec.add_dependency 'stanford-mods'
|
26
|
+
spec.add_dependency 'dor-rights-auth'
|
27
|
+
spec.add_dependency 'mods_display'
|
26
28
|
|
27
29
|
spec.add_development_dependency "bundler"
|
28
|
-
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rake"
|
29
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purl_fetcher-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dor-rights-auth
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mods_display
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: bundler
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +98,16 @@ dependencies:
|
|
70
98
|
name: rake
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
|
-
- - "
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
103
|
+
version: '0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- - "
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: rspec
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,16 +122,16 @@ dependencies:
|
|
94
122
|
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '3.0'
|
97
|
-
description:
|
125
|
+
description:
|
98
126
|
email:
|
99
127
|
- cabeer@stanford.edu
|
100
128
|
executables: []
|
101
129
|
extensions: []
|
102
130
|
extra_rdoc_files: []
|
103
131
|
files:
|
132
|
+
- ".github/workflows/ruby.yml"
|
104
133
|
- ".gitignore"
|
105
134
|
- ".rspec"
|
106
|
-
- ".travis.yml"
|
107
135
|
- CODE_OF_CONDUCT.md
|
108
136
|
- Gemfile
|
109
137
|
- README.md
|
@@ -116,10 +144,10 @@ files:
|
|
116
144
|
- lib/purl_fetcher/client/reader.rb
|
117
145
|
- lib/purl_fetcher/client/version.rb
|
118
146
|
- purl_fetcher-client.gemspec
|
119
|
-
homepage:
|
147
|
+
homepage:
|
120
148
|
licenses: []
|
121
149
|
metadata: {}
|
122
|
-
post_install_message:
|
150
|
+
post_install_message:
|
123
151
|
rdoc_options: []
|
124
152
|
require_paths:
|
125
153
|
- lib
|
@@ -134,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
162
|
- !ruby/object:Gem::Version
|
135
163
|
version: '0'
|
136
164
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
-
signing_key:
|
165
|
+
rubygems_version: 3.2.3
|
166
|
+
signing_key:
|
139
167
|
specification_version: 4
|
140
168
|
summary: Traject-compatible reader implementation for streaming data from purl-fetcher
|
141
169
|
test_files: []
|