dspace_rest_client 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a5caf190284294ce02a942a3d72941bfdd452e0
4
- data.tar.gz: a2f03710acec47e549750ec8883fa3506ddf8e3c
3
+ metadata.gz: 5beb7c52c728e6467bdbc68f0d8a7ca7fc6fa08c
4
+ data.tar.gz: 423f753535f47ec8f64fd9196ce47d32325ec856
5
5
  SHA512:
6
- metadata.gz: 0dcaae58f9183bc3b8c68d6775443da62f5b423902bf7eaaf95e7ba108769fa1d7b0d45e44e8fda227e31522d2fccabbc82accae889936101fbd130916f20d30
7
- data.tar.gz: bfd559a9ed06a3c6fa02ec20bad5210b2b3469f58d5eefc4e6a4f65b1bc94ed4d2808f2bc720c43f9db57d9e072bdbbd3caaa5b22f43bbe918092b704bd9e251
6
+ metadata.gz: e132ad2bbdf9786150de16e123b38c5dac637e7373ae2b74d9017d3e4b403e0881443b715f00e003e1e0ee634d4ab41ccabeef7265d8c73a34adaa0b96d2c9b6
7
+ data.tar.gz: bcb42dcfb45d18da3370680147726536c4d48aed446905e5b5303c7498b49b253f92dc156ad1581635322f499fb2c5837ce81086626c12c9dedc612d74677eb5
@@ -12,4 +12,6 @@ require File.dirname(__FILE__) + '/dspacerest/repositories/community_repository'
12
12
  require File.dirname(__FILE__) + '/dspacerest/repositories/dspace_repository'
13
13
  require File.dirname(__FILE__) + '/dspacerest/repositories/item_repository'
14
14
  require File.dirname(__FILE__) + '/dspacerest/strategies/uploads/curl_strategy'
15
- require File.dirname(__FILE__) + '/dspacerest/strategies/uploads/rest_strategy'
15
+ require File.dirname(__FILE__) + '/dspacerest/strategies/uploads/rest_strategy'
16
+ require File.dirname(__FILE__) + '/dspacerest/builders/hash_builder'
17
+ require File.dirname(__FILE__) + '/dspacerest/builders/model_builder'
@@ -9,42 +9,43 @@ module DSpaceRest
9
9
  :sequence_id, :policies
10
10
 
11
11
  def initialize args
12
- @id = args['id'] || ""
13
- @name = args['name'] || ""
14
- @type = args['type'] || ""
15
- @link = args['link'] || ""
16
- @bundle_name = args['bundleName'] || ""
17
- @description = args['description'] || ""
18
- @format = args['format'] || ""
19
- @mime_type = args['mimeType'] || ""
20
- @size_bytes = args['sizeBytes'] || ""
21
- @parent_object = args['parentObject'] || ""
22
- @retrieve_link = args['retrieveLink'] || ""
23
- @check_sum = args['checkSum'] || ""
24
- @sequence_id = args['sequenceId'] || ""
25
- @policies = args['policies'] || ""
26
- @expand = args['expand'] || ""
12
+ @id = args['id']
13
+ @name = args['name']
14
+ @type = args['type']
15
+ @link = args['link']
16
+ @bundle_name = args['bundleName']
17
+ @description = args['description']
18
+ @format = args['format']
19
+ @mime_type = args['mimeType']
20
+ @size_bytes = args['sizeBytes']
21
+ @parent_object = args['parentObject']
22
+ @retrieve_link = args['retrieveLink']
23
+ @check_sum = args['checkSum']
24
+ @sequence_id = args['sequenceId']
25
+ @policies = DSpaceRest::Builders::ModelBuilder.build_policies(args['policies'])
26
+ @expand = args['expand']
27
27
  end
28
28
 
29
29
  def to_h
30
- h = Hash.new
31
- h['id'] = @id
32
- h['name'] = @name
33
- h['type'] = @type
34
- h['link'] = @link
35
- h['bundleName'] = @bundle_name
36
- h['description'] = @description
37
- h['format'] = @format
38
- h['mimeType'] = @mime_type
39
- h['sizeBytes'] = @size_bytes
40
- h['parentObject'] = @parent_object
41
- h['retrieveLink'] = @retrieve_link
42
- h['checkSum'] = @check_sum
43
- h['sequenceId'] = @sequence_id
44
- h['policies'] = @policies
45
- h['expand'] = @expand
30
+ h = {
31
+ id: @id,
32
+ name: @name,
33
+ type: @type,
34
+ link: @link,
35
+ bundleName: @bundle_name,
36
+ description: @description,
37
+ format: @format,
38
+ mimeType: @mime_type,
39
+ sizeBytes: @size_bytes,
40
+ parentObject: @parent_object,
41
+ retrieveLink: @retrieve_link,
42
+ checkSum: @check_sum,
43
+ sequenceId: @sequence_id,
44
+ policies: @policies,
45
+ expand: @expand
46
+ }
47
+
46
48
  h
47
49
  end
48
-
49
50
  end
50
51
  end
