Class: Riiif::HttpFileResolver

Inherits:
Object
  • Object
show all
Defined in:
app/resolvers/riiif/http_file_resolver.rb

Defined Under Namespace

Classes: RemoteFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_path: 'tmp/network_files') ⇒ HttpFileResolver

Returns a new instance of HttpFileResolver.



18
19
20
# File 'app/resolvers/riiif/http_file_resolver.rb', line 18

def initialize(cache_path: 'tmp/network_files')
  @cache_path = cache_path
end

Instance Attribute Details

#basic_auth_credentialsObject

Returns the value of attribute basic_auth_credentials.



15
16
17
# File 'app/resolvers/riiif/http_file_resolver.rb', line 15

def basic_auth_credentials
  @basic_auth_credentials
end

#cache_pathObject

Returns the value of attribute cache_path.



16
17
18
# File 'app/resolvers/riiif/http_file_resolver.rb', line 16

def cache_path
  @cache_path
end

#id_to_uriObject

Set a lambda that maps the first parameter (id) to a URL Example:

resolver = Riiif::HttpFileResolver.new resolver.id_to_uri = lambda do |id|

"http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/#{id}.jpg/600px-#{id}.jpg"

end



14
15
16
# File 'app/resolvers/riiif/http_file_resolver.rb', line 14

def id_to_uri
  @id_to_uri
end

Instance Method Details

#find(id) ⇒ Object



22
23
24
25
26
27
# File 'app/resolvers/riiif/http_file_resolver.rb', line 22

def find(id)
  remote = RemoteFile.new(uri(id),
                          cache_path: cache_path,
                          basic_auth_credentials: basic_auth_credentials)
  Riiif::File.new(remote.fetch)
end