diff --git a/src/DataCite.jl b/src/DataCite.jl index 164e858..8169dd5 100644 --- a/src/DataCite.jl +++ b/src/DataCite.jl @@ -1,6 +1,8 @@ struct DataCite <: DataRepo end +base_url(::DataCite) = "https://api.datacite.org/works/" + function description(repo::DataCite, mainpage) attributes = mainpage["attributes"] desc = attributes["description"] @@ -10,7 +12,7 @@ function description(repo::DataCite, mainpage) date = attributes["published"] paper = format_papers(authors, date, attributes["title"] * " [Data set]. " * attributes["container-title"] * ".", mainpage["id"]) - final = escape_multiline_string(""" + escape_multiline_string(""" Author: $(author) License: $(license) Date: $(date) @@ -38,13 +40,13 @@ function data_fullname(::DataCite, mainpage) end function website(repo::DataCite, mainpage_url) - replace(mainpage_url, "https://api.datacite.org/works/", "https://doi.org/") + replace(mainpage_url, base_url(repo), "https://doi.org/") end function mainpage_url(repo::DataCite, dataname) try - identifier = match(r"\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?![\"&\'<>])\S)+)\b", dataname).match - url = "https://api.datacite.org/works/" * identifier + identifier = check_dois(dataname) + url = base_url(repo) * identifier JSON.parse(text_only(getpage(url).root))["data"], url catch ErrorException error("Please use a valid url") diff --git a/src/DataDepsGenerators.jl b/src/DataDepsGenerators.jl index 0c8059b..dd4e43d 100644 --- a/src/DataDepsGenerators.jl +++ b/src/DataDepsGenerators.jl @@ -114,6 +114,11 @@ function format_papers(authors::Vector, year::String, name::String, link::String join(authors, ", ") * " ($year). " * name * " " * link end +function check_dois(uri::String) + identifier = match(r"\b(10[.][0-9]{4,}(?:[.][0-9]+)*\/(?:(?![\"&\'<>])\S)+)\b", uri).match + return identifier +end + website(::DataRepo, mainpage_url) = mainpage_url function mainpage_url(repo::DataRepo, dataname)