From ba5ff0eef2a180e9a23702b07d374a8f79c7b1ed Mon Sep 17 00:00:00 2001 From: Kristian Garza Date: Wed, 19 Sep 2018 23:00:46 +0200 Subject: [PATCH] added compatibility for usernam password --- lib/cirneco/api.rb | 8 ++++++-- lib/cirneco/doi.rb | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/cirneco/api.rb b/lib/cirneco/api.rb index a9a32b5..6a387d0 100644 --- a/lib/cirneco/api.rb +++ b/lib/cirneco/api.rb @@ -22,12 +22,16 @@ def put_metadata(doi, options={}) end def transfer_doi(doi, options={}) - return OpenStruct.new(body: { "errors" => [{ "title" => "JWT missing" }] }) unless options[:jwt].present? + return OpenStruct.new(body: { "errors" => [{ "title" => "JWT or Username or password missing" }] }) unless options[:jwt].present? || (options[:username].present? && options[:password].present?) api_url = options[:sandbox] ? 'https://api.test.datacite.org' : 'https://api.datacite.org' url = URI.encode("#{api_url}/dois/#{doi}") - Maremma.patch(url, content_type: 'application/vnd.api+json;charset=UTF-8', data: options[:data], bearer: options[:jwt]) + if options[:jwt].present? + Maremma.patch(url, content_type: 'application/vnd.api+json;charset=UTF-8', data: options[:data], bearer: options[:jwt]) + else + Maremma.patch(url, content_type: 'application/vnd.api+json;charset=UTF-8', data: options[:data], username: options[:username], password: options[:password]) + end end def get_metadata(doi, options={}) diff --git a/lib/cirneco/doi.rb b/lib/cirneco/doi.rb index d665b28..6a3e4ab 100644 --- a/lib/cirneco/doi.rb +++ b/lib/cirneco/doi.rb @@ -114,9 +114,11 @@ def check(doi) end desc "transfer DOIs", "transfer list of DOIs" - method_option :jwt, :default => ENV['JWT'] method_option :target, :type => :string + method_option :username, :default => ENV['MDS_USERNAME'] + method_option :password, :default => ENV['MDS_PASSWORD'] method_option :sandbox, :type => :boolean, :force => false + method_option :jwt, :default => ENV['JWT'] def transfer(file) count = 0 File.foreach(file) do |line|