@@ -0,0 +1,16 @@
1
+ module DSpaceRest
2
+ module Builders
3
+ module HashBuilder
4
+
5
+ def self.models2hash(list)
6
+ hash = []
7
+ list.each do |m|
8
+ hash << m.to_h
9
+ end
10
+
11
+ hash
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,61 @@
1
+ module DSpaceRest
2
+ module Builders
3
+ module ModelBuilder
4
+
5
+ def self.build_communities(communities=[])
6
+ return communities if communities.nil?
7
+ colls = []
8
+ communities.each do |c|
9
+ colls << DSpaceRest::Community.new(c)
10
+ end
11
+ colls
12
+ end
13
+
14
+ def self.build_collections(collections=[])
15
+ return collections if collections.nil?
16
+ colls = []
17
+ collections.each do |c|
18
+ colls << DSpaceRest::Collection.new(c)
19
+ end
20
+ colls
21
+ end
22
+
23
+ def self.build_items(items=[])
24
+ return items if items.nil?
25
+ colls = []
26
+ items.each do |c|
27
+ colls << DSpaceRest::Item.new(c)
28
+ end
29
+ colls
30
+ end
31
+
32
+ def self.build_bitstreams(bitstreams=[])
33
+ return bitstreams if bitstreams.nil?
34
+ colls = []
35
+ bitstreams.each do |c|
36
+ colls << DSpaceRest::Bitstream.new(c)
37
+ end
38
+ colls
39
+ end
40
+
41
+ def self.build_metadatas(metadatas=[])
42
+ return metadatas if metadatas.nil?
43
+ colls = []
44
+ metadatas.each do |c|
45
+ colls << DSpaceRest::Metadata.new(c)
46
+ end
47
+ colls
48
+ end
49
+
50
+ def self.build_policies(policies=[])
51
+ return policies if policies.nil?
52
+ colls = []
53
+ policies.each do |c|
54
+ colls << DSpaceRest::Policy.new(c)
55
+ end
56
+ colls
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -6,7 +6,7 @@ module DSpaceRest
6
6
 
7
7
  attr_reader :id, :handle, :type, :link, :parent_community,
8
8
  :parent_community_list, :items,
9
- :number_iems, :sub_communities, :collections, :expand
9
+ :number_items, :expand
10
10
 
11
11
  def initialize args
12
12
  @id = args['id']
@@ -15,38 +15,47 @@ module DSpaceRest
15
15
  @type = args['type']
16
16
  @link = args['link']
17
17
  @logo = args['logo']
18
- @parent_community = args['parentCommunity']
19
- @parent_community_list = args['parentCommunityList']
20
- @items = args['items']
21
18
  @license = args['license']
22
19
  @copyright_text = args['copyrightText']
23
20
  @introductory_text = args['introductoryText']
24
21
  @short_description = args['shortDescription']
25
22
  @sidebar_text = args['sidebarText']
26
- @number_items = args['countItems']
23
+ @number_items = args['numberItems']
27
24
  @expand = args['expand']
25
+
26
+ @parent_community = DSpaceRest::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
27
+ @parent_community_list = DSpaceRest::Builders::ModelBuilder.build_communities(args['parentCommunityList'])
28
+ @items = DSpaceRest::Builders::ModelBuilder.build_items(args['items'])
28
29
  end
29
30
 
30
31
  def to_h
31
- h = Hash.new
32
- h["id"] = @id
33
- h["name"] = @name
34
- h["handle"] = @handle
35
- h["type"] = @type
36
- h["link"] = @link
37
- h["logo"] = @logo
38
- h["parentCommunity"] = @parent_community
39
- h["parentCommunityList"] = @parent_community_list
40
- h["items"] = @items
41
- h["license"] = @license
42
- h["copyrightText"] = @copyright_text
43
- h["introductoryText"] = @introductory_text
44
- h["shortDescription"] = @short_description
45
- h["sidebarText"] = @sidebar_text
46
- h["numberItems"] = @number_items
47
- h["expand"] = @expand
32
+ h = {
33
+ id: @id,
34
+ name: @name,
35
+ handle: @handle,
36
+ type: @type,
37
+ link: @link,
38
+ logo: @logo,
39
+ parentCommunity: @parent_community,
40
+ parentCommunitList: @parent_community_list,
41
+ items: obj2hash(@items),
42
+ license: @license,
43
+ copyrightText: @copyright_text,
44
+ introductoryText: @introductory_text,
45
+ shortDescription: @short_description,
46
+ sidebarText: @sidebar_text,
47
+ numberItems: @number_items,
48
+ expand: @expand
49
+ }
50
+
48
51
  h
49
52
  end
50
53
 
54
+ private
55
+
56
+ def obj2hash(list)
57
+ DSpaceRest::Builders::HashBuilder.models2hash list
58
+ end
59
+
51
60
  end
52
- end
61
+ end
@@ -14,36 +14,44 @@ module DSpaceRest
14
14
  @type = args['type']
15
15
  @link = args['link']
16
16
  @logo = args['logo']
17
- @parent_community = args['parentCommunity']
17
+ @parent_community = DSpaceRest::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
18
18
  @copyright_text = args['copyrightText']
19
19
  @introductory_text = args['introductoryText']
20
20
  @short_description = args['shortDescription']
21
21
  @sidebar_text = args['sidebarText']
22
22
  @count_items = args['countItems']
23
- @sub_communities = args['subcommunities']
24
- @collections = args['collections']
23
+ @sub_communities = DSpaceRest::Builders::ModelBuilder.build_communities(args['subcommunities'])
24
+ @collections = DSpaceRest::Builders::ModelBuilder.build_collections(args['collections'])
25
25
  @expand = args['expand']
26
26
  end
27
27
 
28
28
  def to_h
29
- h = Hash.new
30
- h["handle"] = @handle
31
- h["name"] = @name
32
- h["id"] = @id
33
- h["type"] = @type
34
- h["link"] = @link
35
- h["logo"] = @logo
36
- h["parentCommunity"] = @parent_community
37
- h["copyrightText"] = @copyright_text
38
- h["introductoryText"] = @introductory_text
39
- h["shortDescription"] = @short_description
40
- h["sidebarText"] = @sidebar_text
41
- h["countItems"] = @count_items
42
- h["subcommunities"] = @sub_communities
43
- h["collections"] = @collections
44
- h["expand"] = @expand
29
+ h = {
30
+ id: @id,
31
+ name: @name,
32
+ handle: @handle,
33
+ type: @type,
34
+ link: @link,
35
+ logo: @logo,
36
+ parentCommunity: @parent_community,
37
+ subcommunities: obj2hash(@sub_communities),
38
+ collections: obj2hash(@collections),
39
+ copyrightText: @copyright_text,
40
+ introductoryText: @introductory_text,
41
+ shortDescription: @short_description,
42
+ sidebarText: @sidebar_text,
43
+ countItems: @count_items,
44
+ expand: @expand
45
+ }
46
+
45
47
  h
