Commit d226919e authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

start Implementing Hierarchy endpoint

parent 1b7b9adb
......@@ -5,6 +5,7 @@ require "faraday"
require "active_support/all"
require_relative "dspace/version"
require_relative "dspace/resources/hierarchy_resource"
require_relative "dspace/resources/schema_registry_resource"
require_relative "dspace/resources/community_resource"
require_relative "dspace/resources/collection_resource"
......
......@@ -28,7 +28,8 @@ module Dspace
communities: ::Dspace::Resources::CommunityResource,
status: ::Dspace::Resources::StatusResource,
authentication: ::Dspace::Resources::AuthenticationResource,
schema_registry: ::Dspace::Resources::SchemaRegistryResource
schema_registry: ::Dspace::Resources::SchemaRegistryResource,
hierarchy: ::Dspace::Resources::HierarchyResource
}
end
......
module Dspace
module Resources
class HierarchyResource < 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)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :all, 'GET /rest/hierarchy' do
handler(200) do |response|
response.body
end
end
end
end
end
end
module Dspace
class Site
include Dspace::Builders::HashBuilder
attr_accessor :name
attr_reader :id, :handle
def initialize(args={})
@id = args['id'] || args['uuid']
@name = args['name']
@handle = args['handle']
@community_list = Dspace::Collection.new(args['parentCollection']) unless args['parentCollection'].nil?
end
def to_h
{
uuid: @id,
name: @name,
handle: @handle
}
end
end
end
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