Commit 8a33db0a authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

rollback Handles status on resources

parent ed1430a0
......@@ -4,6 +4,8 @@ module Dspace
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
......@@ -13,12 +15,12 @@ module Dspace
action :login, 'POST /rest/login' do
query_keys :email, :password
handler(200) { |response| response['set-cookie'] }
handler(200, 201) { |response| response['set-cookie'] }
end
action :logout, 'POST /rest/logout' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| true }
handler(200, 201, 203, 204) { |response| true }
end
end
......
......@@ -4,6 +4,8 @@ module Dspace
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
......@@ -36,26 +38,26 @@ module Dspace
end
action :delete, 'DELETE /rest/bitstreams/:id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :delete_policy, 'DELETE /rest/bitstreams/:id/policy/:policy_id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :add_policy, 'POST /rest/bitstreams/:id/policy' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
action :update, 'PUT /rest/bitstreams/:id' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
action :update_data, 'PUT /rest/bitstreams/:id/data' do
body { |file| file.read }
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
end
......
......@@ -4,6 +4,8 @@ module Dspace
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
......@@ -27,15 +29,15 @@ module Dspace
action :update, 'PUT /rest/collections/:id' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
action :delete, 'DELETE /rest/collections/:id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :delete_item, 'DELETE /rest/collections/:id/items/:item_id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :items, 'GET /rest/collections/:id/items' do
......@@ -47,7 +49,7 @@ module Dspace
action :create_item, 'POST /rest/collections/:id/items' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| Dspace::Item.new(JSON.parse(response.body)) }
handler(200, 201) { |response| Dspace::Item.new(JSON.parse(response.body)) }
end
end
......
......@@ -4,6 +4,8 @@ module Dspace
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
......@@ -48,34 +50,34 @@ module Dspace
action :create, 'POST /rest/communities' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| Dspace::Community.new(JSON.parse(response.body)) }
handler(200, 201) { |response| Dspace::Community.new(JSON.parse(response.body)) }
end
action :create_subcommunity, 'POST /rest/communities/:id/communities' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| Dspace::Community.new(JSON.parse(response.body)) }
handler(200, 201) { |response| Dspace::Community.new(JSON.parse(response.body)) }
end
action :create_collection, 'POST /rest/communities/:id/collections' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| Dspace::Collection.new(JSON.parse(response.body)) }
handler(200, 201) { |response| Dspace::Collection.new(JSON.parse(response.body)) }
end
action :update, 'PUT /rest/communities/:id' do
body { |object| JSON.generate(object.to_h) }
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
action :delete, 'DELETE /rest/communities/:id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :delete_collection, 'DELETE /rest/communities/:id/collections/:collection_id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :delete_subcommunity, 'DELETE /rest/communities/:id/communities/:subcommunity_id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
end
......
......@@ -3,7 +3,9 @@ module Dspace
class ItemResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
......@@ -46,20 +48,20 @@ module Dspace
end
action :delete, 'DELETE /rest/items/:id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :clear_metadata, 'DELETE /rest/items/:id/metadata' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :delete_bitstream, 'DELETE /rest/items/:id/bitstreams/:bitstream_id' do
handler(200) { |response| true }
handler(200, 201, 204) { |response| true }
end
action :add_metadata, 'POST /rest/items/:id/metadata' do
body { |objects| Dspace::Builders::ModelBuilder.models2hash(objects) }
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
action :add_bitstream, 'POST /rest/items/:id/bitstreams' do
......@@ -70,7 +72,7 @@ module Dspace
action :update_metadata, 'PUT /rest/items/:id/metadata' do
body { |object| JSON.generate(Dspace::Builders::ModelBuilder.models2hash(object))}
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
end
......
......@@ -4,6 +4,8 @@ module Dspace
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
......
......@@ -4,6 +4,8 @@ module Dspace
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
......@@ -12,7 +14,7 @@ module Dspace
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :test, 'GET /rest/test' do
handler(200) { |response| true }
handler(200, 201) { |response| true }
end
action :status, 'GET /rest/status' do
......
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