Class: Spotlight::Resources::IiifService

Inherits:
Object
  • Object
show all
Defined in:
app/models/spotlight/resources/iiif_service.rb

Overview

Wrapper around IIIF-Presentation’s IIIF::Service that provides the ability to recursively traverse through all collections and manifests

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ IiifService

Returns a new instance of IiifService.



8
9
10
# File 'app/models/spotlight/resources/iiif_service.rb', line 8

def initialize(url)
  @url = url
end

Class Method Details

.iiif_response(url) ⇒ Object



41
42
43
44
45
46
# File 'app/models/spotlight/resources/iiif_service.rb', line 41

def iiif_response(url)
  Faraday.get(url).body
rescue Faraday::Error::ConnectionFailed, Faraday::TimeoutError => e
  Rails.logger.warn("HTTP GET for #{url} failed with #{e}")
  {}.to_json
end

.parse(url) ⇒ Object



26
27
28
# File 'app/models/spotlight/resources/iiif_service.rb', line 26

def self.parse(url)
  recursive_manifests(new(url))
end

Instance Method Details

#collectionsObject



12
13
14
15
16
# File 'app/models/spotlight/resources/iiif_service.rb', line 12

def collections
  @collections ||= (object.try(:collections) || []).map do |collection|
    self.class.new(collection['@id'])
  end
end

#manifestsObject



18
19
20
21
22
23
24
# File 'app/models/spotlight/resources/iiif_service.rb', line 18

def manifests
  @manifests ||= if manifest?
                   [create_iiif_manifest(object)]
                 else
                   build_collection_manifest.to_a
                 end
end