qa 5.15.0 → 5.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11cbb13006d50dd1457c8782b84f49a677717302d43a3978e3629670ac9ec433
4
- data.tar.gz: 72c2de2f8114cc9df223ef68eeac9f3ff9046a74c87dd93103a3461d24c2c15e
3
+ metadata.gz: 16eaf3a1b00dfb3b3063af78f2065ebd16b254fe5d97c55bc27c6255e41c5946
4
+ data.tar.gz: 50dc8f8818c16b2ccfcfa0dfb79b74ebb1d7032ca1cd389ac4d181e885ca0db1
5
5
  SHA512:
6
- metadata.gz: 30f799610d3d6980f0e33d3b5fcb2364e9c0019c18f8a12f5474dd22a82ccb865f95cc5f4d49da70df2246fda033ab17ea20dd3da554c220b881841d2a64c1bf
7
- data.tar.gz: cc3c22f2e7cb940eff5f7f3d398090ae2caaff78840a81eff1ea9e229d1db2c2a17673617e0cd12fd9aef1a6ffa30128accf66cf8eaa1537b0df901e1847ceac
6
+ metadata.gz: ee41c3074ee5172e3e4455afa5a1a7858e61894140642e45d6c3efddca298cd46749f9eed04a9446bc287965497dbab715167e682821a85e37aba97a0e36e71b
7
+ data.tar.gz: 6412e3a3843ee1984797299d22cac8c6e8f9ac19f544b8b85c530db4a67c8826811f416fb546d633467736b1070bc86068fde65db7c48e939e9cba12d6956f65
@@ -433,7 +433,7 @@ module Qa
433
433
  # linked_data module pagination).
434
434
  def requested_page_offset
435
435
  return @requested_page_offset if @requested_page_offset.present?
436
- @requested_page_offset = (request_params['page_offset'] || request_params['startRecord'])
436
+ @requested_page_offset = request_params['page_offset'] || request_params['startRecord']
437
437
  end
438
438
 
439
439
  # @return [Integer] The first record to include in the response data as
@@ -470,7 +470,7 @@ module Qa
470
470
  # linked_data module pagination).
471
471
  def requested_page_limit
472
472
  return @requested_page_limit if @requested_page_limit.present?
473
- @requested_page_limit ||= (request_params['page_limit'] || request_params['maxRecords'])
473
+ @requested_page_limit ||= request_params['page_limit'] || request_params['maxRecords']
474
474
  end
475
475
 
476
476
  # @return [Integer] The max number of records to include in response data as
@@ -0,0 +1,6 @@
1
+ {
2
+ "term": { },
3
+ "search": {
4
+ "urls" : { "getty_vocab_url": "https://vocab.getty.edu" }
5
+ }
6
+ }
@@ -11,7 +11,7 @@ This generator makes the following changes to your application:
11
11
  def add_to_gemfile
12
12
  gem 'swagger-docs'
13
13
 
14
- Bundler.with_clean_env do
14
+ Bundler.with_unbundled_env do
15
15
  run "bundle install"
16
16
  end
17
17
  end
@@ -1,13 +1,11 @@
1
1
  module Qa::Authorities
2
2
  # for use with Faraday; encode spaces as '%20' not '+'
3
3
  class AssignFast::SpaceFixEncoder
4
+ delegate :decode, to: Faraday::NestedParamsEncoder
5
+
4
6
  def encode(hash)
5
7
  encoded = Faraday::NestedParamsEncoder.encode(hash)
6
8
  encoded.gsub('+', '%20')
7
9
  end
8
-
9
- def decode(str)
10
- Faraday::NestedParamsEncoder.decode(str)
11
- end
12
10
  end
13
11
  end
@@ -1,12 +1,15 @@
1
1
  require 'rdf'
2
2
  require 'rdf/ntriples'
3
+ require 'net/http'
4
+ require 'json'
5
+
3
6
  module Qa::Authorities
4
7
  class Discogs::GenericAuthority < Base
5
8
  include WebServiceBase
6
9
  include Discogs::DiscogsTranslation
7
10
  include Discogs::DiscogsUtils
8
11
 
9
- class_attribute :discogs_secret, :discogs_key
12
+ class_attribute :discogs_secret, :discogs_key, :discogs_user_token
10
13
  attr_accessor :primary_artists, :selected_format, :work_uri, :instance_uri
11
14
 
12
15
  # @param [String] subauthority to use
@@ -26,8 +29,8 @@ module Qa::Authorities
26
29
  # physical or digital object and a master represents a set of similar releases. Use of a
27
30
  # subauthority (e.g., /qa/search/discogs/master) will target a specific type. Using the "all"
28
31
  # subauthority will search for both types.
29
- unless discogs_key && discogs_secret
30
- Rails.logger.error "Questioning Authority tried to call Discogs, but no secret and/or key were set."
32
+ unless discogs_user_token.present? || (discogs_key && discogs_secret)
33
+ Rails.logger.error "Questioning Authority tried to call Discogs, but no user token, secret and/or key were set."
31
34
  return []
32
35
  end
33
36
  response = json(build_query_url(q, tc))
@@ -72,7 +75,9 @@ module Qa::Authorities
72
75
  per_page = tc.params["per_page"]
73
76
  end
74
77
  escaped_q = ERB::Util.url_encode(q)
75
- "https://api.discogs.com/database/search?q=#{escaped_q}&type=#{tc.params['subauthority']}&page=#{page}&per_page=#{per_page}&key=#{discogs_key}&secret=#{discogs_secret}"
78
+ url = "https://api.discogs.com/database/search?q=#{escaped_q}&type=#{tc.params['subauthority']}&page=#{page}&per_page=#{per_page}"
79
+ url += "&key=#{discogs_key}&secret=#{discogs_secret}" if discogs_user_token.blank?
80
+ url
76
81
  end
77
82
 
78
83
  # @param [String] the id of the selected item
@@ -82,6 +87,23 @@ module Qa::Authorities
82
87
  "https://api.discogs.com/#{subauthority}s/#{id}"
83
88
  end
84
89
 
90
+ def json(url)
91
+ if discogs_user_token.present?
92
+ uri = URI(url)
93
+ http = Net::HTTP.new(uri.host, uri.port)
94
+ http.use_ssl = true
95
+
96
+ request = Net::HTTP::Get.new(uri)
97
+ request['Authorization'] = "Discogs token=#{discogs_user_token}"
98
+ request['User-Agent'] = 'HykuApp/1.0'
99
+
100
+ response = http.request(request)
101
+ JSON.parse(response.body)
102
+ else
103
+ super
104
+ end
105
+ end
106
+
85
107
  private
86
108
 
87
109
  # In the unusual case that we have an id and the subauthority is "all", we don't know which Discogs url to
@@ -7,7 +7,7 @@ module Qa::Authorities
7
7
  end
8
8
 
9
9
  def build_query_url(q)
10
- "http://vocab.getty.edu/sparql.json?query=#{ERB::Util.url_encode(sparql(q))}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
10
+ "#{getty_vocab_url}/sparql.json?query=#{ERB::Util.url_encode(sparql(q))}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
11
11
  end
12
12
 
13
13
  def sparql(q) # rubocop:disable Metrics/MethodLength
@@ -38,7 +38,7 @@ module Qa::Authorities
38
38
  end
39
39
 
40
40
  def find_url(id)
41
- "http://vocab.getty.edu/download/json?uri=http://vocab.getty.edu/aat/#{id}.json"
41
+ "#{getty_vocab_url}/download/json?uri=#{getty_vocab_url}/aat/#{id}.json"
42
42
  end
43
43
 
44
44
  def request_options
@@ -58,5 +58,13 @@ module Qa::Authorities
58
58
  Rails.logger.warn " ERROR fetching Getty response: #{e.message}; cause: #{cause}"
59
59
  {}
60
60
  end
61
+
62
+ def linked_data_authority_configs
63
+ Qa.config.linked_data_authority_configs
64
+ end
65
+
66
+ def getty_vocab_url
67
+ @getty_vocab_url ||= linked_data_authority_configs.dig(:GETTY_AAC, :search, :urls, :getty_vocab_url) || 'https://vocab.getty.edu'
68
+ end
61
69
  end
62
70
  end
@@ -179,7 +179,7 @@ module Qa::Authorities
179
179
  end
180
180
 
181
181
  def wrap_labels(labels)
182
- lbl = "" if labels.nil? || labels.size.zero?
182
+ lbl = "" if labels.blank?
183
183
  lbl = labels.join(', ') if labels.size.positive?
184
184
  lbl = '[' + lbl + ']' if labels.size > 1
185
185
  lbl
