Skip to content

Commit

Permalink
Merge pull request #280 from samvera/discogs-context
Browse files Browse the repository at this point in the history
Issue 278: context should be an array, not a hash
  • Loading branch information
elrayle committed Nov 8, 2019
2 parents 281799b + 30e718d commit 559393b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
55 changes: 26 additions & 29 deletions lib/qa/authorities/discogs/generic_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,27 @@ def check_for_msg_response(release_resp, master_resp)

# @param [Hash] the http response from discogs
# @example returns parsed discogs data with context
# {
# "uri": "https://api.discogs.com/releases/4212473",
# "id": "4212473",
# "label": "Frank Sinatra And The Modernaires - Sorry / Why Remind Me",
# }
# "context": {
# "Image URL": [
# "https://img.discogs.com/2e-YoNr0dvmMgbzEN0hjHD6X0sU=/fit-in/600x580/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-4212473-1358693671-5430.jpeg.jpg"
# ],
# "Year": [
# "1950"
# ],
# "Record Labels": [
# "Columbia"
# ],
# "Formats": [
# "Shellac",
# "10\"",
# "78 RPM"
# ],
# "Type": [
# "release"
# ]
# }
# [{
# "uri": "https://www.discogs.com/Frank-Sinatra-And-The-Modernaires-Sorry-Why-Remind-Me/release/4212473",
# "id": "4212473",
# "label": "Frank Sinatra And The Modernaires - Sorry / Why Remind Me",
# "context": [{
# "property": "Image URL",
# "values": ["https://img.discogs.com/1358693671-5430.jpeg.jpg"]
# }, {
# "property": "Year",
# "values": ["1950"]
# }, {
# "property": "Record Labels",
# "values": ["Columbia"]
# }, {
# "property": "Formats",
# "values": ["Shellac", "10\"", "78 RPM"]
# }, {
# "property": "Type",
# "values": ["release"]
# }]
# }]
def parse_authority_response(response)
response['results'].map do |result|
{ 'uri' => build_uri(result),
Expand All @@ -141,11 +138,11 @@ def build_uri(result)

# @param [Hash] the results hash from the JSON returned by Discogs
def assemble_search_context(result)
{ "Image URL" => get_context_for_string(result['cover_image']),
"Year" => get_context_for_string(result['year']),
"Record Labels" => get_context_for_array(result['label']),
"Formats" => get_context_for_array(result['format']),
"Type" => get_context_for_string(result['type']) }
[{ "property" => "Image URL", "values" => get_context_for_string(result['cover_image']) },
{ "property" => "Year", "values" => get_context_for_string(result['year']) },
{ "property" => "Record Labels", "values" => get_context_for_array(result['label']) },
{ "property" => "Formats", "values" => get_context_for_array(result['format']) },
{ "property" => "Type", "values" => get_context_for_string(result['type']) }]
end

# checks if the param is null, returns appropriate value
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/authorities/discogs/generic_authority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@
expect(results.first["uri"]).to eq("https://www.discogs.com/Melody-Gardot-Who-Will-Comfort-Me-Over-The-Rainbow/release/1750352")
expect(results.first["id"]).to eq "1750352"
expect(results.first["label"]).to eq "Melody Gardot - Who Will Comfort Me / Over The Rainbow"
expect(results.first["context"]["Year"]).to eq ['2009']
expect(results.first["context"]["Formats"][0]).to eq "Vinyl"
expect(results.first["context"]["Record Labels"][1]).to eq "Universal Music Classics & Jazz"
expect(results.first["context"]["Type"][0]).to eq "release"
expect(results.first["context"][1]["values"]).to eq ["2009"]
expect(results.first["context"][3]["values"][0]).to eq "Vinyl"
expect(results.first["context"][2]["values"][1]).to eq "Universal Music Classics & Jazz"
expect(results.first["context"][4]["values"][0]).to eq "release"
end
end

Expand All @@ -299,9 +299,9 @@
expect(results.first['uri']).to eq "https://www.discogs.com/Wes-Montgomery-Bumpin-On-Sunset-Tequila/master/606116"
expect(results.first['id']).to eq "606116"
expect(results.first['label']).to eq "Wes Montgomery - Bumpin' On Sunset / Tequila"
expect(results.first['context']["Year"]).to eq ['1966']
expect(results.first['context']["Formats"][2]).to eq "45 RPM"
expect(results.first["context"]["Type"][0]).to eq "master"
expect(results.first['context'][1]["values"]).to eq ['1966']
expect(results.first['context'][3]["values"][2]).to eq "45 RPM"
expect(results.first["context"][4]["values"][0]).to eq "master"
end
end

Expand Down

0 comments on commit 559393b

Please sign in to comment.