Skip to content

Commit

Permalink
get the context right
Browse files Browse the repository at this point in the history
  • Loading branch information
tworrall committed Nov 7, 2019
1 parent 7e0ff28 commit 30e718d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
43 changes: 24 additions & 19 deletions lib/qa/authorities/discogs/generic_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,25 @@ 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-YoNr0d=/fit-in/600x580/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-4212473.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|
Expand All @@ -133,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"][1]["Year"]).to eq ["2009"]
expect(results.first["context"][3]["Formats"][0]).to eq "Vinyl"
expect(results.first["context"][2]["Record Labels"][1]).to eq "Universal Music Classics & Jazz"
expect(results.first["context"][4]["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'][1]["Year"]).to eq ['1966']
expect(results.first['context'][3]["Formats"][2]).to eq "45 RPM"
expect(results.first["context"][4]["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 30e718d

Please sign in to comment.