46
48
  end
47
49
 
50
+ private
51
+
52
+ def obj2hash(list)
53
+ DSpaceRest::Builders::HashBuilder.models2hash list
54
+ end
55
+
48
56
  end
49
57
  end
@@ -5,46 +5,44 @@ module DSpaceRest
5
5
 
6
6
  attr_accessor :name, :archived, :withdrawn
7
7
 
8
- attr_reader :id, :handle, :type, :link, :last_modified,
9
- :parent_collection, :parent_collection_list, :bit_streams,
8
+ attr_reader :id, :handle, :type, :link, :last_modified, :parent_collection,
9
+ :parent_collection_list, :parent_community_list, :bit_streams,
10
10
  :expand, :metadata
11
11
 
12
12
  def initialize args
13
- @id = args['id'] || ""
14
- @name = args['name'] || ""
15
- @handle = args['handle'] || ""
16
- @type = args['type'] || ""
17
- @link = args['link'] || ""
18
- @last_modified = args['lastModified'] || ""
19
- @parent_collection = args['parentCollection'] || ""
20
- @parent_collection_list = args['parentCollectionList'] || ""
21
- @parent_community_list = args['parentCommunityList'] || ""
22
- @bit_streams = args['bitstreams'] || ""
23
- @archived = args['archived'] || ""
24
- @withdrawn = args['withdrawn'] || ""
25
- @expand = args['expand'] || ""
26
- @metadata = []
13
+ @id = args['id']
14
+ @name = args['name']
15
+ @handle = args['handle']
16
+ @type = args['type']
17
+ @link = args['link']
18
+ @last_modified = args['lastModified']
19
+ @parent_collection = DSpaceRest::Collection.new(args['parentCollection']) unless args['parentCollection'].nil?
20
+ @parent_collection_list = DSpaceRest::Builders::ModelBuilder.build_collections(args['parentCollectionList'])
21
+ @parent_community_list = DSpaceRest::Builders::ModelBuilder.build_communities(args['parentCommunityList'])
22
+ @bit_streams = DSpaceRest::Builders::ModelBuilder.build_bitstreams(args['bitstreams'])
23
+ @archived = args['archived']
24
+ @withdrawn = args['withdrawn']
25
+ @expand = args['expand']
26
+ @metadata = DSpaceRest::Builders::ModelBuilder.build_metadatas(args['metadata'])
27
27
  end
28
28
 
29
29
  def to_h
30
- h = Hash.new
31
- h["id"] = @id
32
- h["name"] = @name
33
- h["handle"] = @handle
34
- h["type"] = @type
35
- h["link"] = @link
36
- h["lastModified"] = @last_modified
37
- h["parentCollection"] = @parent_collection
38
- h["parentCollectionList"] = @parent_collection_list
39
- h["parentCommunityList"] = @parent_community_list
40
- h["bitstreams"] = @bit_streams
41
- h["archived"] = @archived
42
- h["withdrawn"] = @withdrawn
43
- h["expand"] = @expand
44
-
45
- if !@metadata.empty?
46
- h["metadata"] = metadata2hash @metadata
47
- end
30
+ h = {
31
+ id: @id,
32
+ name: @name,
33
+ handle: @handle,
34
+ type: @type,
35
+ link: @link,
36
+ lastModified: @last_modified,
37
+ parentCollection: @parent_collection.to_h,
38
+ parentCollectionList: obj2hash(@parent_collection_list),
39
+ parentCommunityList: obj2hash(@parent_community_list),
40
+ bitstreams: obj2hash(@bit_streams),
41
+ archived: @archived,
42
+ withdrawn: @withdrawn,
43
+ expand: @expand,
44
+ metadata: obj2hash(@metadata)
45
+ }
48
46
 
49
47
  h
50
48
  end
@@ -65,14 +63,9 @@ module DSpaceRest
65
63
 
66
64
  private
67
65
 
68
- def metadata2hash(metadata)
69
- hash = []
70
- @metadata.each do |m|
71
- hash << m.to_h
72
- end
73
-
74
- hash
66
+ def obj2hash(list)
67
+ DSpaceRest::Builders::HashBuilder.models2hash list
75
68
  end
76
69
 
77
70
  end
78
- end
71
+ end
@@ -6,11 +6,11 @@ module DSpaceRest
6
6
  def initialize args
7
7
  @key = args['key']
8
8
  @value = args['value']
9
- @language = args['language']
9
+ @language = args['language'] || nil
10
10
  end
11
11
 
12
12
  def to_h
13
- return {"key" => @key, "value" => @value, "language" => @language}
13
+ {key: @key, value: @value, language: @language}
14
14
  end
15
15
 
16
16
  end
