README.md 4.44 KB
Newer Older
1
# DSpace REST Client
Mauricio Giacomini Girardello's avatar
Mauricio Giacomini Girardello committed
2

3
4
5
## Installation

Add this line to your application's Gemfile:
Mauricio Giacomini Girardello's avatar
Mauricio Giacomini Girardello committed
6
7

```ruby
8
gem 'dspace_rest_client'
9
```
10

11
And then execute:
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
12

13
    $ bundle
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
14

15
Or install it yourself as:
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
16

17
    $ gem install dspace_rest_client
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
18
19
20
21
    
Depends on packages (apt):
    
    $ ruby ruby-dev bundler
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
## Resources

### Item's resources
* action :all, 'GET /rest/items' (query_keys :expand, :limit, :offset)
* action :find, 'GET /rest/items/:id' (query_keys :expand)
* action :find_by_metadata, 'POST /rest/items/find-by-metadata-field'
* action :metadata, 'GET /rest/items/:id/metadata'
* action :bitstreams, 'GET /rest/items/:id/bitstreams' (query_keys :expand, :limit, :offset)
* action :delete, 'DELETE /rest/items/:id'
* action :clear_metadata, 'DELETE /rest/items/:id/metadata'
* action :delete_bitstream, 'DELETE /rest/items/:id/bitstreams/:bitstream_id'
* action :add_metadata, 'POST /rest/items/:id/metadata'
* action :add_bitstream, 'POST /rest/items/:id/bitstreams' (query_keys :name, :description, :bundle_name)
* action :update_metadata, 'PUT /rest/items/:id/metadata'

### Collection's resources
* action :all, 'GET /rest/collections' (query_keys :expand, :limit, :offset)
* action :find, 'GET /rest/collections/:id' (query_keys :expand)
* action :update, 'PUT /rest/collections/:id'
* action :delete, 'DELETE /rest/collections/:id'
* action :delete_item, 'DELETE /rest/collections/:id/items/:item_id'
* action :items, 'GET /rest/collections/:id/items' (query_keys :expand, :limit, :offset)
* action :create_item, 'POST /rest/collections/:id/items'

### Community's resources
* action :all, 'GET /rest/communities' (query_keys :expand, :limit, :offset)
* action :top_communities, 'GET /rest/communities/top-communities' (query_keys :expand, :limit, :offset)
* action :find, 'GET /rest/communities/:id' (query_keys :expand)
* action :collections, 'GET /rest/communities/:id/collections' (query_keys :expand, :limit, :offset)
* action :sub_communities, 'GET /rest/communities/:id/communities' (query_keys :expand, :limit, :offset)
* action :create, 'POST /rest/communities'
* action :create_subcommunity, 'POST /rest/communities/:id/communities'
* action :create_collection, 'POST /rest/communities/:id/collections'
* action :update, 'PUT /rest/communities/:id'
* action :delete, 'DELETE /rest/communities/:id'
* action :delete_collection, 'DELETE /rest/communities/:id/collections/:collection_id'
* action :delete_subcommunity, 'DELETE /rest/communities/:id/communities/:subcommunity_id'

### Bitstream's resources
* action :all, 'GET /rest/bitstreams' (query_keys :expand, :limit, :offset)
* action :find, 'GET /rest/bitstreams/:id' (query_keys :expand)
* action :policy, 'GET /rest/bitstreams/:id/policy'
* action :retrieve, 'GET /rest/bitstreams/:id/retrieve'
* action :delete, 'DELETE /rest/bitstreams/:id'
* action :delete_policy, 'DELETE /rest/bitstreams/:id/policy/:policy_id'
* action :add_policy, 'POST /rest/bitstreams/:id/policy'
* action :update, 'PUT /rest/bitstreams/:id'}
* action :update_data, 'PUT /rest/bitstreams/:id/data' do

### Authentication's resources
* action :login, 'POST /rest/login'
* action :logout, 'POST /rest/logout'

### Status's resources
* action :test, 'GET /rest/test'
* action :status, 'GET /rest/status'

80
## Get started
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
81

82
Some requests requires user authentication.
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
83

84
85
86
87
88
89
90
```ruby
require 'dspace'
client = Dspace::Client.new(dspace_api: 'https://demo.dspace.org/')

if !client.is_running?
  raise 'Can\'t connect to DSpace API.'
end
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
91

92
93
94
95
96
# authenticate
client.login 'dspacedemo+admin@gmail.com', 'dspace'

# create an community
client.communities.create(Dspace::Community.new({'name' => 'Testando'}))
97
98
99

# get a bitstream and your file
bitstream = client.bitstreams.find(id: 20, expand: 'parent')
100
tmp_file = client.bitstreams.retrieve(id: 20) #<Tempfile:/tmp/..._teste.jpg>
101
102
103
104
105
106
107
108

# creating a new bitstream for some item
file = File.new('/your/path/Pictures/Celular/some_book.pdf', 'r')
bitstream = client.items.add_bitstream(file, id: 11, name: 'some_book.pdf', description: 'testing upload a pdf book')

# updating bitstream metadata
bitstream.name = 'new_book_name.pdf'
client.bitstreams.update(bitstream, id: bitstream.id)
109
110
```

111
112
To see more examples, visit our Wiki.

113
## Development
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
114

115
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
116

117
## Contributing
Bruno Nocera Zanette's avatar
Bruno Nocera Zanette committed
118

119
Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration.