Class: Riiif::HTTPFileResolver

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

Defined Under Namespace

Classes: RemoteFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHTTPFileResolver

Returns a new instance of HTTPFileResolver.



19
20
21
# File 'lib/riiif/http_file_resolver.rb', line 19

def initialize
  @cache_path = 'tmp/network_files'
end

Instance Attribute Details

#basic_auth_credentialsObject

Returns the value of attribute basic_auth_credentials.



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

def basic_auth_credentials
  @basic_auth_credentials
end

#cache_pathObject

Returns the value of attribute cache_path.



17
18
19
# File 'lib/riiif/http_file_resolver.rb', line 17

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



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

def id_to_uri
  @id_to_uri
end

Instance Method Details

#find(id) ⇒ Object



23
24
25
26
27
28
# File 'lib/riiif/http_file_resolver.rb', line 23

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