first commit of second version

parent 158625b2
Gem::Specification.new do |s|
s.name = 'dspace_rest_client'
s.version = '1.1.2'
s.version = '2.0.0'
s.date = '2015-05-22'
s.summary = "DSpace REST-API Client for Ruby!"
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 N. 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.files = `git ls-files -z`.split("\0")
s.test_files = `git ls-files -z test/`.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
......@@ -27,7 +27,7 @@ module DSpaceRest
end
def to_h
h = {
{
id: @id,
name: @name,
type: @type,
......@@ -44,8 +44,6 @@ module DSpaceRest
policies: @policies,
expand: @expand
}
h
end
end
end
module Dspace
class Client
def initialize(url, authenticated_token = nil)
@url = url
@authenticated_token = authenticated_token
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
JSON.parse @rest_client['/logout'].post []
end
def status
JSON.parse @rest_client['/status'].get
end
def test
JSON.parse(@rest_client['/test'].get)
end
end
end
......@@ -29,7 +29,7 @@ module DSpaceRest
end
def to_h
h = {
{
id: @id,
name: @name,
handle: @handle,
......@@ -47,8 +47,6 @@ module DSpaceRest
numberItems: @number_items,
expand: @expand
}
h
end
private
......
......@@ -26,7 +26,7 @@ module DSpaceRest
end
def to_h
h = {
{
id: @id,
name: @name,
handle: @handle,
......@@ -43,8 +43,6 @@ module DSpaceRest
countItems: @count_items,
expand: @expand
}
h
end
private
......
......@@ -27,7 +27,7 @@ module DSpaceRest
end
def to_h
h = {
{
id: @id,
name: @name,
handle: @handle,
......@@ -43,8 +43,6 @@ module DSpaceRest
expand: @expand,
metadata: obj2hash(@metadata)
}
h
end
def add_metadata(key, value, language)
......
module DSpaceRest
class Metadata
attr_accessor :key, :value, :language
def initialize args
......
......@@ -20,7 +20,7 @@ module DSpaceRest
end
def to_h
h = {
{
id: @id,
action: @action,
epersonId: @eperson_id,
......@@ -33,8 +33,6 @@ module DSpaceRest
startDate: @start_date,
endDate: @end_date
}
h
end
end
......
module Dspace
#the current dspace-rest-client version
VERSION = '2.0.0'
end
\ No newline at end of file
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment