Skip to content

Commit

Permalink
[WIP] Implementing handling for cases where responses for MVW Manifes…
Browse files Browse the repository at this point in the history
…ts return a 403 response
  • Loading branch information
jrgriffiniii committed Apr 23, 2018
1 parent 87716f9 commit cfe0b5c
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 59 deletions.
15 changes: 14 additions & 1 deletion app/models/iiif_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class IIIFResource < Spotlight::Resources::IiifHarvester
after_destroy :cleanup_solr
before_save :set_noid

validate :valid_url?

def iiif_manifests
@iiif_manifests ||= ::IiifService.parse(url)
end
Expand All @@ -18,7 +20,9 @@ def noid
private

def set_noid
data["noid"] = iiif_manifests.first.noid
first_manifest = iiif_manifests.first
return if first_manifest.nil?
data["noid"] = first_manifest.noid
end

def solr
Expand All @@ -28,4 +32,13 @@ def solr
def document_ids
document_builder.documents_to_index.to_a.map { |y| y[:id] }
end

def url_is_forbidden?(url)
req = Faraday.head(url)
req.status == 403
end

def valid_url?
errors.add(:url, 'Invalid IIIF URL') unless url_is_iiif?(url) || url_is_forbidden?(url)
end
end
2 changes: 2 additions & 0 deletions app/services/iiif_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ def self.iiif_response(url)
resp = Faraday.get(url)
if resp.success?
resp.body
elsif resp.status == 403
{ 'exhibit_first_public_bsi' => false }.to_json
else
Rails.logger.info("Failed to get #{url}")
{}.to_json
Expand Down
Loading

0 comments on commit cfe0b5c

Please sign in to comment.