qa 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8158fccc9df38a91d74c1dbda277ce9308cf08c3
4
- data.tar.gz: 28be737c24fc1cdd77fed1fc5da6216c68b675fd
3
+ metadata.gz: 69b198054c52dafc00d9cf83f2f61b5fdc3e55cb
4
+ data.tar.gz: 00aa3d111681efe0a1c068846190e41531155e21
5
5
  SHA512:
6
- metadata.gz: d8e1fdedaa020bf6ffcac6bf1248729439d758be0966bb397aeaf05c54c681fd0f4f5e5c061e9b5ece5f8b8c9dc0494c6d1c9091c2f691e185256cb1cc42ec18
7
- data.tar.gz: 49e4402ab1422fee3e78cc7fdf485175144642b26fc6697a64873877fbbdc6095ad011881e8c42a35c9fb21c5704a056443f0ce6bc7e26c14494c958007d6434
6
+ metadata.gz: c75338fdecba820602eb3c669065679a87387e80bf65e350fdc42d6224dc5eb152439198257b6da3eb38812a9e44e6764472fa3a8fff3f554e782b13da0e4c38
7
+ data.tar.gz: bcf795d36f8fc600dbc672d9884b4b37efd084ad9e12a7e53583b491cf122b1247f8335fdcfe216cfda6b2c3c326628ac27f2b6a375aa44feb783daf8ce0f2b5
@@ -55,6 +55,28 @@ module Qa::Authorities
55
55
  "http://id.loc.gov/ontologies/bibframe/Role"
56
56
  end
57
57
 
58
+ def format(tc)
59
+ return 'json' unless tc.params.key?('format')
60
+ return 'json' if tc.params['format'].blank?
61
+ tc.params['format']
62
+ end
63
+
64
+ def jsonld?(tc)
65
+ format(tc).casecmp?('jsonld')
66
+ end
67
+
68
+ def n3?(tc)
69
+ format(tc).casecmp?('n3')
70
+ end
71
+
72
+ def ntriples?(tc)
73
+ format(tc).casecmp?('ntriples')
74
+ end
75
+
76
+ def graph_format?(tc)
77
+ jsonld?(tc) || n3?(tc) || ntriples?(tc)
78
+ end
79
+
58
80
  def discogs_genres
59
81
  DISCOGS_GENRE_MAPPING
60
82
  end
@@ -63,6 +85,19 @@ module Qa::Authorities
63
85
  DISCOGS_FORMATS_MAPPING
64
86
  end
65
87
 
88
+ # @param json results
89
+ # @param json results
90
+ # @return [String] status information
91
+ def check_for_msg_response(release_resp, master_resp)
92
+ if release_resp.key?("message") && master_resp.key?("message")
93
+ "no responses"
94
+ elsif !release_resp.key?("message") && !master_resp.key?("message")
95
+ "two responses"
96
+ else
97
+ "mixed"
98
+ end
99
+ end
100
+
66
101
  # both the work and the instance require a statement for the release year
67
102
  # @param [Hash] the http response from discogs
68
103
  # @return [Array] rdf statements
@@ -4,6 +4,7 @@ module Qa::Authorities
4
4
  class Discogs::GenericAuthority < Base
5
5
  include WebServiceBase
6
6
  include Discogs::DiscogsTranslation
7
+ include Discogs::DiscogsUtils
7
8
 
8
9
  class_attribute :discogs_secret, :discogs_key
9
10
  attr_accessor :primary_artists, :selected_format, :work_uri, :instance_uri
@@ -28,7 +29,14 @@ module Qa::Authorities
28
29
  Rails.logger.error "Questioning Authority tried to call Discogs, but no secret and/or key were set."
29
30
  return []
30
31
  end
31
- parse_authority_response(json(build_query_url(q, tc.params["subauthority"])))
32
+ response = json(build_query_url(q, tc))
33
+ if tc.params["response_header"] == "true"
34
+ response_hash = {}
35
+ response_hash["results"] = parse_authority_response(response)
36
+ response_hash["response_header"] = build_response_header(response)
37
+ return response_hash
38
+ end
39
+ parse_authority_response(response)
32
40
  end
33
41
 
34
42
  # If the subauthority = "all" (though it shouldn't), call the fetch_discogs_results method to determine
@@ -52,9 +60,18 @@ module Qa::Authorities
52
60
  # @param [String] the query
53
61
  # @param [String] the subauthority
54
62
  # @return [String] the url
55
- def build_query_url(q, subauthority)
63
+ def build_query_url(q, tc)
64
+ page = nil
65
+ per_page = nil
66
+ if tc.params["startRecord"].present?
67
+ page = (tc.params["startRecord"].to_i - 1) / tc.params["maxRecords"].to_i + 1
68
+ per_page = tc.params["maxRecords"]
69
+ else
70
+ page = tc.params["page"]
71
+ per_page = tc.params["per_page"]
72
+ end
56
73
  escaped_q = ERB::Util.url_encode(q)
57
- "https://api.discogs.com/database/search?q=#{escaped_q}&type=#{subauthority}&key=#{discogs_key}&secret=#{discogs_secret}"
74
+ "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}"
58
75
  end
59
76
 
60
77
  # @param [String] the id of the selected item
@@ -86,19 +103,6 @@ module Qa::Authorities
86
103
  release_resp
87
104
  end
88
105
 
89
- # @param json results
90
- # @param json results
91
- # @return [String] status information
92
- def check_for_msg_response(release_resp, master_resp)
93
- if release_resp.key?("message") && master_resp.key?("message")
94
- "no responses"
95
- elsif !release_resp.key?("message") && !master_resp.key?("message")
96
- "two responses"
97
- else
98
- "mixed"
99
- end
100
- end
101
-
102
106
  # @param [Hash] the http response from discogs
103
107
  # @example returns parsed discogs data with context
104
108
  # [{
@@ -131,6 +135,19 @@ module Qa::Authorities
131
135
  end
132
136
  end
133
137
 
138
+ # @param [Hash] the http response from discogs
139
+ # @param [Class] QA::TermsController
140
+ # @example returns parsed discogs pagination data
141
+ def build_response_header(response)
142
+ start_record = (response['pagination']['page'] - 1) * response['pagination']['per_page'] + 1
143
+ rh_hash = {}
144
+ rh_hash['start_record'] = start_record
145
+ rh_hash['requested_records'] = response['pagination']['per_page']
146
+ rh_hash['retrieved_records'] = response['results'].length
147
+ rh_hash['total_records'] = response['pagination']['items']
148
+ rh_hash
149
+ end
150
+
134
151
  # @param [Hash] the results hash from the JSON returned by Discogs
135
152
  def build_uri(result)
136
153
  result['uri'].present? ? "https://www.discogs.com" + result['uri'].to_s : result['resource_url'].to_s
@@ -156,27 +173,5 @@ module Qa::Authorities
156
173
  def get_context_for_array(item)
157
174
  item.present? ? item : [""]
158
175
  end
159
-
160
- def format(tc)
161
- return 'json' unless tc.params.key?('format')
162
- return 'json' if tc.params['format'].blank?
163
- tc.params['format']
164
- end
165
-
166
- def jsonld?(tc)
167
- format(tc).casecmp?('jsonld')
168
- end
169
-
170
- def n3?(tc)
171
- format(tc).casecmp?('n3')
172
- end
173
-
174
- def ntriples?(tc)
175
- format(tc).casecmp?('ntriples')
176
- end
177
-
178
- def graph_format?(tc)
179
- jsonld?(tc) || n3?(tc) || ntriples?(tc)
180
- end
181
176
  end
182
177
  end
@@ -1,3 +1,3 @@
1
1
  module Qa
2
- VERSION = "5.1.0".freeze
2
+ VERSION = "5.2.0".freeze
3
3
  end
