Commit 9886d4b3 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

adding create community action and query keys

parent 08caf65d
......@@ -3,38 +3,49 @@ module Dspace
class CommunityResource < ResourceKit::Resource
resources do
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
action :all, 'GET /rest/communities' do
query_keys :expand
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_communities(JSON.parse(response.body))
end
end
action :top_communities, 'GET /rest/communities/top-communities' do
query_keys :expand
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_communities(JSON.parse(response.body))
end
end
action :find, 'GET /rest/communities/:id' do
query_keys :expand
handler(200) do |response|
Dspace::Community.new(JSON.parse(response.body))
end
end
action :collections, 'GET /rest/communities/:id/collections' do
query_keys :expand
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_collections(JSON.parse(response.body))
end
end
action :sub_communities, 'GET /rest/communities/:id/communities' do
query_keys :expand
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_communities(JSON.parse(response.body))
end
end
end
action :create, 'POST /rest/communities' do
body { |object| JSON.generate(object.to_h) }
handler(200, 201) { |response| true }
end
end
end
end
end
\ No newline at end of file
......@@ -4,25 +4,41 @@ RSpec.describe Dspace::Resources::CommunityResource, resource_kit: true do
subject(:resource) { Dspace::Resources::CommunityResource }
it 'get all communities' do
expect(resource).to have_action(:all).that_handles(200).at_path('/rest/communities')
expect(resource).to have_action(:all).that_handles(200).at_path('/rest/communities').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Community))
end
end
it 'get top communities' do
expect(resource).to have_action(:top_communities).that_handles(200).at_path('/rest/communities/top-communities')
expect(resource).to have_action(:top_communities).that_handles(200).at_path('/rest/communities/top-communities').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Community))
end
end
it 'find community' do
expect(resource).to have_action(:find).that_handles(200).at_path('/rest/communities/:id')
expect(resource).to have_action(:find).that_handles(200).at_path('/rest/communities/:id').with_verb(:get) do |handled|
expect(handled).to be_kind_of(Dspace::Community)
end
end
it 'create a new top-level community' do
expect(resource).to have_action(:create).that_handles(200,201).at_path('/rest/communities').with_verb(:post) do |handled|
expect(handled).to eq(true)
end
end
context "with community scope" do
it "get collections" do
expect(resource).to have_action(:collections).that_handles(200).at_path('/rest/communities/:id/collections')
expect(resource).to have_action(:collections).that_handles(200).at_path('/rest/communities/:id/collections').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Collection))
end
end
it "get sub communities" do
expect(resource).to have_action(:sub_communities).that_handles(200).at_path('/rest/communities/:id/communities')
expect(resource).to have_action(:sub_communities).that_handles(200).at_path('/rest/communities/:id/communities').with_verb(:get) do |handled|
expect(handled).to all(be_kind_of(Dspace::Community))
end
end
end
......
require_relative 'lib/dspace'
require 'faraday'
faraday = Faraday.new('https://mecdb3.c3sl.ufpr.br:8443/rest', {ssl: {verify: false}, headers: {content_type: 'application/json',
faraday = Faraday.new('https://demo.dspace.org/', {ssl: {verify: false}, headers: {content_type: 'application/json',
accept: 'application/json'}})
r = Dspace::Resources::CommunityResource.new(connection: faraday)
p r.all
\ No newline at end of file
r = Dspace::Resources::CommunityResource.new(connection: faraday)
\ 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