Commit 827971ac authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

implement HierarchyResource and SiteClass

parent d226919e
......@@ -16,6 +16,7 @@ require_relative "dspace/resources/item_resource"
require_relative "dspace/builders/hash_builder"
require_relative "dspace/builders/model_builder"
require_relative "dspace/builders/tempfile_builder"
require_relative "dspace/site"
require_relative "dspace/community"
require_relative "dspace/collection"
require_relative "dspace/item"
......
......@@ -20,8 +20,17 @@ module Dspace
@short_description = args['shortDescription'] || args['short_description']
@sidebar_text = args['sidebarText'] || args['sidebar_text']
@count_items = args['countItems']
@sub_communities = Dspace::Builders::ModelBuilder.build_communities(args['subcommunities']) unless args['subcommunities'].nil?
@collections = Dspace::Builders::ModelBuilder.build_collections(args['collections']) unless args['collections'].nil?
# subcommunities = All community endpoints
# community = Hierarchy endpoint
sub_communities = args['subcommunities'] || args['community']
@sub_communities = Dspace::Builders::ModelBuilder.build_communities(sub_communities) unless sub_communities.nil?
# collections = All community/collection endpoints
# collection = Hierarchy endpoint
collections = args['collections'] || args['collection']
@collections = Dspace::Builders::ModelBuilder.build_collections(collections) unless collections.nil?
@expand = args['expand']
end
......
......@@ -15,7 +15,7 @@ module Dspace
action :all, 'GET /rest/hierarchy' do
handler(200) do |response|
response.body
Dspace::Site.new(JSON.parse(response.body))
end
end
......
......@@ -2,22 +2,21 @@ module Dspace
class Site
include Dspace::Builders::HashBuilder
attr_accessor :name
attr_reader :id, :handle
attr_reader :id, :name, :handle, :community_list
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?
@community_list = Dspace::Builders::ModelBuilder.build_communities(args['community']) unless args['community'].nil?
end
def to_h
{
uuid: @id,
name: @name,
handle: @handle
handle: @handle,
community: obj2hash(@community_list),
}
end
......
require 'spec_helper'
RSpec.describe Dspace::Resources::HierarchyResource, resource_kit: true do
subject(:resource) { Dspace::Resources::HierarchyResource }
it 'get all hierarchy' do
expect(resource).to have_action(:all).that_handles(200).at_path('/rest/hierarchy').with_verb(:get) do |handled|
expect(handled).to be_kind_of(Dspace::Site)
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