@@ -0,0 +1 @@
1
+ {"pagination": {"per_page": 10, "pages": 2, "page": 1, "urls": {"last": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=10&type=master&page=2", "next": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=10&type=master&page=2"}, "items": 17}, "results": [{"style": ["Acoustic", "Soft Rock"], "thumb": "https://img.discogs.com/PDVaKISZBGLJnTkHxLdacDZx8AY=/fit-in/150x150/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/R-2304876-1521522385-7719.jpeg.jpg", "format": ["CD", "Album"], "country": "US", "barcode": ["0 7464-46038-2", "1A CK46038 01 B", "1A CK46038 10 B1", "CMU P 112"], "uri": "/James-Taylor-New-Moon-Shine/master/297372", "master_url": "https://api.discogs.com/masters/297372", "label": ["Columbia", "Skyline Studios", "Power Station", "A&M Studios", "Studio F", "Skyline Studios", "Sterling Sound"], "genre": ["Rock"], "catno": "CK 46038", "community": {"want": 224, "have": 761}, "year": "1991", "cover_image": "https://img.discogs.com/cr-KOWrcvF8_3z6kx3go4ikTOcw=/fit-in/600x597/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-2304876-1521522385-7719.jpeg.jpg", "title": "James Taylor (2) - New Moon Shine", "resource_url": "https://api.discogs.com/masters/297372", "master_id": 297372, "type": "master", "id": 297372}, {"id": 123}, {"id":234},{"id":345},{"id": 456}, {"id": 567}, {"id": 678}, {"id": 789}, {"id": 890}, {"id": 901}]}
@@ -0,0 +1 @@
1
+ {"pagination": {"per_page": 5, "pages": 4, "page": 4, "urls": {"prev": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=5&type=master&page=3", "first": "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&secret=yNSnBqrCDUYmwfMheZdtdCDuaUgQRJTn&key=bXDsQzXjWPxUowNRUoxq&per_page=5&type=master&page=1"}, "items": 17}, "results": [{"style": ["Big Band"], "thumb": "https://img.discogs.com/discogs-images/R-5420943-1507027002-2700.jpeg.jpg", "format": ["CD", "Compilation", "Limited Edition", "Box Set"], "country": "US", "barcode": [], "uri": "/Stan-Kenton-The-Complete-Capitol-Studio-Recordings-Of-Stan-Kenton-1943-47/master/866349", "master_url": "https://api.discogs.com/masters/866349", "label": ["Mosaic Records", "CEMA Special Markets"], "genre": ["Jazz"], "catno": "MD7-163", "community": {"want": 36, "have": 70}, "year": "1995", "cover_image": "https://img.discogs.com/2700.jpeg.jpg", "title": "Stan Kenton - The Complete Capitol Studio Recordings Of Stan Kenton 1943-47", "resource_url": "https://api.discogs.com/masters/866349", "master_id": 866349, "type": "master", "id": 866349}, {"style": ["Prog Rock", "Classic Rock"], "thumb": "https://img.discogs.com/discogs-images/R-1570546-1229281515.jpeg.jpg", "format": ["CD", "Album", "Reissue", "Remastered", "Box Set", "Compilation"], "country": "Europe", "uri": "/Pink-Floyd-Oh-By-The-Way/master/437149", "master_url": "https://api.discogs.com/masters/437149", "label": ["EMI", "EMI", "EMI", "EMI"], "genre": ["Rock", "Pop"], "catno": "50999 511267 2 8", "community": {"want": 0, "have": 0}, "year": "2007", "cover_image": "https://img.discogs.com/discogs-images/R-1570546-1229281515.jpeg.jpg", "title": "Pink Floyd - Oh By The Way", "resource_url": "https://api.discogs.com/masters/437149", "master_id": 437149, "type": "master", "id": 437149}]}
@@ -9,8 +9,26 @@ describe Qa::Authorities::Discogs::GenericAuthority do
9
9
  let(:authority) { described_class.new "all" }
10
10
 
11
11
  describe "#build_query_url" do
12
- subject { authority.build_query_url("foo", 'master') }
13
- it { is_expected.to eq 'https://api.discogs.com/database/search?q=foo&type=master&key=dummy_key&secret=dummy_secret' }
12
+ context "build_query_url startRecord" do
13
+ subject { authority.build_query_url("foo", tc) }
14
+ let(:tc) { instance_double(Qa::TermsController) }
15
+ before do
16
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
17
+ allow(tc).to receive(:params).and_return('startRecord' => "16", 'maxRecords' => "5", 'subauthority' => "master")
18
+ end
19
+
20
+ it { is_expected.to eq 'https://api.discogs.com/database/search?q=foo&type=master&page=4&per_page=5&key=dummy_key&secret=dummy_secret' }
21
+ end
22
+ context "build_query_url per_page" do
23
+ subject { authority.build_query_url("foo", tc) }
24
+ let(:tc) { instance_double(Qa::TermsController) }
25
+ before do
26
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
27
+ allow(tc).to receive(:params).and_return('page' => "1", 'per_page' => "10", 'subauthority' => "master")
28
+ end
29
+
30
+ 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
+ end
14
32
  end
15
33
 
16
34
  describe "#find_url" do
@@ -263,7 +281,7 @@ describe Qa::Authorities::Discogs::GenericAuthority do
263
281
  context "with subauthority all" do
264
282
  let(:tc) { instance_double(Qa::TermsController) }
265
283
  let :results do
266
- stub_request(:get, "https://api.discogs.com/database/search?q=melody+gardot+who+will+comfort+me+over+the+rainbo&type=all&key=dummy_key&secret=dummy_secret")
284
+ stub_request(:get, "https://api.discogs.com/database/search?q=melody+gardot+who+will+comfort+me+over+the+rainbo&type=all&page=&per_page=&key=dummy_key&secret=dummy_secret")
267
285
  .to_return(status: 200, body: webmock_fixture("discogs-search-response-no-subauth.json"))
268
286
  authority.search("melody gardot who will comfort me over the rainbo", tc)
269
287
  end
@@ -286,7 +304,7 @@ describe Qa::Authorities::Discogs::GenericAuthority do
286
304
  context "with subauthority master" do
287
305
  let(:tc) { instance_double(Qa::TermsController) }
288
306
  let :results do
289
- stub_request(:get, "https://api.discogs.com/database/search?q=wes+montgomery+tequila+bumpin'+on+sunse&type=master&key=dummy_key&secret=dummy_secret")
307
+ stub_request(:get, "https://api.discogs.com/database/search?q=wes+montgomery+tequila+bumpin'+on+sunse&type=master&page=&per_page=&key=dummy_key&secret=dummy_secret")
290
308
  .to_return(status: 200, body: webmock_fixture("discogs-search-response-subauth.json"))
291
309
  authority.search("wes montgomery tequila bumpin' on sunse", tc)
292
310
  end
@@ -305,6 +323,46 @@ describe Qa::Authorities::Discogs::GenericAuthority do
305
323
  end
306
324
  end
307
325
 
326
+ context "with setRecord and maxRecords" do
327
+ let(:tc) { instance_double(Qa::TermsController) }
328
+ let :results do
329
+ stub_request(:get, "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&type=master&page=4&per_page=5&key=dummy_key&secret=dummy_secret")
330
+ .to_return(status: 200, body: webmock_fixture("discogs-search-response-set-record.json"))
331
+ authority.search("james taylor new moon shine", tc)
332
+ end
333
+ before do
334
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
335
+ allow(tc).to receive(:params).and_return('subauthority' => "master", 'startRecord' => 16, 'maxRecords' => 5, 'response_header' => 'true')
336
+ end
337
+
338
+ it "has id and label keys" do
339
+ expect(results['response_header']['start_record']).to eq 16
340
+ expect(results['response_header']['requested_records']).to eq 5
341
+ expect(results['response_header']['retrieved_records']).to eq 2
342
+ expect(results['response_header']['total_records']).to eq 17
343
+ end
344
+ end
345
+
346
+ context "with page and per_page" do
347
+ let(:tc) { instance_double(Qa::TermsController) }
348
+ let :results do
349
+ stub_request(:get, "https://api.discogs.com/database/search?q=james+taylor+new+moon+shine&type=master&page=1&per_page=10&key=dummy_key&secret=dummy_secret")
350
+ .to_return(status: 200, body: webmock_fixture("discogs-search-response-per-page.json"))
351
+ authority.search("james taylor new moon shine", tc)
352
+ end
353
+ before do
354
+ allow(Qa::TermsController).to receive(:new).and_return(tc)
355
+ allow(tc).to receive(:params).and_return('subauthority' => "master", 'page' => 1, 'per_page' => 10, 'response_header' => 'true')
356
+ end
357
+
358
+ it "has id and label keys" do
359
+ expect(results['response_header']['start_record']).to eq 1
360
+ expect(results['response_header']['requested_records']).to eq 10
361
+ expect(results['response_header']['retrieved_records']).to eq 10
362
+ expect(results['response_header']['total_records']).to eq 17
363
+ end
364
+ end
365
+
308
366
  context "when authentication isn't set" do
309
367
  let(:tc) { instance_double(Qa::TermsController) }
310
368
  let :results do
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.1.0
4
+ version: 5.2.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: 2019-11-22 00:00:00.000000000 Z
19
+ date: 2019-12-03 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activerecord-import
@@ -92,16 +92,22 @@ dependencies:
92
92
  name: rails
93
93
  requirement: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '5.0'
98
+ - - "<"
99
+ - !ruby/object:Gem::Version
100
+ version: '6.1'
98
101
  type: :runtime
99
102
  prerelease: false
100
103
  version_requirements: !ruby/object:Gem::Requirement
101
104
  requirements:
102
- - - "~>"
105
+ - - ">="
103
106
  - !ruby/object:Gem::Version
104
107
  version: '5.0'
108
+ - - "<"
109
+ - !ruby/object:Gem::Version
110
+ version: '6.1'
105
111
  - !ruby/object:Gem::Dependency
106
112
  name: rdf
107
113
  requirement: !ruby/object:Gem::Requirement
@@ -455,6 +461,8 @@ files:
455
461
  - spec/fixtures/discogs-id-not-found-release.json
456
462
  - spec/fixtures/discogs-search-response-no-auth.json
457
463
  - spec/fixtures/discogs-search-response-no-subauth.json
464
+ - spec/fixtures/discogs-search-response-per-page.json
465
+ - spec/fixtures/discogs-search-response-set-record.json
458
466
  - spec/fixtures/discogs-search-response-subauth.json
459
467
  - spec/fixtures/funders-find-response.json
460
468
  - spec/fixtures/funders-noquery.json
@@ -633,6 +641,7 @@ test_files:
633
641
  - spec/lib/services/rdf_authority_parser_spec.rb
634
642
  - spec/fixtures/lod_lang_search_enesfrde.rdf.xml
635
643
  - spec/fixtures/oclcts-response-mesh-3.txt
644
+ - spec/fixtures/discogs-search-response-set-record.json
636
645
  - spec/fixtures/loc-names-response.txt
637
646
  - spec/fixtures/oclcts-response-mesh-2.txt
638
647
  - spec/fixtures/lod_loc_term_bad_id.rdf.xml
@@ -653,6 +662,7 @@ test_files:
653
662
  - spec/fixtures/getty-aat-find-response.json
654
663
  - spec/fixtures/lod_lang_term_enfr_noalt.rdf.xml
655
664
  - spec/fixtures/assign-fast-noresults.json
665
+ - spec/fixtures/discogs-search-response-per-page.json
656
666
  - spec/fixtures/getty-error-response.txt
657
667
  - spec/fixtures/lod_loc_term_found.rdf.xml
658
668
  - spec/fixtures/lod_lang_term_enfr.rdf.xml