Commit f2dfead4 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

adding retrive action for bitstream resource

parent 4c83c6ad
module Dspace
module Builders
module TempfileBuilder
def self.build(filename, contents = nil)
file = Tempfile.new([sanitize_filename(name), File.extname(name)]).tap do |f|
f.write contents
f.close
end
end
private
def self.sanitize_filename(filename)
filename.strip do |name|
# NOTE: File.basename doesn't work right with Windows paths on Unix
# get only the filename, not the whole path
name.gsub!(/^.*(\\|\/)/, '')
# Strip out the non-ascii character
name.gsub!(/[^0-9A-Za-z.\-]/, '_')
end
end
end
end
end
\ No newline at end of file
......@@ -30,11 +30,9 @@ module Dspace
end
end
#action :retrive, 'GET /rest/bitstreams/:id/retrieve' do
# handler(200) do |response|
# tmpfile = Tempfile.new([filename, extension])
# end
#end
action :retrive, 'GET /rest/bitstreams/:id/retrieve' do
handler(200) { |response| response.body }
end
action :delete, 'DELETE /rest/bitstreams/:id' do
handler(200, 201, 204) { |response| true }
......@@ -54,12 +52,18 @@ module Dspace
handler(200, 201) { |response| true }
end
# action :update_data, 'PUT /rest/bitstreams/:id/data' do
# body { |object| JSON.generate(object.to_h) }
# action :update_data, 'PUT /rest/bitstreams/:id/data' do
# body { |object| JSON.generate(object.to_h) }
# handler(200, 201) { |response| true }
# end
# end
end
def retrieve(args={})
bitstream = ResourceKit::ActionInvoker.call(action(:find), self, id: args.fetch(:id))
Dspace::Builders::TempfileBuilder.build bitstream.name, ResourceKit::ActionInvoker.call(action(:retrive), self)
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment