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

.http_clientObject



32
33
34
35
36
37
# File 'app/models/spotlight/resources/iiif_service.rb', line 32

def self.http_client
  Faraday.new do |b|
    b.response :follow_redirects
    b.adapter Faraday.default_adapter
  end
end

.iiif_response(url) ⇒ Object



50
51
52
53
54
55
# File 'app/models/spotlight/resources/iiif_service.rb', line 50

def iiif_response(url)
  Spotlight::Resources::IiifService.http_client.get(url).body
rescue Faraday::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