Commit 50bec2c7 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

adding authentication and status resources

parent 2084cfec
......@@ -10,9 +10,15 @@ require_relative "dspace/builders/hash_builder"
require_relative "dspace/builders/model_builder"
require_relative "dspace/community"
require_relative "dspace/collection"
require_relative "dspace/item"
require_relative "dspace/metadata"
require_relative "dspace/bitstream"
require_relative "dspace/policy"
module Dspace
class NotAuthorizedError < StandardError; end
class InvalidTokenError < StandardError; end
class InvalidCredentialsError < StandardError; end
end
require 'curb'
module Dspace
class Item
......
module Dspace
module Resources
class AuthenticationResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Invalid access token.' }
action :login, 'POST /rest/login' do
body { |email, password| JSON.generate({email: email, password: password}) }
handler(200, 201) { |response| access_token = response.body }
end
action :logout, 'POST /rest/logout' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201, 203, 204) { |response| true }
end
end
end
end
end
\ No newline at end of file
module Dspace
module Resources
class StatusResource < ResourceKit::Resource
resources do
action :test, 'GET /rest/test' do
handler(200, 201) { |response| true }
end
action :status, 'GET /rest/status' do
handler(200) { |response| JSON.parse(response.body) }
end
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