Skip to content

Commit

Permalink
Make suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastinSanty committed Jun 17, 2018
1 parent 1ab0814 commit c62c626
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/DataCite.jl
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions src/DataDepsGenerators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c62c626

Please sign in to comment.