@@ -22,7 +22,7 @@ module Qa::Authorities::LocSubauthority
22
22
  return "authorities" if authorities.include?(authority)
23
23
  return "vocabulary" if vocabularies.include?(authority)
24
24
  return "datatype" if datatypes.include?(authority)
25
- return "vocabulary/preservation" if preservation.include?(authority)
25
+ "vocabulary/preservation" if preservation.include?(authority)
26
26
  end
27
27
 
28
28
  def authorities
@@ -47,6 +47,7 @@ module Qa::Authorities::LocSubauthority
47
47
  "languages",
48
48
  "iso639-1",
49
49
  "iso639-2",
50
+ "iso639-3",
50
51
  "iso639-5",
51
52
  "preservation",
52
53
  "actionsGranted",
@@ -1,23 +1,17 @@
1
1
  module Qa::Authorities
2
2
  module Local
3
3
  class Registry
4
+ delegate :keys, :fetch, to: :@hash
5
+
4
6
  def initialize
5
7
  @hash = {}
6
8
  yield self if block_given?
7
9
  end
8
10
 
9
- def keys
10
- @hash.keys
11
- end
12
-
13
11
  def instance_for(key)
14
12
  fetch(key).instance
15
13
  end
16
14
 
17
- def fetch(key)
18
- @hash.fetch(key)
19
- end
20
-
21
15
  def self.logger
22
16
  @logger ||= ::Rails.logger if defined? Rails && Rails.respond_to?(:logger)
23
17
  end
data/lib/qa/engine.rb CHANGED
@@ -17,5 +17,12 @@ module Qa
17
17
  Rails.autoloaders.main.ignore(Rails.root.join('lib', 'generators'))
18
18
  end
19
19
  end
20
+
21
+ # Allow main application to configure deprecation behavior
22
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0')
23
+ initializer "qa.deprecator" do |app|
24
+ app.deprecators[:qa] = Qa.deprecator
25
+ end
26
+ end
20
27
  end
21
28
  end
data/lib/qa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "5.15.0".freeze
2
+ VERSION = "5.17.0".freeze
3
3
  end
data/lib/qa.rb CHANGED
@@ -25,10 +25,22 @@ module Qa
25
25
  @config
26
26
  end
27
27
 
28
+ def self.deprecator
29
+ @deprecator ||= deprecator_instance
30
+ end
31
+
32
+ # TODO: refactor when support for Rails < 7.1.0 is dropped
33
+ def self.deprecator_instance
34
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0')
35
+ ActiveSupport::Deprecation.new("6.0.0", "Qa")
36
+ else
37
+ Rails.logger
38
+ end
39
+ end
40
+
28
41
  def self.deprecation_warning(in_msg: nil, msg:)
29
- return if Rails.env == 'test'
30
42
  in_msg = in_msg.present? ? "In #{in_msg}, " : ''
31
- warn "[DEPRECATED] #{in_msg}#{msg} It will be removed in the next major release."
43
+ deprecator.warn "#{in_msg}#{msg} It will be removed in the next major release."
32
44
  end
33
45
 
34
46
  # Raised when the authority is not valid
data/lib/tasks/mesh.rake CHANGED
@@ -1,9 +1,9 @@
1
- require 'benchmark'
2
-
3
1
  namespace :qa do
4
2
  namespace :mesh do
5
3
  desc "Import MeSH terms from the file $MESH_FILE, it will update any terms which are already in the database"
6
4
  task import: :environment do
5
+ require 'benchmark' # may require you to add benchmark dependency in ruby 4+
6
+
7
7
  fname = ENV['MESH_FILE']
8
8
  if fname.nil?
9
9
  puts "Need to set $MESH_FILE with path to file to ingest"
@@ -32,7 +32,7 @@ describe Qa::TermsController, type: :controller do
32
32
  msg = "Unable to initialize sub-authority non-existent-subauthority for Qa::Authorities::Loc. Valid sub-authorities are " \
33
33
  "[\"subjects\", \"names\", \"classification\", \"childrensSubjects\", \"genreForms\", \"performanceMediums\", " \
34
34
  "\"graphicMaterials\", \"organizations\", \"relators\", \"countries\", \"ethnographicTerms\", \"geographicAreas\", " \
