Skip to content

Commit

Permalink
Code review feedback 1
Browse files Browse the repository at this point in the history
- Preserve and respect namespaces in API response

- Add Sentry message in branch of code that is not
currently covered by tests
  • Loading branch information
matt-bernhardt committed Jan 13, 2025
1 parent a0a6d1f commit c8d8a25
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/models/lookup_barcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def info(barcode)

def extract_metadata(xml)
{
recordId: xml.xpath('//recordIdentifier').text,
title: xml.xpath('//title').text,
date: xml.xpath('//date').text,
publisher: xml.xpath('//publisher').text,
authors: xml.xpath('//contributor').text
recordId: xml.xpath('//default:recordIdentifier', 'default' => 'http://www.loc.gov/zing/srw/').text,
title: xml.xpath('//dc:title', 'dc' => 'http://purl.org/dc/elements/1.1/').text,
date: xml.xpath('//dc:date', 'dc' => 'http://purl.org/dc/elements/1.1/').text,
publisher: xml.xpath('//dc:publisher', 'dc' => 'http://purl.org/dc/elements/1.1/').text,
authors: xml.xpath('//dc:contributor', 'dc' => 'http://purl.org/dc/elements/1.1/').text
}
end

Expand All @@ -49,12 +49,13 @@ def fetch(barcode)
resp = HTTP.headers(accept: 'application/xml').get(url(barcode))

if resp.status == 200
Nokogiri::XML(resp.to_s).remove_namespaces!
Nokogiri::XML(resp.to_s)
else
Rails.logger.debug do
"Barcode lookup error. Barcode #{barcode} detected but Primo returned an error status"
end
Rails.logger.debug { "URL: #{url(barcode)}" }
Sentry.capture_message('Primo API error after barcode detection')
'Error'
end
end
Expand Down

0 comments on commit c8d8a25

Please sign in to comment.