Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test datacite metadata and coin
#! /usr/bin/perl
use LWP;
use Crypt::SSLeay;
use utf8;
binmode(STDOUT,'utf8');
$user_name="<YOUR_USER>";
$user_pw="<YOUR_PASSW>";
$url="https://mds.test.datacite.org/";
$doi="10.5072/TEST/T2/89";
$doiurl="http://domain_of_VALID_URL";
$xml= <<EOXML;
<resource xmlns="http://datacite.org/schema/kernel-2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-2.2 http://schema.datacite.org/meta/kernel-2.2/metadata.xsd">
<identifier identifierType="DOI">$doi</identifier>
<creators>
<creator>
<creatorName>test, test</creatorName>
</creator>
</creators>
<titles>
<title>
my test title
</title>
</titles>
<publisher>Publ test</publisher>
<publicationYear>2006</publicationYear>
<resourceType resourceTypeGeneral="Text">BookSection</resourceType>
<alternateIdentifiers>
<alternateIdentifier alternateIdentifierType="URL">http://www.test.it/89/</alternateIdentifier>
</alternateIdentifiers>
</resource>
EOXML
$res=datacite_request("POST", $url."metadata", $user_name, $user_pw, $xml, "application/xml;charset=UTF-8");
print $res->as_string;
my $doi_reg = "doi=$doi\nurl=".$doiurl;
$res=datacite_request("POST", $url."doi", $user_name, $user_pw, $doi_reg, "text/plain;charset=UTF-8");
print $res->as_string;
sub datacite_request {
my ($method, $url, $user_name, $user_pw, $content, $content_type) = @_;
my $headers = HTTP::Headers->new(
'Accept' => 'application/xml',
'Content-Type' => $content_type
);
my $req = HTTP::Request->new(
$method => $url,
$headers, $content
);
$req->authorization_basic($user_name, $user_pw);
my $ua = LWP::UserAgent->new;
my $res = $ua->request($req);
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.