Skip to content

Commit

Permalink
Adding sending of XML to datacite
Browse files Browse the repository at this point in the history
Need to update the gem to allow for xml format
  • Loading branch information
carolyncole committed Aug 2, 2022
1 parent 512f182 commit af26b25
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ gem "friendly_id", "~> 5.4.0"

gem "faraday"

gem "datacite"
gem "datacite", :github => 'carolyncole/datacite-ruby', :branch => 'patch-1'

gem "kramdown"

Expand Down
20 changes: 13 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
GIT
remote: https://github.com/carolyncole/datacite-ruby.git
revision: 3c32263dd66db4509ac6e5b643745c3ba83638ba
branch: patch-1
specs:
datacite (0.3.0)
dry-monads (~> 1.3)
faraday (~> 2.0)
json_schema (~> 0.21.0)
zeitwerk (~> 2.4)

GIT
remote: https://github.com/duke-libraries/ezid-client.git
revision: dfcf7f49995560ed48df407560c4fe3fb6dbfa7b
Expand Down Expand Up @@ -152,11 +163,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
datacite (0.3.0)
dry-monads (~> 1.3)
faraday (~> 2.0)
json_schema (~> 0.21.0)
zeitwerk (~> 2.4)
datacite-mapping (0.4.1)
typesafe_enum (~> 0.1, >= 0.1.7)
xml-mapping_extensions (~> 0.4, >= 0.4.7)
Expand All @@ -170,7 +176,7 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.5.0)
docile (1.4.0)
dry-core (0.7.1)
dry-core (0.8.1)
concurrent-ruby (~> 1.0)
dry-monads (1.4.0)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -458,7 +464,7 @@ DEPENDENCIES
capybara (>= 3.26)
coveralls_reborn (~> 0.24)
database_cleaner-active_record
datacite
datacite!
datacite-mapping
devise
ezid-client!
Expand Down
35 changes: 35 additions & 0 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
}
end

let(:xml_attributes) do
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<resource xmlns=\"http://datacite.org/schema/kernel-4\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://datacite.org/schema/kernel-4 http://schema.datacite.org/meta/kernel-4/metadata.xsd\">\r\n\t<identifier identifierType=\"DOI\">10.5438/0012</identifier>" \
"\r\n\t<creators>\r\n\t\t<creator>\r\n\t\t\t<creatorName>DataCite Metadata Working Group</creatorName>\r\n\t\t</creator>\r\n\t</creators>\r\n\t<titles>\r\n\t\t<title>DataCite Metadata Schema Documentation for the Publication and Citation of Research Data v4.0</title>\r\n\t</titles>\r\n\t<publisher>DataCite e.V.</publisher>\r\n\t<publicationYear>2016</publicationYear>" \
"<resourceType resourceTypeGeneral=\"Text\">Documentation</resourceType>\r\n</resource>\r\n"
end

let(:minimum_xml_publish_attributes) do
{
"event" => "publish",
"xml" => Base64.encode64(xml_attributes),
"url" => "https://schema.datacite.org/meta/kernel-4.0/index.html"
}
end

describe "SPIKE" do
it "mints a new DOI" do
stub_datacite(host: "api.datacite.org", body: datacite_register_body(prefix: prefix))
Expand All @@ -57,6 +71,7 @@
->(response) { response.doi },
->(response) { raise("Something went wrong", response.status) }
)
puts doi
expect(doi).to be_present
end

Expand Down Expand Up @@ -123,5 +138,25 @@
)
expect(data["attributes"]["state"]).to eq("findable")
end

it "publishes an existing DOI with xml" do
doi = "10.80021/f91s-fg71"
stub_datacite_update(doi: doi, body: datacite_update_body(attributes: minimum_xml_publish_attributes), fixture: "doi_publish_response.json", host: "api.datacite.org")
#
# Comment out the above stub and uncomment the below code to send a real request and publish a DOI
# you must have the datacite host, user name, and password in your environment
# set the doi above to an unpublished doi
#
# WebMock.enable_net_connect!

# Publish the DOI with the minimum attributes needed to publish the item
result = client.update(id: doi, attributes: minimum_xml_publish_attributes)

data = result.either(
->(response) { response.body["data"] },
->(response) { raise("Something went wrong", response.status) }
)
expect(data["attributes"]["state"]).to eq("findable")
end
end
end

0 comments on commit af26b25

Please sign in to comment.