Class: ActiveFedora::File::Streaming::FileBody

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, headers) ⇒ FileBody

Returns a new instance of FileBody.



307
308
309
310
# File 'lib/active_fedora/file.rb', line 307

def initialize(uri, headers)
  @uri = uri
  @headers = headers
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



306
307
308
# File 'lib/active_fedora/file.rb', line 306

def headers
  @headers
end

#uriObject (readonly)

Returns the value of attribute uri.



306
307
308
# File 'lib/active_fedora/file.rb', line 306

def uri
  @uri
end

Instance Method Details

#eachObject



312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/active_fedora/file.rb', line 312

def each
  Net::HTTP.start(uri.host, uri.port) do |http|
    request = Net::HTTP::Get.new uri, headers
    http.request request do |response|

      raise "Couldn't get data from Fedora (#{uri}). Response: #{response.code}" unless response.is_a?(Net::HTTPSuccess)
      response.read_body do |chunk|
        yield chunk
      end
    end
  end
end