From 4de7212c397bbb9c3351018ceef509ef36be13f8 Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Mon, 4 Dec 2023 10:37:24 -0500 Subject: [PATCH] Refactor OembedController --- app/controllers/oembed_controller.rb | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/app/controllers/oembed_controller.rb b/app/controllers/oembed_controller.rb index 35493c7ae2..07090d252e 100644 --- a/app/controllers/oembed_controller.rb +++ b/app/controllers/oembed_controller.rb @@ -1,17 +1,36 @@ require_relative '../../lib/aapb' class OembedController < CatalogController - def show - - puts "\n\nparams = #{params}\n\n" - render json: { - "title": "Test", - "type": "rich", - "width": "640", - "height": "480", - "html": "

Blah blah blah

", + "title": pbcore_presenter.title, + "type": "video/mp4", + "width": "1640", + "height": "1480", + "src": "https://americanarchive.org/embed/#{pbcore_presenter.id}", } end + + + private + + def pbcore_presenter + @pbcore_presenter ||= PBCorePresenter.new(solr_doc['xml']) + end + + def solr_doc + @solr_doc ||= begin + _resp, doc = fetch_from_solr(id_from_url_param) + raise Blacklight::Exceptions::RecordNotFound unless doc + doc + end + end + + def id_from_url_param + @id_from_url_param ||= begin + uri = URI.parse(params['url']) + path_parts = uri.path.split('/') + path_parts.detect {|path_part| path_part =~ /^cpb\-aacip/} + end + end end