dspace_rest_client 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,57 +1,57 @@
1
- module DSpaceRest
2
- class Community
3
-
4
- attr_accessor :name, :logo, :copyright_text,
5
- :introductory_text, :short_description, :sidebar_text
6
-
7
- attr_reader :id, :handle, :type, :link, :parent_community,
8
- :count_items, :sub_communities, :collections, :expand
9
-
10
- def initialize(args={})
11
- @id = args['id']
12
- @name = args['name']
13
- @handle = args['handle']
14
- @type = args['type']
15
- @link = args['link']
16
- @logo = args['logo']
17
- @parent_community = DSpaceRest::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
18
- @copyright_text = args['copyrightText']
19
- @introductory_text = args['introductoryText']
20
- @short_description = args['shortDescription']
21
- @sidebar_text = args['sidebarText']
22
- @count_items = args['countItems']
23
- @sub_communities = DSpaceRest::Builders::ModelBuilder.build_communities(args['subcommunities'])
24
- @collections = DSpaceRest::Builders::ModelBuilder.build_collections(args['collections'])
25
- @expand = args['expand']
26
- end
27
-
28
- def to_h
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
-
47
- h
48
- end
49
-
50
- private
51
-
52
- def obj2hash(list)
53
- DSpaceRest::Builders::HashBuilder.models2hash list
54
- end
55
-
56
- end
57
- end
1
+ module DSpaceRest
2
+ class Community
3
+
4
+ attr_accessor :name, :logo, :copyright_text,
5
+ :introductory_text, :short_description, :sidebar_text
6
+
7
+ attr_reader :id, :handle, :type, :link, :parent_community,
8
+ :count_items, :sub_communities, :collections, :expand
9
+
10
+ def initialize(args={})
11
+ @id = args['id']
12
+ @name = args['name']
13
+ @handle = args['handle']
14
+ @type = args['type']
15
+ @link = args['link']
16
+ @logo = args['logo']
17
+ @parent_community = DSpaceRest::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
18
+ @copyright_text = args['copyrightText']
19
+ @introductory_text = args['introductoryText']
20
+ @short_description = args['shortDescription']
21
+ @sidebar_text = args['sidebarText']
22
+ @count_items = args['countItems']
23
+ @sub_communities = DSpaceRest::Builders::ModelBuilder.build_communities(args['subcommunities'])
24
+ @collections = DSpaceRest::Builders::ModelBuilder.build_collections(args['collections'])
25
+ @expand = args['expand']
26
+ end
27
+
28
+ def to_h
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
+
47
+ h
48
+ end
49
+
50
+ private
51
+
52
+ def obj2hash(list)
53
+ DSpaceRest::Builders::HashBuilder.models2hash list
54
+ end
55
+
56
+ end
57
+ end
@@ -1,71 +1,70 @@
1
- require 'curb'
2
-
3
- module DSpaceRest
4
- class Item
5
-
6
- attr_accessor :name, :archived, :withdrawn
7
-
8
- attr_reader :id, :handle, :type, :link, :last_modified, :parent_collection,
9
- :parent_collection_list, :parent_community_list, :bit_streams,
10
- :expand, :metadata
11
-
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 = 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
- end
28
-
29
- def to_h
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
- }
46
-
47
- h
48
- end
49
-
50
- def add_metadata(key, value, language)
51
- m = {}
52
- m['key'] = key
53
- m['value'] = value
54
- m['language'] = language || ""
55
-
56
- @metadata << DSpaceRest::Metadata.new(m)
57
- @metadata
58
- end
59
-
60
- def reset_metadata
61
- @metadata = []
62
- end
63
-
64
- private
65
-
66
- def obj2hash(list)
67
- DSpaceRest::Builders::HashBuilder.models2hash list
68
- end
69
-
70
- end
71
- end
1
+ require 'curb'
2
+
3
+ module DSpaceRest
4
+ class Item
5
+
6
+ attr_accessor :name, :archived, :withdrawn
7
+
8
+ attr_reader :id, :handle, :type, :link, :last_modified, :parent_collection,
9
+ :parent_collection_list, :parent_community_list, :bit_streams,
10
+ :expand, :metadata
11
+
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 = 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
+ end
28
+
29
+ def to_h
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
+ }
46
+
47
+ h
48
+ end
49
+
50
+ def add_metadata(key, value, language)
51
+ m = {}
52
+ m['key'] = key
53
+ m['value'] = value
54
+ m['language'] = language || ""
55
+ @metadata << DSpaceRest::Metadata.new(m)
56
+ @metadata
57
+ end
58
+
59
+ def reset_metadata
60
+ @metadata = []
61
+ end
62
+
63
+ private
64
+
65
+ def obj2hash(list)
66
+ DSpaceRest::Builders::HashBuilder.models2hash list
67
+ end
68
+
69
+ end
70
+ end
@@ -1,17 +1,17 @@
1
- module DSpaceRest
2
- class Metadata
3
-
4
- attr_accessor :key, :value, :language
5
-
6
- def initialize args
7
- @key = args['key']
8
- @value = args['value']
9
- @language = args['language'] || nil
10
- end
11
-
12
- def to_h
13
- {key: @key, value: @value, language: @language}
14
- end
15
-
16
- end
17
- end
1
+ module DSpaceRest
2
+ class Metadata
3
+
4
+ attr_accessor :key, :value, :language
5
+
6
+ def initialize args
7
+ @key = args['key']
8
+ @value = args['value']
9
+ @language = args['language'] || nil
10
+ end
11
+
12
+ def to_h
13
+ {key: @key, value: @value, language: @language}
14
+ end
15
+
16
+ end
17
+ end
@@ -1,41 +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
+ 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,20 +1,37 @@
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
20
- 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_query_string(params)
13
+
14
+ query_string=""
15
+
16
+ if query_parameters.include? 'limit'
17
+ query_string << "limit=#{params[:limit]}&"
18
+ end
19
+
20
+ if query_parameters.include? 'offset'
21
+ query_string << "offset=#{params[:offset]}&"
22
+ end
23
+
24
+ expand_string = ""
25
+ params[:expand].each do |expand|
26
+ if expandable_properties.include? expand
27
+ expand_string << "#{expand},"
28
+ end
29
+ end
30
+ query_string << "expand=#{expand_string}"
31
+
32
+ query_string
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -1,58 +1,62 @@
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
58
- 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, params)
25
+ query_string = build_query_string(params)
26
+ response = rest_client["/bitstreams/#{id}?#{query_string}"].get
27
+ DSpaceRest::Bitstream.new(JSON.parse(response))
28
+ end
29
+
30
+ def get_all_bitstreams(params)
31
+ query_string = build_query_string(params)
32
+ response = rest_client["/bitstreams?#{query_string}"].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
+ def query_parameters
57
+ ["limit","offset"]
58
+ end
59
+
60
+ end
61
+ end
62
+ end