Class: DSpaceRest::Repositories::CommunityRepository

Inherits:
AbstractRepository show all
Defined in:
lib/dspacerest/repositories/community_repository.rb

Instance Attribute Summary

Attributes inherited from AbstractRepository

#rest_client

Instance Method Summary collapse

Methods inherited from AbstractRepository

#initialize

Constructor Details

This class inherits a constructor from DSpaceRest::Repositories::AbstractRepository

Instance Method Details

#create_community(community) ⇒ Object



52
53
54
55
# File 'lib/dspacerest/repositories/community_repository.rb', line 52

def create_community(community)
  form = JSON.generate(community.to_h)
  response = rest_client["/communities"].post form
end

#create_subcommunity_of(community, subcommunity) ⇒ Object



57
58
59
60
61
62
# File 'lib/dspacerest/repositories/community_repository.rb', line 57

def create_subcommunity_of(community, subcommunity)
  form = JSON.generate(subcommunity.to_h)
  response = rest_client["/communities/#{community.id}/communities"].post form

  DSpaceRest::Community.new(JSON.parse(response))
end

#get_all_communities(expand = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/dspacerest/repositories/community_repository.rb', line 22

def get_all_communities(expand = nil)
  expand_uri = build_expand_uri(expand)
  response = rest_client["/communities?#{expand_uri}"].get
  communities = []
  JSON.parse(response).each do |comm|
    communities << DSpaceRest::Community.new(comm)
  end
  communities
end

#get_community_by_id(id, expand = nil) ⇒ Object

√ GET /communities - Returns array of all communities in DSpace. √ GET /communities/top-communities - Returns array of all top communities in DSpace √ GET /communities/communityId - Returns community √ GET /communities/communityId/communities - Returns array of subcommunities of community. √ POST /communities - Create new community at top level. You must post community. √ POST /communities/communityId/communities - Create new subcommunity in community. You must post Community. PUT /communities/communityId - Update community. You must put Community DELETE /communities/communityId - Delete community. DELETE /communities/communityId/communities/communityId2 - Delete subcommunity in community.



16
17
18
19
20
# File 'lib/dspacerest/repositories/community_repository.rb', line 16

def get_community_by_id(id, expand = nil)
  expand_uri = build_expand_uri(expand)
  response = rest_client["/communities/#{id}?#{expand_uri}"].get
  DSpaceRest::Community.new(JSON.parse(response))
end

#get_subcommunities_of(community, expand = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/dspacerest/repositories/community_repository.rb', line 42

def get_subcommunities_of(community, expand = nil)
  expand_uri = build_expand_uri(expand)
  response = rest_client["/communities/#{community.id}/communities?#{expand_uri}"].get
  communities = []
  JSON.parse(response).each do |comm|
    communities << DSpaceRest::Community.new(comm)
  end
  communities
end

#get_top_communities(expand = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/dspacerest/repositories/community_repository.rb', line 32

def get_top_communities(expand = nil)
  expand_uri = build_expand_uri(expand)
  response = rest_client["/communities/top-communities?#{expand_uri}"].get
  communities = []
  JSON.parse(response).each do |comm|
    communities << DSpaceRest::Community.new(comm)
  end
  communities
end