...
 
Commits (5)
......@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
spec.date = '2016-03-14'
spec.name = "dspace_rest_client"
spec.version = Dspace::VERSION
spec.authors = ["Mauricio Giacomini Girardello", "Lucas Ernesto Kindinger", "Bruno N. Zanette", "Mateus Rambo Strey"]
spec.email = ["mauriciogiacomini4@gmail.com", "kindingerlek@hotmail.com"]
spec.authors = ["Mauricio Giacomini Girardello", "Lucas Ernesto Kindinger", "Bruno Nocera Zanette", "Mateus Rambo Strey"]
spec.email = ["mauriciogiacomini4@gmail.com", "kindingerlek@hotmail.com", "brunonzanette@gmail.com"]
spec.summary = 'DSpace REST API Client for Ruby'
spec.description = 'DSpace REST-API Client for Ruby! Implements all DSpace REST-API endpoints requests.'
spec.homepage = 'https://gitlab.c3sl.ufpr.br/c3sl/dspace-rest-client'
......
......@@ -25,6 +25,10 @@ require_relative "dspace/client"
module Dspace
class NotAuthorizedError < StandardError; end
class NotFoundError < StandardError; end
class MethodNotAllowedError < StandardError; end
class UnsupportedMediaTypeError < StandardError; end
class ServerError < StandardError; end
class InvalidTokenError < StandardError; end
class InvalidCredentialsError < StandardError; end
......
......@@ -15,7 +15,7 @@ module Dspace
@handle = args['handle']
@type = args['type']
@link = args['link']
@logo = args['logo']
@logo = Dspace::Bitstream.new(args['logo']) unless args['logo'].nil?
@license = args['license']
@copyright_text = args['copyrightText'] || args['copyright_text']
@introductory_text = args['introductoryText'] || args['introductory_text']
......
......@@ -13,7 +13,7 @@ module Dspace
@handle = args['handle']
@type = args['type']
@link = args['link']
@logo = args['logo']
@logo = Dspace::Bitstream.new(args['logo']) unless args['logo'].nil?
@parent_community = Dspace::Community.new(args['parentCommunity']) unless args['parentCommunity'].nil?
@copyright_text = args['copyrightText'] || args['copyright_text']
@introductory_text = args['introductoryText'] || args['introductory_text']
......
......@@ -3,9 +3,15 @@ module Dspace
class AuthenticationResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler { |response| raise StandardError, "#{response}" }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :login, 'POST /rest/login' do
body { |email, password| JSON.generate({email: email, password: password}) }
......@@ -16,6 +22,7 @@ module Dspace
body { |object| JSON.generate(object.to_h) }
handler(200, 201, 203, 204) { |response| true }
end
end
end
......
......@@ -3,13 +3,20 @@ module Dspace
class BitstreamResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler { |response| raise StandardError, "#{response}" }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :all, 'GET /rest/bitstreams' do
query_keys :expand, :limit, :offset
handler(200) do |response|
Dspace::Builders::ModelBuilder.build_items(JSON.parse(response.body))
Dspace::Builders::ModelBuilder.build_bitstreams(JSON.parse(response.body))
end
end
......
......@@ -3,8 +3,15 @@ module Dspace
class CollectionResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler { |response| raise StandardError, "#{response}" }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :all, 'GET /rest/collections' do
query_keys :expand, :limit, :offset
......
......@@ -3,8 +3,15 @@ module Dspace
class CommunityResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler { |response| raise StandardError, "#{response}" }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :all, 'GET /rest/communities' do
query_keys :expand, :limit, :offset
......
......@@ -3,8 +3,15 @@ module Dspace
class ItemResource < ResourceKit::Resource
resources do
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler { |response| raise StandardError, "#{response}" }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :all, 'GET /rest/items' do
query_keys :expand, :limit, :offset
......@@ -64,7 +71,7 @@ module Dspace
end
action :update_metadata, 'PUT /rest/items/:id/metadata' do
body { |object| JSON.generate(object.to_h) }
body { |object| JSON.generate(Dspace::Builders::ModelBuilder.models2hash(object))}
handler(200, 201) { |response| true }
end
......
......@@ -3,7 +3,15 @@ module Dspace
class StatusResource < ResourceKit::Resource
resources do
default_handler { |response| raise StandardError, "#{response}" }
default_handler(400) { raise InvalidTokenError, 'Invalid access token.' }
default_handler(403) { raise InvalidCredentialsError, 'Wrong Dspace credentials.' }
default_handler(401) { raise NotAuthorizedError, 'This request requires authentication' }
default_handler(404) { raise NotFoundError, 'The specified object doesn\'t exist' }
default_handler(405) { raise MethodNotAllowedError, 'Wrong request method (GET,POST,PUT,DELETE) or wrong data format (JSON/XML)' }
default_handler(415) { raise UnsupportedMediaTypeError, 'Missing "Content-Type: application/json" or "Content-Type: application/xml" request header' }
default_handler(500) { raise ServerError, 'Likely a SQLException, IOException, more details in the logs' }
default_handler { |response| raise StandardError, "#{response.inspect}" }
action :test, 'GET /rest/test' do
handler(200, 201) { |response| true }
......
module Dspace
VERSION = "2.2.7"
VERSION = "2.2.9"
end
......@@ -23,7 +23,7 @@ RSpec.describe Dspace::Resources::CommunityResource, resource_kit: true do
it 'create a new top-level community' do
expect(resource).to have_action(:create).that_handles(200, 201).at_path('/rest/communities').with_verb(:post) do |handled|
expect(handled).to eq(true)
expect(handled).to be_kind_of(Dspace::Community)
end
end
......@@ -49,7 +49,7 @@ RSpec.describe Dspace::Resources::CommunityResource, resource_kit: true do
it 'create a sub-community' do
expect(resource).to have_action(:create_subcommunity).that_handles(200, 201).at_path('/rest/communities/:id/communities').with_verb(:post) do |handled|
expect(handled).to eq(true)
expect(handled).to be_kind_of(Dspace::Community)
end
end
......@@ -61,7 +61,7 @@ RSpec.describe Dspace::Resources::CommunityResource, resource_kit: true do
it 'create a collection' do
expect(resource).to have_action(:create_collection).that_handles(200, 201).at_path('/rest/communities/:id/collections').with_verb(:post) do |handled|
expect(handled).to eq(true)
expect(handled).to be_kind_of(Dspace::Collection)
end
end
......@@ -78,4 +78,4 @@ RSpec.describe Dspace::Resources::CommunityResource, resource_kit: true do
end
end
end
\ No newline at end of file
end