35
- "\"languages\", \"iso639-1\", \"iso639-2\", \"iso639-5\", \"preservation\", \"actionsGranted\", \"agentType\", " \
35
+ "\"languages\", \"iso639-1\", \"iso639-2\", \"iso639-3\", \"iso639-5\", \"preservation\", \"actionsGranted\", \"agentType\", " \
36
36
  "\"edtf\", \"contentLocationType\", \"copyrightStatus\", \"cryptographicHashFunctions\", " \
37
37
  "\"environmentCharacteristic\", \"environmentPurpose\", \"eventRelatedAgentRole\", \"eventRelatedObjectRole\", " \
38
38
  "\"eventType\", \"formatRegistryRole\", \"hardwareType\", \"inhibitorTarget\", \"inhibitorType\", \"objectCategory\", " \
@@ -4,6 +4,7 @@ describe Qa::Authorities::Discogs::GenericAuthority do
4
4
  before do
5
5
  described_class.discogs_key = 'dummy_key'
6
6
  described_class.discogs_secret = 'dummy_secret'
7
+ described_class.discogs_user_token = nil
7
8
  end
8
9
 
9
10
  let(:authority) { described_class.new "all" }
@@ -29,6 +30,18 @@ describe Qa::Authorities::Discogs::GenericAuthority do
29
30
 
30
31
  it { is_expected.to eq 'https://api.discogs.com/database/search?q=foo&type=master&page=1&per_page=10&key=dummy_key&secret=dummy_secret' }
31
32
  end
33
+
34
+ context "with a user token" do
35
+ subject { authority.build_query_url("foo", tc) }
36
+ let(:tc) { instance_double(Qa::TermsController) }
37
+ before do
38
+ described_class.discogs_user_token = 'dummy_token'
39
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
40
+ allow(tc).to receive(:params).and_return('page' => "1", 'per_page' => "10", 'subauthority' => "master")
41
+ end
42
+
43
+ it { is_expected.to eq 'https://api.discogs.com/database/search?q=foo&type=master&page=1&per_page=10' }
44
+ end
32
45
  end
33
46
 
34
47
  describe "#find_url" do
@@ -363,6 +376,33 @@ describe Qa::Authorities::Discogs::GenericAuthority do
363
376
  end
364
377
  end
365
378
 
379
+ context "with user token authentication" do
380
+ let(:tc) { instance_double(Qa::TermsController) }
381
+ let :results do
382
+ described_class.discogs_user_token = 'dummy_token'
383
+ described_class.discogs_key = nil
384
+ described_class.discogs_secret = nil
385
+ stub_request(:get, "https://api.discogs.com/database/search?q=melody+gardot&type=all&page=&per_page=")
386
+ .with(
387
+ headers: {
388
+ 'Authorization' => 'Discogs token=dummy_token',
389
+ 'User-Agent' => 'HykuApp/1.0'
390
+ }
391
+ )
392
+ .to_return(status: 200, body: webmock_fixture("discogs-search-response-no-subauth.json"))
393
+ authority.search("melody gardot", tc)
394
+ end
395
+ before do
396
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
397
+ allow(tc).to receive(:params).and_return('subauthority' => "all")
398
+ end
399
+
400
+ it "has id and label keys" do
401
+ expect(results.first["uri"]).to eq("https://www.discogs.com/Melody-Gardot-Who-Will-Comfort-Me-Over-The-Rainbow/release/1750352")
402
+ expect(results.first["id"]).to eq "1750352"
403
+ end
404
+ end
405
+
366
406
  context "when authentication isn't set" do
367
407
  let(:tc) { instance_double(Qa::TermsController) }
368
408
  let :results do
@@ -373,12 +413,13 @@ describe Qa::Authorities::Discogs::GenericAuthority do
373
413
  before do
374
414
  described_class.discogs_secret = nil
375
415
  described_class.discogs_key = nil
416
+ described_class.discogs_user_token = nil
376
417
  allow(Qa::TermsController).to receive(:new).and_return(tc)
377
418
  allow(tc).to receive(:params).and_return('subauthority' => "master")
378
419
  end
379
420
 
380
421
  it "logs an error" do
381
- expect(Rails.logger).to receive(:error).with('Questioning Authority tried to call Discogs, but no secret and/or key were set.')
422
+ expect(Rails.logger).to receive(:error).with('Questioning Authority tried to call Discogs, but no user token, secret and/or key were set.')
382
423
  expect(results).to be_empty
383
424
  end
384
425
  end
@@ -5,12 +5,12 @@ describe Qa::Authorities::Getty::AAT do
5
5
 
6
6
  describe "#build_query_url" do
