Class: FAIRChampionHarvester::DOI
- Inherits:
-
Object
- Object
- FAIRChampionHarvester::DOI
- Defined in:
- lib/doi.rb
Class Method Summary collapse
- .check_affiliation_information_from_crossref(doi, meta) ⇒ Object
- .check_affiliation_information_from_datacite(doi, meta) ⇒ Object
- .check_license_information_from_crossref(doi, meta) ⇒ Object
- .check_license_information_from_datacite(doi, meta) ⇒ Object
- .get_funding_information_from_crossref(doi, meta) ⇒ Object
- .get_funding_information_from_datacite(doi, meta) ⇒ Object
- .resolve_doi(guid, meta) ⇒ Object
-
.resolve_doi_to_registration_agency(doi, meta) ⇒ Object
this should only be called AFTER the general resolve above.
Class Method Details
.check_affiliation_information_from_crossref(doi, meta) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/doi.rb', line 99 def self.check_affiliation_information_from_crossref(doi, ) # https://api.crossref.org/works/10.1063/5.0095229 doi.downcase! doi.gsub!(%r{https?://[^/+]/}, "") doi.strip! url = "https://api.crossref.org/works/#{doi}" .comments << "INFO: Looking for affiliation information\n" _headers, body = Core.fetch(guid: url, headers: FAIRChampionHarvester::Utils::AcceptDefaultHeader) # warn "headers #{_headers} #{url}" # abort return false unless body # normal author .comments << "INFO: parsing affiliation info from response\n" json = JSON.parse(body) auths = json.dig("message", "author") auths&.each do |auth| if auth["affiliation"]&.first # cant be empty list .comments << "INFO: At least one author has affiliation information\n" return true end end # grant author # "investigator": [ # { # "given": "Manka", # "family": "Varghese", # "affiliation": [ # { # "name": "University of Washington" # } # ] # }, # ... # "lead-investigator": [ # { # "given": "Jessica", # "family": "Thompson", # "affiliation": [ # { # "name": "University of Washington" # } # ] # } # ], .comments << "INFO: checking for investigator or lead investigator in grant information\n" json = JSON.parse(body) projects = json.dig("message", "project") # returns a list projects&.each do |proj| investigators = proj["investigator"] # two possibilities investigators << proj["lead-investigator"] investigators&.each do |inv| if inv["affiliation"]&.first .comments << "INFO: At least one investigator has affiliation information\n" return true end end end .comments << "WARN: no authors had affiliation information\n" false end |
.check_affiliation_information_from_datacite(doi, meta) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/doi.rb', line 164 def self.check_affiliation_information_from_datacite(doi, ) # https://api.datacite.org/dois/10.15151/ESRF-ES-2303075148 doi.downcase! doi.gsub!(%r{https?://[^/+]/}, "") doi.strip! url = "https://api.datacite.org/dois/#{doi}" .comments << "INFO: Looking for author affiliation information\n" _headers, body = Core.fetch(guid: url, headers: FAIRChampionHarvester::Utils::AcceptDefaultHeader) return false unless body # warn body .comments << "INFO: parsing affiliation info from response\n" data = JSON.parse(body) auths = data.dig("data", "attributes", "creators") auths&.each do |auth| if auth["affiliation"] .comments << "INFO: At least one author has affiliation information\n" return true end end .comments << "WARN: no authors had affiliation information\n" false end |
.check_license_information_from_crossref(doi, meta) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/doi.rb', line 214 def self.check_license_information_from_crossref(doi, ) # https://api.crossref.org/works/10.1063/5.0095229 doi.downcase! doi.gsub!(%r{https?://[^/+]/}, "") doi.strip! url = "https://api.crossref.org/works/#{doi}" .comments << "INFO: Looking for license information\n" _headers, body = Core.fetch(guid: url, headers: FAIRChampionHarvester::Utils::AcceptDefaultHeader) # warn "headers #{_headers} #{url}" # abort return false unless body # normal author .comments << "INFO: parsing license info from response\n" json = JSON.parse(body) lics = json.dig("message", "license") if lics&.first .comments << "INFO: found license information\n" return true end .comments << "WARN: no licsense information found\n" false end |
.check_license_information_from_datacite(doi, meta) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/doi.rb', line 190 def self.check_license_information_from_datacite(doi, ) # https://api.datacite.org/dois/10.15151/ESRF-ES-2303075148 doi.downcase! doi.gsub!(%r{https?://[^/+]/}, "") doi.strip! url = "https://api.datacite.org/dois/#{doi}" .comments << "INFO: Looking for license information\n" _headers, body = Core.fetch(guid: url, headers: FAIRChampionHarvester::Utils::AcceptDefaultHeader) return false unless body # warn body .comments << "INFO: parsing license info from response\n" data = JSON.parse(body) rights = data.dig("data", "attributes", "rightsList") # may return empty list - for a fail if rights&.first .comments << "INFO: license information found\n" return true end .comments << "WARN: no license information found\n" false end |
.get_funding_information_from_crossref(doi, meta) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/doi.rb', line 48 def self.get_funding_information_from_crossref(doi, ) # https://api.crossref.org/works/10.1063/5.0095229 doi.downcase! doi.gsub!(%r{https?://[^/+]/}, "") doi.strip! url = "https://api.crossref.org/works/#{doi}" .comments << "INFO: Looking for funding information\n" _headers, body = Core.fetch(guid: url, headers: FAIRChampionHarvester::Utils::AcceptDefaultHeader) return false unless body .comments << "INFO: parsing funding info from response\n" json = JSON.parse(body) funding_refs = json.dig("message", "funder") first_funding = funding_refs&.dig(0) # safe navigation + dig if first_funding .comments << "INFO: funding info block found\n" first_funding else .comments << "WARN: no funding information block found\n" false end end |
.get_funding_information_from_datacite(doi, meta) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/doi.rb', line 72 def self.get_funding_information_from_datacite(doi, ) # https://api.datacite.org/dois/10.15151/ESRF-ES-2303075148 doi.downcase! doi.gsub!(%r{https?://[^/+]/}, "") doi.strip! url = "https://api.datacite.org/dois/#{doi}" .comments << "INFO: Looking for funding information\n" _headers, body = Core.fetch(guid: url, headers: FAIRChampionHarvester::Utils::AcceptDefaultHeader) return false unless body # warn body .comments << "INFO: parsing funding info from response\n" data = JSON.parse(body) funding_refs = data.dig("data", "attributes", "fundingReferences") first_funding = funding_refs&.dig(0) # safe navigation + dig if first_funding .comments << "INFO: funding info block found\n" first_funding else .comments << "WARN: no funding information block found\n" false end end |
.resolve_doi(guid, meta) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/doi.rb', line 3 def self.resolve_doi(guid, ) guid.downcase! type, url = Core.convertToURL(guid) .guidtype = type if .guidtype.nil? .comments << "INFO: Found a DOI.\n" .comments << "INFO: Attempting to resolve #{url} using HTTP Headers #{FAIRChampionHarvester::Utils::AcceptHeader}.\n" FAIRChampionHarvester::URL.resolve_url(guid: url, meta: , nolinkheaders: false) # specifically metadataguid: link, meta: meta, nolinkheaders: true .comments << "INFO: Attempting to resolve #{url} using HTTP Headers {\"Accept\"=>\"*/*\"}.\n" FAIRChampionHarvester::URL.resolve_url(guid: url, meta: , nolinkheaders: false, headers: { "Accept" => "*/*" }) # whatever is default # CrossRef and DataCite both "intercept" the normal redirect process, when a URI has a content-type # Accept header that they understand. This prevents the owner of the data from providing their own # metadata of that type, when using the DOI as their GUID. Here # we have let the redirect process go all the way to the final URL, and we then # treat that as a new GUID. finalURI = .finalURI.last if finalURI =~ %r{\w+://} .comments << "INFO: DOI resolution captures content-negotiation before reaching final data owner. Now re-attempting the full suite of content negotiation on final redirect URI #{finalURI}.\n" FAIRChampionHarvester::Uri.resolve_uri(finalURI, ) end end |
.resolve_doi_to_registration_agency(doi, meta) ⇒ Object
this should only be called AFTER the general resolve above
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/doi.rb', line 29 def self.resolve_doi_to_registration_agency(doi, ) doi.downcase! doi.gsub!(%r{https?://[^/+]/}, "") doi.strip! url = "https://doi.org/doiRA/#{doi}" .comments << "INFO: Finding DOI registration agency.\n" .comments << "INFO: Attempting to resolve #{url} using HTTP Headers {\"Accept\"=>\"*/*\"}.\n" _headers, body = Core.fetch(guid: url, headers: FAIRChampionHarvester::Utils::AcceptDefaultHeader) if body .comments << "INFO: parsing agency from response\n" json = JSON.parse(body) json.dig(0, "RA") else .comments << "WARN: doiRA did not return JSON. Aborting.\n" false end end |