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.



10
11
12
# File 'app/models/spotlight/resources/iiif_service.rb', line 10

def initialize(url)
  @url = url
end

Class Method Details

.iiif_response(url) ⇒ Object



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

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



28
29
30
# File 'app/models/spotlight/resources/iiif_service.rb', line 28

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

Instance Method Details

#collectionsObject



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

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

#manifestsObject



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

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