7
7
  subject { authority.build_query_url("foo") }
8
- it { is_expected.to match(/^http:\/\/vocab\.getty\.edu\//) }
8
+ it { is_expected.to match(/^https:\/\/vocab\.getty\.edu\//) }
9
9
  end
10
10
 
11
11
  describe "#find_url" do
12
12
  subject { authority.find_url("300053264") }
13
- it { is_expected.to eq "http://vocab.getty.edu/download/json?uri=http://vocab.getty.edu/aat/300053264.json" }
13
+ it { is_expected.to eq "https://vocab.getty.edu/download/json?uri=https://vocab.getty.edu/aat/300053264.json" }
14
14
  end
15
15
 
16
16
  describe "#search" do
@@ -62,7 +62,7 @@ describe Qa::Authorities::Getty::AAT do
62
62
  describe "#find" do
63
63
  context "using a subject id" do
64
64
  before do
65
- stub_request(:get, "http://vocab.getty.edu/download/json?uri=http://vocab.getty.edu/aat/300265560.json")
65
+ stub_request(:get, "https://vocab.getty.edu/download/json?uri=https://vocab.getty.edu/aat/300265560.json")
66
66
  .to_return(status: 200, body: webmock_fixture("getty-aat-find-response.json"))
67
67
  end
68
68
  subject { authority.find("300265560") }
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Qa::LinkedData::AuthorityService do
4
4
  let(:auth_names) do
5
- [:LOC,
5
+ [:GETTY_AAC,
6
+ :LOC,
6
7
  :LOD_ENCODING_CONFIG,
7
8
  :LOD_FULL_CONFIG,
8
9
  :LOD_FULL_CONFIG_1_0,
@@ -74,8 +74,7 @@ RSpec.describe Qa::LinkedData::ResponseHeaderService do
74
74
 
75
75
  describe '#fetch_header' do
76
76
  let(:request_header) do
77
- {
78
- }.with_indifferent_access
77
+ {}.with_indifferent_access
79
78
  end
80
79
  let(:term_config) { double }
81
80
  let(:graph) { instance_double(RDF::Graph) }
data/spec/spec_helper.rb CHANGED
@@ -22,7 +22,11 @@ require 'pry'
22
22
  Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
23
23
 
24
24
  RSpec.configure do |config|
25
- config.fixture_path = File.expand_path("../fixtures", __FILE__)
25
+ if config.respond_to?(:fixture_paths=)
26
+ config.fixture_paths = [File.expand_path("../fixtures", __FILE__)]
27
+ else
28
+ config.fixture_path = File.expand_path("../fixtures", __FILE__)
29
+ end
26
30
 
27
31
  config.use_transactional_fixtures = true
28
32
 
@@ -26,4 +26,13 @@ group :development do
26
26
  gem 'concurrent-ruby', '1.3.4'
27
27
  end
28
28
 
29
+ # multi_json 1.19.x / json 2.19.x interaction causes
30
+ # RDF::Graph#dump(:jsonld, standard_prefixes: true) to raise:
31
+ # NoMethodError: undefined method `except' for JSON::Ext::Generator::State
32
+ # in e.g. lib/qa/authorities/linked_data/find_term.rb and
33
+ # lib/qa/authorities/discogs/discogs_translation.rb
34
+ if RUBY_VERSION =~ /^3\.[01]\./
35
+ gem "multi_json", ">= 1.17", "< 1.19"
36
+ end
37
+
29
38
  end
@@ -4,7 +4,7 @@ class TestAppGenerator < Rails::Generators::Base
4
4
  source_root Rails.root
5
5
 
6
6
  def update_app
7
- Bundler.with_clean_env do
7
+ Bundler.with_unbundled_env do
8
8
  run "bundle install"
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.15.0
4
+ version: 5.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Anderson
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2025-06-02 00:00:00.000000000 Z
19
+ date: 2026-06-22 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord-import
@@ -32,20 +32,6 @@ dependencies:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
- - !ruby/object:Gem::Dependency
36
- name: deprecation
37
- requirement: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- type: :runtime
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
35
  - !ruby/object:Gem::Dependency
50
36
  name: faraday
51
37
  requirement: !ruby/object:Gem::Requirement
@@ -114,20 +100,20 @@ dependencies:
114
100
  requirements:
115
101
  - - ">="
116
102
  - !ruby/object:Gem::Version
117
- version: '5.0'
103
+ version: '6.0'
118
104
  - - "<"
119
105
  - !ruby/object:Gem::Version
120
- version: '8.1'
106
+ version: '8.2'
121
107
  type: :runtime
122
108
  prerelease: false
123
109
  version_requirements: !ruby/object:Gem::Requirement
124
110
  requirements:
125
111
  - - ">="
126
112
  - !ruby/object:Gem::Version
127
- version: '5.0'
113
+ version: '6.0'
128
114
  - - "<"
129
115
  - !ruby/object:Gem::Version
130
- version: '8.1'
116
+ version: '8.2'
131
117
  - !ruby/object:Gem::Dependency
132
118
  name: rdf
133
119
  requirement: !ruby/object:Gem::Requirement
@@ -414,6 +400,7 @@ files:
414
400
  - app/views/layouts/qa/application.html.erb
415
401
  - config/authorities.yml
416
402
  - config/authorities/assign_fast/oclc_assign_fast.json
403
+ - config/authorities/linked_data/getty_aac.json
417
404
  - config/authorities/linked_data/loc.json
418
405
  - config/authorities/linked_data/oclc_fast.json
419
406
  - config/authorities/states.yml
@@ -476,7 +463,6 @@ files:
476
463
  - lib/qa/authorities/geonames.rb
477
464
  - lib/qa/authorities/getty.rb
478
465
  - lib/qa/authorities/getty/aat.rb
479
- - lib/qa/authorities/getty/aat2.rb
480
466
  - lib/qa/authorities/getty/tgn.rb
481
467
  - lib/qa/authorities/getty/ulan.rb
482
468
  - lib/qa/authorities/linked_data.rb
@@ -681,7 +667,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
681
667
  - !ruby/object:Gem::Version
682
668
  version: '0'
683
669
  requirements: []
684
- rubygems_version: 3.4.21
670
+ rubygems_version: 3.5.22
685
671
  signing_key:
686
672
  specification_version: 4
687
673
  summary: You should question your authorities.
@@ -1,62 +0,0 @@
1
- module Qa::Authorities
2
- class Getty::AAT2 < Base
3
- include WebServiceBase
4
-
5
- def search(q)
6
- parse_authority_response(json(build_query_url(q)))
7
- end
8
-
9
- def build_query_url(q)
10
- "http://vocab.getty.edu/sparql.json?query=#{ERB::Util.url_encode(sparql(q))}&_implicit=false&implicit=true&_equivalent=false&_form=%2Fsparql"
11
- end
12
-
13
- def sparql(q) # rubocop:disable Metrics/MethodLength
14
- search = untaint(q)
15
- if search.include?(' ')
16
- clauses = search.split(' ').collect do |i|
17
- %((regex(?name, "#{i}", "i")))
18
- end
19
- ex = "(#{clauses.join(' && ')})"
20
- else
21
- ex = %(regex(?name, "#{search}", "i"))
22
- end
23
- # The full text index matches on fields besides the term, so we filter to ensure the match is in the term.
24
- %(SELECT ?s ?name {
25
- ?s a skos:Concept; luc:term "#{search}";
26
- skos:inScheme <http://vocab.getty.edu/aat/> ;
27
- gvp:prefLabelGVP [skosxl:literalForm ?name].
28
- FILTER #{ex} .
29
- } ORDER BY ?name).gsub(/[\s\n]+/, " ")
30
- end
31
-
32
- def untaint(q)
33
- q.gsub(/[^\w\s-]/, '')
34
- end
35
-
36
- def find(id)
37
- json(find_url(id))
38
- end
39
-
40
- def find_url(id)
41
- "http://vocab.getty.edu/download/json?uri=http://vocab.getty.edu/aat/#{id}.json"
42
- end
43
-
44
- def request_options
45
- { accept: 'application/sparql-results+json' }
46
- end
47
-
48
- private
49
-
50
- # Reformats the data received from the Getty service
51
- def parse_authority_response(response)
52
- response['results']['bindings'].map do |result|
53
- { 'id' => result['s']['value'], 'label' => result['name']['value'] }
54
- end
55
- rescue StandardError => e
56
- cause = response.fetch('error', {}).fetch('cause', 'UNKNOWN')
57
- cause = cause.presence || 'UNKNOWN'
58
- Rails.logger.warn " ERROR fetching Getty response: #{e.message}; cause: #{cause}"
59
- {}
60
- end
61
- end
62
- end