Sha256: 90cb19473c4192c0d69aeefae77f71a9a148078bae554cb0c44595800a050dce

Contents?: true

Size: 981 Bytes

Versions: 29

Compression:

Stored size: 981 Bytes

Contents

# frozen_string_literal: true

require 'iiif/presentation'

module Spotlight
  module Resources
    # harvest Images from IIIF Manifest and turn them into a Spotlight::Resource
    # Note: IIIF API : http://iiif.io/api/presentation/2.0
    class IiifHarvester < Spotlight::Resource
      self.document_builder_class = Spotlight::Resources::IiifBuilder
      self.weight = -5000

      validate :valid_url?

      def iiif_manifests
        @iiif_manifests ||= IiifService.parse(url)
      end

      private

      def valid_url?
        errors.add(:url, 'Invalid IIIF URL') unless url_is_iiif?(url)
      end

      def url_is_iiif?(url)
        valid_content_types = ['application/json', 'application/ld+json']
        req = Faraday.head(url)
        req = Faraday.get(url) if req.status == 405
        return unless req.success?

        valid_content_types.any? do |valid_type|
          req.headers['content-type'].include?(valid_type)
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc3 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.rc2 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.rc1 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.10 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.9 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.8 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.7 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.6 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.5 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.4 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.3 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.2 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-3.0.0.alpha.1 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-2.13.0 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-2.12.1 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-2.12.0 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-2.11.0 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-2.10.0 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-2.9.0 app/models/spotlight/resources/iiif_harvester.rb
blacklight-spotlight-2.8.0 app/models/spotlight/resources/iiif_harvester.rb