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,73 +1,78 @@
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
73
- 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, params)
19
+ query_string = build_query_string(params)
20
+ response = rest_client["/collections/#{collection.id}/items?#{query_string}"].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_collection_by_id(id, params)
29
+ query_string = build_query_string(params)
30
+ response = rest_client["/collections/#{id}?#{query_string}"].get
31
+ DSpaceRest::Collection.new(JSON.parse(response))
32
+ end
33
+
34
+ def get_all_collections(params)
35
+ query_string = build_query_string(params)
36
+ response = rest_client["/collections?#{query_string}"].get
37
+ collections = []
38
+ JSON.parse(response).each do |coll|
39
+ collections << DSpaceRest::Collection.new(coll)
40
+ end
41
+ collections
42
+ end
43
+
44
+ def get_collections_of(community, params)
45
+ query_string = build_query_string(params)
46
+ response = rest_client["/communities/#{community.id}/collections?#{query_string}"].get
47
+ collections = []
48
+ JSON.parse(response).each do |coll|
49
+ collections << DSpaceRest::Collection.new(coll)
50
+ end
51
+ collections
52
+ end
53
+
54
+ def create_collection_for(community, collection)
55
+ form = JSON.generate(collection.to_h)
56
+ response = rest_client["/communities/#{community.id}/collections"].post form
57
+ DSpaceRest::Collection.new(JSON.parse(response))
58
+ end
59
+
60
+ def create_item_for(collection, item)
61
+ form = JSON.generate({"metadata" => item.to_h[:metadata]})
62
+ response = rest_client["/collections/#{collection.id}/items"].post form
63
+ DSpaceRest::Item.new(JSON.parse(response))
64
+ end
65
+
66
+ private
67
+
68
+ def expandable_properties
69
+ ["parentCommunityList","parentCommunity","items","license","logo","all"]
70
+ end
71
+
72
+ def query_parameters
73
+ ["limit","offset"]
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -1,72 +1,76 @@
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
72
- 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, params)
17
+ query_string = build_query_string(params)
18
+ response = rest_client["/communities/#{id}?#{query_string}"].get
19
+ DSpaceRest::Community.new(JSON.parse(response))
20
+ end
21
+
22
+ def get_all_communities(params)
23
+ query_string = build_query_string(params)
24
+ response = rest_client["/communities?#{query_string}"].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(params)
33
+ query_string = build_query_string(params)
34
+ response = rest_client["/communities/top-communities?#{query_string}"].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, params)
43
+ query_string = build_query_string(params)
44
+ response = rest_client["/communities/#{community.id}/communities?#{query_string}"].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
+ def query_parameters
71
+ ["limit","offset"]
72
+ end
73
+
74
+ end
75
+ end
76
+ 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,76 +1,80 @@
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
76
- 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(params)
20
+ query_string = build_query_string(params)
21
+ response = rest_client["/items?#{query_string}"].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, params)
30
+ query_string = build_query_string(params)
31
+ response = rest_client["/items/#{id}?#{query_string}"].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, params)
45
+ query_string = build_query_string(params)
46
+ response = rest_client["/items/#{item.id}/bitstreams?#{query_string}"].get
47
+ bitstreams = []
48
+ JSON.parse(response).each do |bits|
49
+ bitstreams << DSpaceRest::Bitstream.new(bits)
50
+ end
51
+ bitstreams
52
+ end
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?name=#{file.name}&description=#{file.description}", file.path)
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
+ def query_parameters
75
+ ["limit","offset"]
76
+ end
77
+
78
+ end
79
+ end
80
+ 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,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dspace_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Giacomini Girardello
8
- - Bruno N. Zanette
8
+ - Bruno Nocera Zanette
9
9
  - Mateus Rambo Strey
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-05-22 00:00:00.000000000 Z
13
+ date: 2015-11-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.4.6
94
+ rubygems_version: 2.4.5.1
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: DSpace REST-API Client for Ruby!