qa 5.15.0 → 5.16.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: 72045748a59fdac5d424b0f6f0703e55282b3971380bc8c8288ccc66677d38d8
4
+ data.tar.gz: b03d37809c9d45a4c20b2b3dce9ce3a650fbb187580b21f6fdc956f549fef710
5
5
  SHA512:
6
- metadata.gz: 30f799610d3d6980f0e33d3b5fcb2364e9c0019c18f8a12f5474dd22a82ccb865f95cc5f4d49da70df2246fda033ab17ea20dd3da554c220b881841d2a64c1bf
7
- data.tar.gz: cc3c22f2e7cb940eff5f7f3d398090ae2caaff78840a81eff1ea9e229d1db2c2a17673617e0cd12fd9aef1a6ffa30128accf66cf8eaa1537b0df901e1847ceac
6
+ metadata.gz: be2bdd94bae283c15a285c3213be0d780053948da33da5e933cc790cdf3ba2fac4c343380b68b80853d2c0fd83aee7c15ed059372fe314af3094376df855b8d7
7
+ data.tar.gz: 85500cf3c3b1d1a86b002ec6ef748d70b91a0f021caec6ef6ba94861766b67035bfb926fcd59c9e6a6d67abf107c99bf5d0a475b64f122604a006d1386753b29
@@ -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
data/lib/qa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "5.15.0".freeze
2
+ VERSION = "5.16.0".freeze
3
3
  end
@@ -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
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
 
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.16.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: 2025-12-10 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord-import
@@ -114,20 +114,20 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '5.0'
117
+ version: '6.0'
118
118
  - - "<"
119
119
  - !ruby/object:Gem::Version
120
- version: '8.1'
120
+ version: '8.2'
121
121
  type: :runtime
122
122
  prerelease: false
123
123
  version_requirements: !ruby/object:Gem::Requirement
124
124
  requirements:
125
125
  - - ">="
126
126
  - !ruby/object:Gem::Version
127
- version: '5.0'
127
+ version: '6.0'
128
128
  - - "<"
129
129
  - !ruby/object:Gem::Version
130
- version: '8.1'
130
+ version: '8.2'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: rdf
133
133
  requirement: !ruby/object:Gem::Requirement