Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
5,813 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class MarcxmlController < ApplicationController #:nodoc: | ||
before_action :set_marcxml_resource | ||
|
||
def catkey | ||
render plain: @marcxml.catkey | ||
end | ||
|
||
def marcxml | ||
render xml: @marcxml.marcxml | ||
end | ||
|
||
def mods | ||
render xml: @marcxml.mods | ||
end | ||
|
||
private | ||
|
||
def set_marcxml_resource | ||
@marcxml = MarcxmlResource.find_by(**marcxml_resource_params) | ||
end | ||
|
||
def marcxml_resource_params | ||
params.slice(:barcode, :catkey).to_unsafe_h.symbolize_keys | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# MARC resource model for retrieving and transforming MARC records | ||
class MarcxmlResource | ||
MARC_TO_MODS_XSLT = Nokogiri::XSLT(File.read(File.join(Rails.root, 'app', 'xslt', 'MARC21slim2MODS3-6.xsl'))) | ||
|
||
def self.find_by(catkey: nil, barcode: nil) | ||
if catkey | ||
new(catkey: catkey) | ||
elsif barcode | ||
solr = RSolr.connect(url: Settings.CATALOG.SOLR_URL) | ||
response = solr.get('barcode', params: { n: barcode }) | ||
catkey = response[:response][:docs].first[:id] | ||
|
||
new(catkey: catkey) | ||
else | ||
raise ArgumentError, 'Must supply either a catkey or barcode' | ||
end | ||
end | ||
|
||
attr_reader :catkey | ||
|
||
def initialize(catkey:) | ||
@catkey = catkey | ||
end | ||
|
||
def mods | ||
MARC_TO_MODS_XSLT.transform(Nokogiri::XML(marcxml)).to_xml | ||
end | ||
|
||
def marcxml | ||
Faraday.get(Settings.CATALOG.MARCXML_URL % { catkey: catkey }).body | ||
end | ||
end |
Oops, something went wrong.