Skip to content

Commit

Permalink
remove solr dependency. #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 29, 2018
1 parent 8e79741 commit e1f4c1c
Show file tree
Hide file tree
Showing 325 changed files with 7,854 additions and 6,109 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bolognese (1.0.32)
bolognese (1.0.33)
activesupport (>= 4.2.5, < 6)
benchmark_methods (~> 0.7)
bibtex-ruby (~> 4.1)
Expand Down
8 changes: 4 additions & 4 deletions lib/bolognese/doi_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def doi_resolver(doi, options = {})
sandbox.present? || options[:sandbox] ? "https://handle.test.datacite.org/" : "https://doi.org/"
end

def doi_search(doi, options = {})
def doi_api_url(doi, options = {})
sandbox = Array(/handle.test.datacite.org/.match(doi)).last
sandbox.present? || options[:sandbox] ? "https://search.test.datacite.org/api" : "https://search.datacite.org/api"
sandbox.present? || options[:sandbox] ? "https://api.test.datacite.org/dois/" + doi_from_url(doi) : "https://api.datacite.org/dois/" + doi_from_url(doi)
end

def normalize_doi(doi, options = {})
Expand All @@ -46,10 +46,10 @@ def get_doi_ra(doi)
prefix = validate_prefix(doi)
return nil if prefix.blank?

url = "https://api.datacite.org/prefixes/#{prefix}"
url = "https://doi.org/ra/#{prefix}"
result = Maremma.get(url)

result.body.fetch("data", {}).fetch('attributes', {}).fetch('registration-agency', nil)
result.body.dig("data", 0, "RA")
end
end
end
28 changes: 15 additions & 13 deletions lib/bolognese/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def initialize(input: nil, from: nil, **options)
elsif input.present? && File.exist?(input)
ext = File.extname(input)
if %w(.bib .ris .xml .json).include?(ext)
hsh = { "url" => options[:url],
hsh = {
"url" => options[:url],
"state" => options[:state],
"date_registered" => options[:date_registered],
"date_updated" => options[:date_updated],
Expand All @@ -41,18 +42,19 @@ def initialize(input: nil, from: nil, **options)
exit 1
end
else
hsh = { "url" => options[:url],
"state" => options[:state],
"date_registered" => options[:date_registered],
"date_updated" => options[:date_updated],
"provider_id" => options[:provider_id],
"client_id" => options[:client_id],
"content_url" => options[:content_url],
"creators" => options[:creators],
"contributors" => options[:contributors],
"titles" => options[:titles],
"publisher" => options[:publisher],
"publication_year" => options[:publication_year] }
hsh = {
"url" => options[:url],
"state" => options[:state],
"date_registered" => options[:date_registered],
"date_updated" => options[:date_updated],
"provider_id" => options[:provider_id],
"client_id" => options[:client_id],
"content_url" => options[:content_url],
"creators" => options[:creators],
"contributors" => options[:contributors],
"titles" => options[:titles],
"publisher" => options[:publisher],
"publication_year" => options[:publication_year] }
string = input
@from = from || find_from_format(string: string)
end
Expand Down
26 changes: 12 additions & 14 deletions lib/bolognese/readers/datacite_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ module DataciteReader
def get_datacite(id: nil, **options)
return { "string" => nil, "state" => "not_found" } unless id.present?

search_url = doi_search(id, options)
doi = doi_from_url(id)
params = { q: "doi:#{doi}",
fl: "doi,url,xml,state,allocator_symbol,datacentre_symbol,media,minted,updated",
wt: "json" }
search_url += "?" + URI.encode_www_form(params)

response = Maremma.get search_url
attributes = response.body.dig("data", "response", "docs").first
api_url = doi_api_url(id, options)
response = Maremma.get api_url
attributes = response.body.dig("data", "attributes")
return { "string" => nil, "state" => "not_found" } unless attributes.present?

string = attributes.fetch('xml', nil)
Expand All @@ -34,17 +28,21 @@ def get_datacite(id: nil, **options)
string = doc.to_xml(:indent => 2)
end

content_url = Array.wrap(attributes.fetch("media", nil)).map do |media|
media.split(":", 2).last
client = Array.wrap(response.body.fetch("included", nil)).find { |m| m["type"] == "clients" }
client_id = client.to_h.fetch("id", nil)
provider_id = Array.wrap(client.to_h.fetch("relationships", nil)).find { |m| m["provider"].present? }.to_h.dig("provider", "data", "id")

content_url = attributes.fetch("contentUrl", nil) || Array.wrap(response.body.fetch("included", nil)).select { |m| m["type"] == "media" }.map do |m|
m.dig("attributes", "url")
end.compact

{ "string" => string,
"url" => attributes.fetch("url", nil),
"state" => attributes.fetch("state", nil),
"date_registered" => attributes.fetch("minted", nil),
"date_registered" => attributes.fetch("registered", nil),
"date_updated" => attributes.fetch("updated", nil),
"provider_id" => attributes.fetch("allocator_symbol", nil),
"client_id" => attributes.fetch("datacentre_symbol", nil),
"provider_id" => provider_id,
"client_id" => client_id,
"content_url" => content_url }
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bolognese/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bolognese
VERSION = "1.0.32"
VERSION = "1.0.33"
end
30 changes: 15 additions & 15 deletions spec/doi_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,47 +51,47 @@
end
end

context "doi search" do
context "doi_api_url" do
it "doi" do
doi = "10.5061/DRYAD.8515"
response = subject.doi_search(doi)
expect(response).to eq("https://search.datacite.org/api")
response = subject.doi_api_url(doi)
expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515")
end

it "doi with protocol" do
doi = "doi:10.5061/DRYAD.8515"
response = subject.doi_search(doi)
expect(response).to eq("https://search.datacite.org/api")
response = subject.doi_api_url(doi)
expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515")
end

it "https url" do
doi = "https://doi.org/10.5061/dryad.8515"
response = subject.doi_search(doi)
expect(response).to eq("https://search.datacite.org/api")
response = subject.doi_api_url(doi)
expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515")
end

it "dx.doi.org url" do
doi = "http://dx.doi.org/10.5061/dryad.8515"
response = subject.doi_search(doi)
expect(response).to eq("https://search.datacite.org/api")
response = subject.doi_api_url(doi)
expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515")
end

it "test resolver" do
doi = "https://handle.test.datacite.org/10.5061/dryad.8515"
response = subject.doi_search(doi)
expect(response).to eq("https://search.test.datacite.org/api")
response = subject.doi_api_url(doi)
expect(response).to eq("https://api.test.datacite.org/dois/10.5061/dryad.8515")
end

it "test resolver http" do
doi = "http://handle.test.datacite.org/10.5061/dryad.8515"
response = subject.doi_search(doi)
expect(response).to eq("https://search.test.datacite.org/api")
response = subject.doi_api_url(doi)
expect(response).to eq("https://api.test.datacite.org/dois/10.5061/dryad.8515")
end

it "force test resolver" do
doi = "https://doi.org/10.5061/dryad.8515"
response = subject.doi_search(doi, sandbox: true)
expect(response).to eq("https://search.test.datacite.org/api")
response = subject.doi_api_url(doi, sandbox: true)
expect(response).to eq("https://api.test.datacite.org/dois/10.5061/dryad.8515")
end
end

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit e1f4c1c

Please sign in to comment.