Skip to content
Snippets Groups Projects
Commit 265bab45 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

add link method to dspaceservice

parent 8b5fc080
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ class LearningObject::Attachment
def get_bitstream_retrievelink_of name
values = @bitstreams.select { |v| v["bundleName"] == name }
unless values.empty?
return Dspace::Config.rest_url + values.first["retrieveLink"]
return "#{DspaceService.link}#{values.first["retrieveLink"]}"
end
end
......@@ -29,4 +29,4 @@ class LearningObject::Attachment
end
end
end
\ No newline at end of file
end
class DspaceService
@config = nil
def self.create_client
if Rails.env.production?
link = "https://#{ENV['PORTALMEC_DSPACE_HOST']}:#{ENV['PORTALMEC_DSPACE_PORT']}"
login = ENV['PORTALMEC_DSPACE_LOGIN']
password = ENV['PORTALMEC_DSPACE_PASSWORD']
else
dspace_configs = YAML.load_file(Rails.root.join('config').to_s.concat('/dspace.yml'))
config = dspace_configs.fetch(Rails.env)
config
link = "#{config['host']}:#{config['port']}"
login = config['login']
password = config['password']
end
dspace_client = Dspace::Client.new(dspace_api: @config['link'])
dspace_client.login @config['login'], @config['password']
end
dspace_client = Dspace::Client.new(dspace_api: link)
dspace_client.login login, password
def self.link
config
@config['link']
end
private
def self.config
if @config.nil?
@config = {}
if Rails.env.production?
@config['link'] = "https://#{ENV['PORTALMEC_DSPACE_HOST']}:#{ENV['PORTALMEC_DSPACE_PORT']}"
@config['login'] = ENV['PORTALMEC_DSPACE_LOGIN']
@config['password'] = ENV['PORTALMEC_DSPACE_PASSWORD']
else
yml_file = YAML.load_file(Rails.root.join('config').to_s.concat('/dspace.yml'))
yml = yml_file.fetch(Rails.env)
@config['link'] = "https://#{yml['host']}:#{yml['port']}"
@config['login'] = yml['login']
@config['password'] = yml['password']
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment