Skip to content

Commit

Permalink
added compatibility for usernam password
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Sep 19, 2018
1 parent 8986883 commit ba5ff0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/cirneco/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
Expand Down
4 changes: 3 additions & 1 deletion lib/cirneco/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit ba5ff0e

Please sign in to comment.