@@ -0,0 +1,41 @@
1
+ module DSpaceRest
2
+ class Policy
3
+
4
+ attr_reader :id, :action, :eperson_id, :group_id,
5
+ :resource_id, :resource_type, :rp_description,
6
+ :rp_name, :rp_type, :start_date, :end_date
7
+
8
+ def initialize args
9
+ @id = args['id']
10
+ @action = args['action']
11
+ @eperson_id = args['epersonId']
12
+ @group_id = args['groupId']
13
+ @resource_id = args['resourceId']
14
+ @resource_type = args['resourceType']
15
+ @rp_description = args['rpDescription']
16
+ @rp_name = args['rpName']
17
+ @rp_type = args['rpType']
18
+ @start_date = args['startDate']
19
+ @end_date = args['endDate']
20
+ end
21
+
22
+ def to_h
23
+ h = {
24
+ id: @id,
25
+ action: @action,
26
+ epersonId: @eperson_id,
27
+ groupId: @group_id,
28
+ resourceId: @resource_id,
29
+ resourceType: @resource_type,
30
+ rpDescription: @rp_description,
31
+ rpName: @rp_name,
32
+ rpType: @rp_type,
33
+ startDate: @start_date,
34
+ endDate: @end_date
35
+ }
36
+
37
+ h
38
+ end
39
+
40
+ end
41
+ end
@@ -1,12 +1,20 @@
1
- module DSpaceRest
2
- module Repositories
3
- class AbstractRepository
4
- attr_reader :rest_client
5
-
6
- def initialize(rest_client)
7
- @rest_client = rest_client
8
- end
9
-
10
- end
11
- end
1
+ module DSpaceRest
2
+ module Repositories
3
+ class AbstractRepository
4
+ attr_reader :rest_client
5
+
6
+ def initialize(rest_client)
7
+ @rest_client = rest_client
8
+ end
9
+
10
+ protected
11
+
12
+ def build_expand_uri(expand = nil)
13
+ if expandable_properties.include? expand
14
+ "expand=#{expand}"
15
+ end
16
+ end
17
+
18
+ end
19
+ end
12
20
  end
@@ -1,49 +1,58 @@
1
- module DSpaceRest
2
- module Repositories
3
- class BitstreamRepository < AbstractRepository
4
-
5
- # Bitstreams are files. They have a filename, size (in bytes), and a file format.
6
- # Typically in DSpace, the Bitstream will the "full text" article, or some other media.
7
- # Some files are the actual file that was uploaded (tagged with bundleName:ORIGINAL),
8
- # others are DSpace-generated files that are derivatives or renditions, such as text-extraction, or thumbnails.
9
- # You can download files/bitstreams.
10
- # DSpace doesn't really limit the type of files that it takes in, so this could be PDF, JPG, audio, video, zip,
11
- # or other.
12
- # Also, the logo for a Collection or a Community, is also a Bitstream.
13
-
14
- # √ GET /bitstreams - Return all bitstreams in DSpace.
15
- # √ GET /bitstreams/{bitstream id} - Return bitstream.
16
- # GET /bitstreams/{bitstream id}/policy - Return bitstream policies.
17
- # √ GET /bitstreams/{bitstream id}/retrieve - Return data of bitstream.
18
- # POST /bitstreams/{bitstream id}/policy - Add policy to item. You must post a ResourcePolicy
19
- # PUT /bitstreams/{bitstream id}/data - Update data/file of bitstream. You must put the data
20
- # √ PUT /bitstreams/{bitstream id} - Update metadata of bitstream. You must put a Bitstream, does not alter the file/data
21
- # DELETE /bitstreams/{bitstream id} - Delete bitstream from DSpace.
22
- # DELETE /bitstreams/{bitstream id}/policy/{policy_id} - Delete bitstream policy.
23
-
24
- def get_bitstream_by_id(id)
25
- response = rest_client["/bitstreams/#{id}"].get
26
- DSpaceRest::Bitstream.new(JSON.parse(response))
27
- end
28
-
29
- def get_all_bitstreams
30
- response = rest_client["/bitstreams"].get
31
- bit_streams = []
32
- JSON.parse(response).each do |bits|
33
- bit_streams << DSpaceRest::Bitstream.new(bits)
34
- end
35
- bit_streams
36
- end
37
-
38
- def retrieve_data(bitstream)
39
- response = rest_client["/bitstreams/#{bitstream.id}/retrieve"].get
40
- end
41
-
42
- def update(bitstream)
43
- valid_keys=['name', 'description', 'sequenceId']
44
- form = JSON.generate(bitstream.to_h.select { |k, v| valid_keys.include? k })
45
- response = rest_client["/bitstreams/#{bitstream.id}"].put form
46
- end
47
- end
48
- end
1
+ module DSpaceRest
2
+ module Repositories
3
+ class BitstreamRepository < AbstractRepository
4
+
5
+ # Bitstreams are files. They have a filename, size (in bytes), and a file format.
6
+ # Typically in DSpace, the Bitstream will the "full text" article, or some other media.
7
+ # Some files are the actual file that was uploaded (tagged with bundleName:ORIGINAL),
8
+ # others are DSpace-generated files that are derivatives or renditions, such as text-extraction, or thumbnails.
9
+ # You can download files/bitstreams.
10
+ # DSpace doesn't really limit the type of files that it takes in, so this could be PDF, JPG, audio, video, zip,
11
+ # or other.
12
+ # Also, the logo for a Collection or a Community, is also a Bitstream.
13
+
14
+ # √ GET /bitstreams - Return all bitstreams in DSpace.
15
+ # √ GET /bitstreams/{bitstream id} - Return bitstream.
16
+ # GET /bitstreams/{bitstream id}/policy - Return bitstream policies.
17
+ # √ GET /bitstreams/{bitstream id}/retrieve - Return data of bitstream.
18
+ # POST /bitstreams/{bitstream id}/policy - Add policy to item. You must post a ResourcePolicy
19
+ # PUT /bitstreams/{bitstream id}/data - Update data/file of bitstream. You must put the data
20
+ # √ PUT /bitstreams/{bitstream id} - Update metadata of bitstream. You must put a Bitstream, does not alter the file/data
21
+ # DELETE /bitstreams/{bitstream id} - Delete bitstream from DSpace.
22
+ # DELETE /bitstreams/{bitstream id}/policy/{policy_id} - Delete bitstream policy.
23
+
24
+ def get_bitstream_by_id(id, expand = nil)
25
+ expand_uri = build_expand_uri(expand)
26
+ response = rest_client["/bitstreams/#{id}?#{expand_uri}"].get
27
+ DSpaceRest::Bitstream.new(JSON.parse(response))
28
+ end
29
+
30
+ def get_all_bitstreams(expand = nil)
31
+ expand_uri = build_expand_uri(expand)
32
+ response = rest_client["/bitstreams?#{expand_uri}"].get
33
+ bit_streams = []
34
+ JSON.parse(response).each do |bits|
35
+ bit_streams << DSpaceRest::Bitstream.new(bits)
36
+ end
37
+ bit_streams
38
+ end
39
+
40
+ def retrieve_data(bitstream)
41
+ response = rest_client["/bitstreams/#{bitstream.id}/retrieve"].get
42
+ end
43
+
44
+ def update(bitstream)
45
+ valid_keys=['name', 'description', 'sequenceId']
46
+ form = JSON.generate(bitstream.to_h.select { |k, v| valid_keys.include? k })
47
+ response = rest_client["/bitstreams/#{bitstream.id}"].put form
48
+ end
49
+
50
+ private
51
+
52
+ def expandable_properties
53
+ ["parent","policies","all"]
54
+ end
55
+
56
+ end
57
+ end
49
58
  end
@@ -1,64 +1,73 @@
1
- module DSpaceRest
2
- module Repositories
3
- class CollectionRepository < AbstractRepository
4
- # Collections in DSpace are containers of Items
5
-
6
- # √ GET /communities/{communityId}/collections - Returns array of collections of community.
7
- # √ GET /collections - Return all collections of DSpace in array.
8
- # √ GET /collections/{collectionId} - Return collection with id.
9
- # √ GET /collections/{collectionId}/items - Return all items of collection.
10
- # √ POST /communities/{communityId}/collections - Create new collections in community. You must post Collection.
11
- # √ POST /collections/{collectionId}/items - Create posted item in collection. You must post an Item
12
- # POST /collections/find-collection - Find collection by passed name.
13
- # PUT /collections/{collectionId} - Update collection. You must put Collection.
14
- # DELETE /collections/{collectionId} - Delete collection from DSpace.
15
- # DELETE /collections/{collectionId}/items/{itemId} - Delete item in collection.
16
- # DELETE /communities/{communityId}/collections/{collectionId} - Delete collection in community.
17
-
18
- def get_collection_items(collection)
19
- response = rest_client["/collections/#{collection.id}/items"].get
20
- items = []
21
- JSON.parse(response).each do |item|
22
- items << DSpaceRest::Item.new(item)
23
- end
24
- items
25
- end
26
-
27
- def get_collection_by_id(id)
28
- response = rest_client["/collections/#{id}"].get
29
- DSpaceRest::Collection.new(JSON.parse(response))
30
- end
31
-
32
- def get_all_collections
33
- response = rest_client["/collections"].get
34
- collections = []
35
- JSON.parse(response).each do |coll|
36
- collections << DSpaceRest::Collection.new(coll)
37
- end
38
- collections
39
- end
40
-
41
- def get_collections_of(community)
42
- response = rest_client["/communities/#{community.id}/collections"].get
43
- collections = []
44
- JSON.parse(response).each do |coll|
45
- collections << DSpaceRest::Collection.new(coll)
46
- end
47
- collections
48
- end
49
-
50
- def create_collection_for(community, collection)
51
- form = JSON.generate(collection.to_h)
52
- response = rest_client["/communities/#{community.id}/collections"].post form
53
- DSpaceRest::Collection.new(JSON.parse(response))
54
- end
55
-
56
- def create_item_for(collection, item)
57
- form = JSON.generate({"metadata" => item.to_h["metadata"]})
58
- response = rest_client["/collections/#{collection.id}/items"].post form
59
- DSpaceRest::Item.new(JSON.parse(response))
60
- end
61
-
62
- end
63
- end
1
+ module DSpaceRest
2
+ module Repositories
3
+ class CollectionRepository < AbstractRepository
4
+ # Collections in DSpace are containers of Items
5
+
6
+ # √ GET /communities/{communityId}/collections - Returns array of collections of community.
7
+ # √ GET /collections - Return all collections of DSpace in array.
8
+ # √ GET /collections/{collectionId} - Return collection with id.
9
+ # √ GET /collections/{collectionId}/items - Return all items of collection.
10
+ # √ POST /communities/{communityId}/collections - Create new collections in community. You must post Collection.
11
+ # √ POST /collections/{collectionId}/items - Create posted item in collection. You must post an Item
12
+ # POST /collections/find-collection - Find collection by passed name.
13
+ # PUT /collections/{collectionId} - Update collection. You must put Collection.
14
+ # DELETE /collections/{collectionId} - Delete collection from DSpace.
15
+ # DELETE /collections/{collectionId}/items/{itemId} - Delete item in collection.
16
+ # DELETE /communities/{communityId}/collections/{collectionId} - Delete collection in community.
17
+
18
+ def get_collection_items(collection)
19
+ response = rest_client["/collections/#{collection.id}/items"].get
20
+ items = []
21
+ JSON.parse(response).each do |item|
22
+ items << DSpaceRest::Item.new(item)
23
+ end
24
+ items
25
+ end
26
+
27
+ def get_collection_by_id(id, expand = nil)
28
+ expand_uri = build_expand_uri(expand)
29
+ response = rest_client["/collections/#{id}?#{expand_uri}"].get
30
+ DSpaceRest::Collection.new(JSON.parse(response))
31
+ end
32
+
33
+ def get_all_collections(expand = nil)
34
+ expand_uri = build_expand_uri(expand)
35
+ response = rest_client["/collections?#{expand_uri}"].get
36
+ collections = []
37
+ JSON.parse(response).each do |coll|
38
+ collections << DSpaceRest::Collection.new(coll)
39
+ end
40
+ collections
41
+ end
42
+
43
+ def get_collections_of(community, expand = nil)
44
+ expand_uri = build_expand_uri(expand)
45
+ response = rest_client["/communities/#{community.id}/collections?#{expand_uri}"].get
46
+ collections = []
47
+ JSON.parse(response).each do |coll|
48
+ collections << DSpaceRest::Collection.new(coll)
49
+ end
50
+ collections
51
+ end
52
+
53
+ def create_collection_for(community, collection)
54
+ form = JSON.generate(collection.to_h)
55
+ response = rest_client["/communities/#{community.id}/collections"].post form
56
+ DSpaceRest::Collection.new(JSON.parse(response))
57
+ end
58
+
59
+ def create_item_for(collection, item)
60
+ form = JSON.generate({"metadata" => item.to_h["metadata"]})
61
+ response = rest_client["/collections/#{collection.id}/items"].post form
62
+ DSpaceRest::Item.new(JSON.parse(response))
63
+ end
64
+
65
+ private
66
+
67
+ def expandable_properties
68
+ ["parentCommunityList","parentCommunity","items","license","logo","all"]
69
+ end
70
+
71
+ end
72
+ end
64
73
  end
@@ -1,62 +1,72 @@
1
- module DSpaceRest
2
- module Repositories
3
- class CommunityRepository < AbstractRepository
4
- # Communities in DSpace are used for organization and hierarchy, and are containers that hold sub-Communities and Collections.
5
-
6
- # √ GET /communities - Returns array of all communities in DSpace.
7
- # √ GET /communities/top-communities - Returns array of all top communities in DSpace
8
- # √ GET /communities/{communityId} - Returns community
9
- # √ GET /communities/{communityId}/communities - Returns array of subcommunities of community.
10
- # √ POST /communities - Create new community at top level. You must post community.
11
- # √ POST /communities/{communityId}/communities - Create new subcommunity in community. You must post Community.
12
- # PUT /communities/{communityId} - Update community. You must put Community
13
- # DELETE /communities/{communityId} - Delete community.
14
- # DELETE /communities/{communityId}/communities/{communityId2} - Delete subcommunity in community.
15
-
16
- def get_community_by_id(id)
17
- response = rest_client["/communities/#{id}"].get
18
- DSpaceRest::Community.new(JSON.parse(response))
19
- end
20
-
21
- def get_all_communities
22
- response = rest_client["/communities"].get
23
- communities = []
24
- JSON.parse(response).each do |comm|
25
- communities << DSpaceRest::Community.new(comm)
26
- end
27
- communities
28
- end
29
-
30
- def get_top_communities
31
- response = rest_client["/communities/top-communities"].get
32
- communities = []
33
- JSON.parse(response).each do |comm|
34
- communities << DSpaceRest::Community.new(comm)
35
- end
36
- communities
37
- end
38
-
39
- def get_subcommunities_of(community)
40
- response = rest_client["/communities/#{community.id}/communities"].get
41
- communities = []
42
- JSON.parse(response).each do |comm|
43
- communities << DSpaceRest::Community.new(comm)
44
- end
45
- communities
46
- end
47
-
48
- def create_community(community)
49
- form = JSON.generate(community.to_h)
50
- response = rest_client["/communities"].post form
51
- end
52
-
53
- def create_subcommunity_of(community, subcommunity)
54
- form = JSON.generate(subcommunity.to_h)
55
- response = rest_client["/communities/#{community.id}/communities"].post form
56
-
57
- DSpaceRest::Community.new(JSON.parse(response))
58
- end
59
-
60
- end
61
- end
1
+ module DSpaceRest
2
+ module Repositories
3
+ class CommunityRepository < AbstractRepository
4
+ # Communities in DSpace are used for organization and hierarchy, and are containers that hold sub-Communities and Collections.
5
+
6
+ # √ GET /communities - Returns array of all communities in DSpace.
7
+ # √ GET /communities/top-communities - Returns array of all top communities in DSpace
8
+ # √ GET /communities/{communityId} - Returns community
9
+ # √ GET /communities/{communityId}/communities - Returns array of subcommunities of community.
10
+ # √ POST /communities - Create new community at top level. You must post community.
11
+ # √ POST /communities/{communityId}/communities - Create new subcommunity in community. You must post Community.
12
+ # PUT /communities/{communityId} - Update community. You must put Community
13
+ # DELETE /communities/{communityId} - Delete community.
14
+ # DELETE /communities/{communityId}/communities/{communityId2} - Delete subcommunity in community.
15
+
16
+ def get_community_by_id(id, expand = nil)
17
+ expand_uri = build_expand_uri(expand)
18
+ response = rest_client["/communities/#{id}?#{expand_uri}"].get
19
+ DSpaceRest::Community.new(JSON.parse(response))
20
+ end
21
+
22
+ def get_all_communities(expand = nil)
23
+ expand_uri = build_expand_uri(expand)
24
+ response = rest_client["/communities?#{expand_uri}"].get
25
+ communities = []
26
+ JSON.parse(response).each do |comm|
27
+ communities << DSpaceRest::Community.new(comm)
28
+ end
29
+ communities
30
+ end
31
+
32
+ def get_top_communities(expand = nil)
33
+ expand_uri = build_expand_uri(expand)
34
+ response = rest_client["/communities/top-communities?#{expand_uri}"].get
35
+ communities = []
36
+ JSON.parse(response).each do |comm|
37
+ communities << DSpaceRest::Community.new(comm)
38
+ end
39
+ communities
40
+ end
41
+
42
+ def get_subcommunities_of(community, expand = nil)
43
+ expand_uri = build_expand_uri(expand)
44
+ response = rest_client["/communities/#{community.id}/communities?#{expand_uri}"].get
45
+ communities = []
46
+ JSON.parse(response).each do |comm|
47
+ communities << DSpaceRest::Community.new(comm)
48
+ end
49
+ communities
50
+ end
51
+
52
+ def create_community(community)
53
+ form = JSON.generate(community.to_h)
54
+ response = rest_client["/communities"].post form
55
+ end
56
+
57
+ def create_subcommunity_of(community, subcommunity)
58
+ form = JSON.generate(subcommunity.to_h)
59
+ response = rest_client["/communities/#{community.id}/communities"].post form
60
+
61
+ DSpaceRest::Community.new(JSON.parse(response))
62
+ end
63
+
64
+ private
65
+
66
+ def expandable_properties
67
+ ["parentCommunity","collections","subCommunities","logo","all"]
68
+ end
69
+
70
+ end
71
+ end
62
72
  end
@@ -1,27 +1,27 @@
1
- module DSpaceRest
2
- module Repositories
3
- class DspaceRepository < AbstractRepository
4
-
5
- def bitstream_repository
6
- BitstreamRepository.new rest_client
7
- end
8
-
9
- def collection_repository
10
- CollectionRepository.new rest_client
11
- end
12
-
13
- def community_repository
14
- CommunityRepository.new rest_client
15
- end
16
-
17
- def item_repository
18
- ItemRepository.new rest_client
19
- end
20
-
21
- def metadata_repository
22
- MetadataRepository.new rest_client
23
- end
24
-
25
- end
26
- end
1
+ module DSpaceRest
2
+ module Repositories
3
+ class DspaceRepository < AbstractRepository
4
+
5
+ def bitstream_repository
6
+ BitstreamRepository.new rest_client
7
+ end
8
+
9
+ def collection_repository
10
+ CollectionRepository.new rest_client
11
+ end
12
+
13
+ def community_repository
14
+ CommunityRepository.new rest_client
15
+ end
16
+
17
+ def item_repository
18
+ ItemRepository.new rest_client
19
+ end
20
+
21
+ def metadata_repository
22
+ MetadataRepository.new rest_client
23
+ end
24
+
25
+ end
26
+ end
27
27
  end
@@ -1,68 +1,76 @@
1
- module DSpaceRest
2
- module Repositories
3
- class ItemRepository < AbstractRepository
4
- # Items in DSpace represent a "work" and combine metadata and files, known as Bitstreams
5
-
6
- # √ GET /items - Return list of items.
7
- # √ GET /items/{item id} - Return item.
8
- # √ GET /items/{item id}/metadata - Return item metadata.
9
- # √ GET /items/{item id}/bitstreams - Return item bitstreams.
10
- # POST /items/find-by-metadata-field - Find items by metadata entry. You must post a MetadataEntry. DS-2501 - wrong SQL in REST /items/find-by-metadata-field CLOSED
11
- # √ POST /items/{item id}/metadata - Add metadata to item. You must post an array of MetadataEntry
12
- # √ POST /items/{item id}/bitstreams - Add bitstream to item. You must post a Bitstream
13
- # √ PUT /items/{item id}/metadata - Update metadata in item. You must put a MetadataEntry
14
- # √ DELETE /items/{item id} - Delete item.
15
- # DELETE /items/{item id}/metadata - Clear item metadata.
16
- # DELETE /items/{item id}/bitstreams/{bitstream id} - Delete item bitstream.
17
-
18
-
19
- def get_all_items
20
- response = rest_client["/items"].get
21
- items = []
22
- JSON.parse(response).each do |item|
23
- items << DSpaceRest::Item.new(item)
24
- end
25
- items
26
- end
27
-
28
- def get_item_by_id(id)
29
- response = rest_client["/items/#{id}"].get
30
- DSpaceRest::Item.new(JSON.parse(response))
31
- end
32
-
33
- def get_metadata_of(item)
34
- response = rest_client["/items/#{item.id}/metadata"].get
35
- metadata = []
36
- JSON.parse(response).each do |m|
37
- metadata << DSpaceRest::Metadata.new(m)
38
- end
39
- metadata
40
- end
41
-
42
- def get_bitstreams_of(item)
43
- response = rest_client["/items/#{item.id}/bitstreams"].get
44
- bitstreams = []
45
- JSON.parse(response).each do |bits|
46
- bitstreams << DSpaceRest::Bitstream.new(bits)
47
- end
48
- bitstreams
49
- end
50
-
51
-
52
- def create_metadata_for(item)
53
- form = JSON.generate(self.to_h["metadata"])
54
- response = rest_client["/items/#{item.id}/metadata"].put form
55
- end
56
-
57
- def create_bitstream_for(item, file, upload_strategy)
58
- response = upload_strategy.upload("/items/#{item.id}/bitstreams", file)
59
- DSpaceRest::Bitstream.new(JSON.parse(response))
60
- end
61
-
62
- def delete(item)
63
- response = rest_client["/items/#{item.id}"].delete
64
- end
65
-
66
- end
67
- end
1
+ module DSpaceRest
2
+ module Repositories
3
+ class ItemRepository < AbstractRepository
4
+ # Items in DSpace represent a "work" and combine metadata and files, known as Bitstreams
5
+
6
+ # √ GET /items - Return list of items.
7
+ # √ GET /items/{item id} - Return item.
8
+ # √ GET /items/{item id}/metadata - Return item metadata.
9
+ # √ GET /items/{item id}/bitstreams - Return item bitstreams.
10
+ # POST /items/find-by-metadata-field - Find items by metadata entry. You must post a MetadataEntry. DS-2501 - wrong SQL in REST /items/find-by-metadata-field CLOSED
11
+ # √ POST /items/{item id}/metadata - Add metadata to item. You must post an array of MetadataEntry
12
+ # √ POST /items/{item id}/bitstreams - Add bitstream to item. You must post a Bitstream
13
+ # √ PUT /items/{item id}/metadata - Update metadata in item. You must put a MetadataEntry
14
+ # √ DELETE /items/{item id} - Delete item.
15
+ # DELETE /items/{item id}/metadata - Clear item metadata.
16
+ # DELETE /items/{item id}/bitstreams/{bitstream id} - Delete item bitstream.
17
+
18
+
19
+ def get_all_items(expand = nil)
20
+ expand_uri = build_expand_uri(expand)
21
+ response = rest_client["/items?#{expand_uri}"].get
22
+ items = []
23
+ JSON.parse(response).each do |item|
24
+ items << DSpaceRest::Item.new(item)
25
+ end
26
+ items
27
+ end
28
+
29
+ def get_item_by_id(id, expand = nil)
30
+ expand_uri = build_expand_uri(expand)
31
+ response = rest_client["/items/#{id}?#{expand_uri}"].get
32
+ DSpaceRest::Item.new(JSON.parse(response))
33
+ end
34
+
35
+ def get_metadata_of(item)
36
+ response = rest_client["/items/#{item.id}/metadata"].get
37
+ metadata = []
38
+ JSON.parse(response).each do |m|
39
+ metadata << DSpaceRest::Metadata.new(m)
40
+ end
41
+ metadata
42
+ end
43
+
44
+ def get_bitstreams_of(item)
45
+ response = rest_client["/items/#{item.id}/bitstreams"].get
46
+ bitstreams = []
47
+ JSON.parse(response).each do |bits|
48
+ bitstreams << DSpaceRest::Bitstream.new(bits)
49
+ end
50
+ bitstreams
51
+ end
52
+
53
+
54
+ def create_metadata_for(item)
55
+ form = JSON.generate(self.to_h["metadata"])
56
+ response = rest_client["/items/#{item.id}/metadata"].put form
57
+ end
58
+
59
+ def create_bitstream_for(item, file, upload_strategy)
60
+ response = upload_strategy.upload("/items/#{item.id}/bitstreams", file)
61
+ DSpaceRest::Bitstream.new(JSON.parse(response))
62
+ end
63
+
64
+ def delete(item)
65
+ response = rest_client["/items/#{item.id}"].delete
66
+ end
67
+
68
+ private
69
+
70
+ def expandable_properties
71
+ ["metadata","parentCollection","parentCollectionList","parentCommunityList","bitstreams","all"]
72
+ end
73
+
74
+ end
75
+ end
68
76
  end
