remove files from 1.x.x version

parent c42bc73b
*.gem
/Gemfile.lock
/.bundle
/vendor
/doc
/pkg
/rdoc
/.idea
\ No newline at end of file
# Copyright (C) 2004-2008 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# dspace-rest-client is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# DSpace REST Client
DSpace REST Client is a ruby gem that integrates DSpace servers with your application.
For now, the gem is under development, so some features are missing.
## Example of use:
Login
```ruby
require 'dspace-rest-client'
client = DspaceClient.new('https://demo.dspace.org/rest')
client.login 'dspacedemo+admin@gmail.com', 'dspace'
# check the status after authentication
puts client.status
```
List communities
```ruby
require 'dspace-rest-client'
client = DspaceClient.new('https://demo.dspace.org/rest')
community_repository = client.repository.community_repository
all_communities = community_repository.get_all_communities
all_communities.each do |c|
puts c.name
end
```
#### Bitstreams features:
- √ GET /bitstreams - Return all bitstreams in DSpace.
- √ GET /bitstreams/{bitstream id} - Return bitstream.
- GET /bitstreams/{bitstream id}/policy - Return bitstream policies.
- √ GET /bitstreams/{bitstream id}/retrieve - Return data of bitstream.
- POST /bitstreams/{bitstream id}/policy - Add policy to item. You must post a ResourcePolicy
- PUT /bitstreams/{bitstream id}/data - Update data/file of bitstream. You must put the data
- √ PUT /bitstreams/{bitstream id} - Update metadata of bitstream. You must put a Bitstream, does not alter the file/data
- DELETE /bitstreams/{bitstream id} - Delete bitstream from DSpace.
- DELETE /bitstreams/{bitstream id}/policy/{policy_id} - Delete bitstream policy.
#### Collections features:
- √ GET /communities/{communityId}/collections - Returns array of collections of community.
- √ GET /collections - Return all collections of DSpace in array.
- √ GET /collections/{collectionId} - Return collection with id.
- √ GET /collections/{collectionId}/items - Return all items of collection.
- √ POST /communities/{communityId}/collections - Create new collections in community. You must post Collection.
- √ POST /collections/{collectionId}/items - Create posted item in collection. You must post an Item
- POST /collections/find-collection - Find collection by passed name.
- PUT /collections/{collectionId} - Update collection. You must put Collection.
- DELETE /collections/{collectionId} - Delete collection from DSpace.
- DELETE /collections/{collectionId}/items/{itemId} - Delete item in collection.
- DELETE /communities/{communityId}/collections/{collectionId} - Delete collection in community.
#### Community features:
- √ 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.
#### Item features:
- √ GET /items - Return list of items.
- √ GET /items/{item id} - Return item.
- √ GET /items/{item id}/metadata - Return item metadata.
- √ GET /items/{item id}/bitstreams - Return item bitstreams.
- 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
- √ POST /items/{item id}/metadata - Add metadata to item. You must post an array of MetadataEntry
- √ POST /items/{item id}/bitstreams - Add bitstream to item. You must post a Bitstream
- √ PUT /items/{item id}/metadata - Update metadata in item. You must put a MetadataEntry
- √ DELETE /items/{item id} - Delete item.
- DELETE /items/{item id}/metadata - Clear item metadata.
- DELETE /items/{item id}/bitstreams/{bitstream id} - Delete item bitstream.
### Version
1.0.0
### Contributors
> - Mauricio Giacomini Girardello <mgg12@inf.ufpr.br>
> - Bruno Zanette <>
### Installation
You need compile the gem:
```sh
$ gem build dspace-rest-client.gemspec
```
To install:
```sh
gem install --local dspace-rest-client-1.0.0.gem
```
### Development
Want to contribute? Great!
...
License
----
MIT
**Free Software, Hell Yeah!**
\ No newline at end of file
---
:rubygems_api_key: cfa0bd29364baee94fbf1ab847955136
Gem::Specification.new do |s|
s.name = 'dspace_rest_client'
s.version = '1.1.3'
s.date = '2015-09-08'
s.summary = "DSpace REST-API Client for Ruby!"
s.description = "DSpace REST-API Client for Ruby! Implements all DSpace REST-API endpoints requests."
s.authors = ["Mauricio Giacomini Girardello", "Bruno Nocera Zanette", "Mateus Rambo Strey"]
s.email = 'c3sl@c3sl.ufpr.br'
s.files = Dir['lib/*.rb'] +
Dir['lib/dspacerest/*.rb'] +
Dir['lib/dspacerest/repositories/*.rb'] +
Dir['lib/dspacerest/builders/*.rb'] +
Dir['lib/dspacerest/strategies/uploads/*.rb'] +
Dir['bin/*']
#s.files = `git ls-files -z`.split("\0")
#s.test_files = `git ls-files -z spec/`.split("\0")
s.homepage = 'https://gitlab.c3sl.ufpr.br/c3sl/dspace-rest-client'
s.license = 'GNU General Public License'
s.add_dependency('rest-client', '>= 1.7', '< 2')
s.add_dependency('curb', '~> 0.8.6')
end
require_relative 'lib/dspace_rest_client'
require 'json'
client = DspaceClient.new('https://demo.dspace.org/rest')
puts '#### status ####'
puts client.status
client.login 'dspacedemo+admin@gmail.com', 'dspace'
puts '#### after login ####'
puts client.status
puts '#### counting communities ####'
community_repository = client.repository.community_repository
all_communities = community_repository.get_all_communities
i = 0
all_communities.each do
i += 1
end
puts "dspace have #{i} communities"
puts '#### get all items by limit/offset ####'
item_repository = client.repository.item_repository
limit = 5
offset = 0
all_items = item_repository.get_all_items('',limit,offset)
while !all_items.nil?
puts "LIMIT: #{limit} / OFFSET: #{offset}"
all_items.each do |i|
puts i.name
end
offset = offset + limit
all_items = item_repository.get_all_items('',limit,offset)
end
#!/bin/bash
gemspec_file='dspace_rest_client.gemspec'
if [ ! -e ${gemspec_file} ]; then
echo -e "ERRO! O arquivo ${gemspec_file} nao foi encontrado."
exit 1
fi
name=$(grep -m 1 "s\.name" ${gemspec_file} | cut -d "=" -f2 | sed "s#\ ##g; s#'##g")
version=$(grep -m 1 "s\.version" ${gemspec_file} | cut -d "=" -f2 | sed "s#\ ##g; s#'##g")
gem build ${gemspec_file} && gem install ${name}-${version}.gem
require 'rest-client'
class DspaceClient
attr_reader :rest_client, :url
def initialize(url, authenticated_token = nil)
@url = url
if (authenticated_token.nil?)
@rest_client = build_rest_client url
else
@rest_client = build_rest_client url, rest_dspace_token: authenticated_token
end
end
def repository
@dspace_repository ||= build_repository @rest_client
end
def login(username, password)
user = JSON.generate({
email: username,
password: password
})
# send login request to server and receive the token
authenticated_token = @rest_client['/login'].post user
# overwrite the rest_client and dspace_repository
@rest_client = build_rest_client @url, rest_dspace_token: authenticated_token
@dspace_repository = build_repository @rest_client
authenticated_token
end
def logout
response = JSON.parse @rest_client['/logout'].post []
end
def status
response = JSON.parse @rest_client['/status'].get
end
def test
response = JSON.parse(@rest_client['/test'].get)
end
private
def build_repository(rest_client)
DSpaceRest::Repositories::DspaceRepository.new rest_client
end
def build_rest_client(url, headers={})
RestClient::Resource.new(url,
verify_ssl: OpenSSL::SSL::VERIFY_NONE,
headers: headers.merge(
content_type: :json,
accept: :json
)
)
end
end
# More logical way to require 'dspace-rest-client'
require File.dirname(__FILE__) + '/dspace_client'
require File.dirname(__FILE__) + '/dspacerest/bitstream'
require File.dirname(__FILE__) + '/dspacerest/collection'
require File.dirname(__FILE__) + '/dspacerest/community'
require File.dirname(__FILE__) + '/dspacerest/item'
require File.dirname(__FILE__) + '/dspacerest/metadata'
require File.dirname(__FILE__) + '/dspacerest/repositories/abstract_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/bitstream_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/collection_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/community_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/dspace_repository'
require File.dirname(__FILE__) + '/dspacerest/repositories/item_repository'
require File.dirname(__FILE__) + '/dspacerest/strategies/uploads/curl_strategy'
require File.dirname(__FILE__) + '/dspacerest/strategies/uploads/rest_strategy'
require File.dirname(__FILE__) + '/dspacerest/builders/hash_builder'
require File.dirname(__FILE__) + '/dspacerest/builders/model_builder'
module DSpaceRest
class Bitstream
attr_accessor :name, :bundle_name,
:description, :format, :mime_type
attr_reader :id, :type, :link, :size_bytes,
:parent_object, :retrieve_link, :check_sum,
:sequence_id, :policies
def initialize args
@id = args['id']
@name = args['name']
@type = args['type']
@link = args['link']
@bundle_name = args['bundleName']
@description = args['description']
@format = args['format']
@mime_type = args['mimeType']
@size_bytes = args['sizeBytes']
@parent_object = args['parentObject']
@retrieve_link = args['retrieveLink']
@check_sum = args['checkSum']
@sequence_id = args['sequenceId']
@policies = DSpaceRest::Builders::ModelBuilder.build_policies(args['policies'])
@expand = args['expand']
end
def to_h
h = {
id: @id,
name: @name,
type: @type,
link: @link,
bundleName: @bundle_name,
description: @description,
format: @format,
mimeType: @mime_type,
sizeBytes: @size_bytes,
parentObject: @parent_object,
retrieveLink: @retrieve_link,
checkSum: @check_sum,
sequenceId: @sequence_id,
policies: @policies,
expand: @expand
}
h
end
end
end
module DSpaceRest
module Builders
module HashBuilder
def self.models2hash(list)
hash = []
unless list.nil?
list.each do |m|
hash << m.to_h
end
end
hash
end
end
end
end
module DSpaceRest
module Builders
module ModelBuilder
def self.build_communities(communities=[])
return communities if communities.nil?
colls = []
communities.each do |c|
colls << DSpaceRest::Community.new(c)
end
colls
end
def self.build_collections(collections=[])
return collections if collections.nil?
colls = []
collections.each do |c|
colls << DSpaceRest::Collection.new(c)
end
colls
end
def self.build_items(items=[])
return items if items.nil?
colls = []
items.each do |c|
colls << DSpaceRest::Item.new(c)
end
colls
end
def self.build_bitstreams(bitstreams=[])
return bitstreams if bitstreams.nil?
colls = []
bitstreams.each do |c|
colls << DSpaceRest::Bitstream.new(c)
end
colls
end
def self.build_metadatas(metadatas=[])
return metadatas if metadatas.nil?
colls = []
metadatas.each do |c|
colls << DSpaceRest::Metadata.new(c)
end
colls
end
def self.build_policies(policies=[])
return policies if policies.nil?
colls = []
policies.each do |c|
colls << DSpaceRest::Policy.new(c)
end
colls
end
end
end
end
module DSpaceRest
class Collection
attr_accessor :name, :logo, :license, :copyright_text,
:introductory_text, :short_description, :sidebar_text
attr_reader :id, :handle, :type, :link, :parent_community,
:parent_community_list, :items,
:number_items, :expand
def initialize args
@id = args['id']
@name = args['name']
@handle = args['handle']
@type = args['type']
@link = args['link']
@logo = args['logo']
@license = args['license']
@copyright_text = args['copyrightText']
@introductory_text = args['introductoryText']
@short_description = args['shortDescription']
@sidebar_text = args['sidebarText']
@number_items = args['numberItems']
@expand = args['expand']
@parent_community = DSpaceRest::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
@parent_community_list = DSpaceRest::Builders::ModelBuilder.build_communities(args['parentCommunityList'])
@items = DSpaceRest::Builders::ModelBuilder.build_items(args['items'])
end
def to_h
h = {
id: @id,
name: @name,
handle: @handle,
type: @type,
link: @link,
logo: @logo,
parentCommunity: @parent_community,
parentCommunitList: @parent_community_list,
items: obj2hash(@items),
license: @license,
copyrightText: @copyright_text,
introductoryText: @introductory_text,
shortDescription: @short_description,
sidebarText: @sidebar_text,
numberItems: @number_items,
expand: @expand
}
h
end
private
def obj2hash(list)
DSpaceRest::Builders::HashBuilder.models2hash list
end
end
end
\ No newline at end of file
module DSpaceRest
class Community
attr_accessor :name, :logo, :copyright_text,
:introductory_text, :short_description, :sidebar_text
attr_reader :id, :handle, :type, :link, :parent_community,
:count_items, :sub_communities, :collections, :expand
def initialize(args={})
@id = args['id']
@name = args['name']
@handle = args['handle']
@type = args['type']
@link = args['link']
@logo = args['logo']
@parent_community = DSpaceRest::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
@copyright_text = args['copyrightText']
@introductory_text = args['introductoryText']
@short_description = args['shortDescription']
@sidebar_text = args['sidebarText']
@count_items = args['countItems']
@sub_communities = DSpaceRest::Builders::ModelBuilder.build_communities(args['subcommunities'])
@collections = DSpaceRest::Builders::ModelBuilder.build_collections(args['collections'])
@expand = args['expand']
end
def to_h
h = {
id: @id,
name: @name,
handle: @handle,
type: @type,
link: @link,
logo: @logo,
parentCommunity: @parent_community,
subcommunities: obj2hash(@sub_communities),
collections: obj2hash(@collections),
copyrightText: @copyright_text,
introductoryText: @introductory_text,
shortDescription: @short_description,
sidebarText: @sidebar_text,
countItems: @count_items,
expand: @expand
}
h
end
private
def obj2hash(list)
DSpaceRest::Builders::HashBuilder.models2hash list
end
end
end
require 'curb'
module DSpaceRest
class Item
attr_accessor :name, :archived, :withdrawn
attr_reader :id, :handle, :type, :link, :last_modified, :parent_collection,
:parent_collection_list, :parent_community_list, :bit_streams,
:expand, :metadata
def initialize args
@id = args['id']
@name = args['name']
@handle = args['handle']
@type = args['type']
@link = args['link']
@last_modified = args['lastModified']
@parent_collection = DSpaceRest::Collection.new(args['parentCollection']) unless args['parentCollection'].nil?
@parent_collection_list = DSpaceRest::Builders::ModelBuilder.build_collections(args['parentCollectionList']) || []
@parent_community_list = DSpaceRest::Builders::ModelBuilder.build_communities(args['parentCommunityList']) || []
@bit_streams = DSpaceRest::Builders::ModelBuilder.build_bitstreams(args['bitstreams']) || []
@archived = args['archived']
@withdrawn = args['withdrawn']
@expand = args['expand']
@metadata = DSpaceRest::Builders::ModelBuilder.build_metadatas(args['metadata']) || []
end
def to_h
h = {
id: @id,
name: @name,
handle: @handle,
type: @type,
link: @link,
lastModified: @last_modified,
parentCollection: @parent_collection.to_h,
parentCollectionList: obj2hash(@parent_collection_list),
parentCommunityList: obj2hash(@parent_community_list),
bitstreams: obj2hash(@bit_streams),
archived: @archived,
withdrawn: @withdrawn,
expand: @expand,
metadata: obj2hash(@metadata)
}
h
end
def add_metadata(key, value, language)
m = {}
m['key'] = key
m['value'] = value
m['language'] = language || ""
@metadata << DSpaceRest::Metadata.new(m)
@metadata
end
def reset_metadata
@metadata = []
end
private
def obj2hash(list)
DSpaceRest::Builders::HashBuilder.models2hash list
end
end
end
module DSpaceRest
class Metadata
attr_accessor :key, :value, :language
def initialize args
@key = args['key']
@value = args['value']
@language = args['language'] || nil
end
def to_h
{key: @key, value: @value, language: @language}
end
end
end
module DSpaceRest
class Policy
attr_reader :id, :action, :eperson_id, :group_id,
:resource_id, :resource_type, :rp_description,
:rp_name, :rp_type, :start_date, :end_date
def initialize args
@id = args['id']
@action = args['action']
@eperson_id = args['epersonId']
@group_id = args['groupId']
@resource_id = args['resourceId']
@resource_type = args['resourceType']
@rp_description = args['rpDescription']
@rp_name = args['rpName']
@rp_type = args['rpType']
@start_date = args['startDate']
@end_date = args['endDate']
end
def to_h
h = {
id: @id,
action: @action,
epersonId: @eperson_id,
groupId: @group_id,
resourceId: @resource_id,
resourceType: @resource_type,
rpDescription: @rp_description,
rpName: @rp_name,
rpType: @rp_type,
startDate: @start_date,
endDate: @end_date
}
h
end
end
end
module DSpaceRest
module Repositories
class AbstractRepository
attr_reader :rest_client
def initialize(rest_client)
@rest_client = rest_client
end
protected
def build_query_string(params)
query_string=""
if query_parameters.include? 'limit'
query_string << "limit=#{params[:limit]}&"
end
if query_parameters.include? 'offset'
query_string << "offset=#{params[:offset]}&"
end
expand_string = ""
params[:expand].each do |expand|
if expandable_properties.include? expand
expand_string << "#{expand},"
end
end
query_string << "expand=#{expand_string}"
query_string
end
end
end
end
module DSpaceRest
module Repositories
class BitstreamRepository < AbstractRepository
# Bitstreams are files. They have a filename, size (in bytes), and a file format.
# Typically in DSpace, the Bitstream will the "full text" article, or some other media.
# Some files are the actual file that was uploaded (tagged with bundleName:ORIGINAL),
# others are DSpace-generated files that are derivatives or renditions, such as text-extraction, or thumbnails.
# You can download files/bitstreams.