@@ -1,27 +1,27 @@
1
- #require 'curl'
2
-
3
- module DSpaceRest
4
- module Strategies
5
- module Uploads
6
- class CurlStrategy
7
-
8
- def initialize(host_url, token)
9
- @host_url = host_url
10
- @token = token
11
- end
12
-
13
- def upload(endpoint, file)
14
- c = Curl::Easy.new(@host_url.concat(endpoint))
15
- c.headers['Accept'] = 'application/json'
16
- c.headers['rest-dspace-token'] = @token
17
-
18
- c.multipart_form_post = true
19
- c.ssl_verify_peer = false
20
- c.http_post(Curl::PostField.file('file', file))
21
-
22
- c.body_str
23
- end
24
- end
25
- end
26
- end
1
+ #require 'curl'
2
+
3
+ module DSpaceRest
4
+ module Strategies
5
+ module Uploads
6
+ class CurlStrategy
7
+
8
+ def initialize(host_url, token)
9
+ @host_url = host_url
10
+ @token = token
11
+ end
12
+
13
+ def upload(endpoint, file)
14
+ c = Curl::Easy.new(@host_url.concat(endpoint))
15
+ c.headers['Accept'] = 'application/json'
16
+ c.headers['rest-dspace-token'] = @token
17
+
18
+ c.multipart_form_post = true
19
+ c.ssl_verify_peer = false
20
+ c.http_post(Curl::PostField.file('file', file))
21
+
22
+ c.body_str
23
+ end
24
+ end
25
+ end
26
+ end
27
27
  end
@@ -1,17 +1,17 @@
1
- module DSpaceRest
2
- module Strategies
3
- module Uploads
4
- class RestStrategy
5
-
6
- def initialize(rest_client)
7
- @rest_client = rest_client
8
- end
9
-
10
- def upload(endpoint, file)
11
- @rest_client[endpoint].post File.read(file)
12
- end
13
-
14
- end
15
- end
16
- end
1
+ module DSpaceRest
2
+ module Strategies
3
+ module Uploads
4
+ class RestStrategy
5
+
6
+ def initialize(rest_client)
7
+ @rest_client = rest_client
8
+ end
9
+
10
+ def upload(endpoint, file)
11
+ @rest_client[endpoint].post File.read(file)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dspace_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Giacomini Girardello
@@ -55,10 +55,13 @@ files:
55
55
  - lib/dspace_client.rb
56
56
  - lib/dspace_rest_client.rb
57
57
  - lib/dspacerest/bitstream.rb
58
+ - lib/dspacerest/builders/hash_builder.rb
59
+ - lib/dspacerest/builders/model_builder.rb
58
60
  - lib/dspacerest/collection.rb
59
61
  - lib/dspacerest/community.rb
60
62
  - lib/dspacerest/item.rb
61
63
  - lib/dspacerest/metadata.rb
64
+ - lib/dspacerest/policy.rb
62
65
  - lib/dspacerest/repositories/abstract_repository.rb
63
66
  - lib/dspacerest/repositories/bitstream_repository.rb
64
67
  - lib/dspacerest/repositories/collection_repository.rb