Skip to content

Commit

Permalink
Merge pull request #759 from datacite/issue1336_characters_accents
Browse files Browse the repository at this point in the history
Fetch and return characters with accents
  • Loading branch information
jrhoads authored Nov 4, 2021
2 parents 8e1f030 + 5b9fc15 commit 6d72426
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gem "lograge", "~> 0.11.2"
gem "logstash-event", "~> 1.2", ">= 1.2.02"
gem "logstash-logger", "~> 0.26.1"
gem "mailgun-ruby", "~> 1.1", ">= 1.1.8"
gem "maremma", "~> 4.9"
gem "maremma", "~> 4.9.6"
gem "mini_magick", "~> 4.8"
gem "mysql2", "~> 0.5.3"
gem "nokogiri", ">= 1.11.2"
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ GEM
mailgun-ruby (1.2.5)
rest-client (>= 2.0.2)
marcel (1.0.1)
maremma (4.9.5)
maremma (4.9.6)
activesupport (>= 4.2.5)
addressable (>= 2.3.6)
builder (~> 3.2, >= 3.2.2)
Expand Down Expand Up @@ -378,7 +378,7 @@ GEM
nokogiri (1.11.7)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
oj (3.13.2)
oj (3.13.9)
oj_mimic_json (1.0.1)
optimist (3.0.1)
pandoc-ruby (2.1.4)
Expand All @@ -399,7 +399,7 @@ GEM
docopt (~> 0.5)
sysrandom
qonfig (0.26.0)
racc (1.5.2)
racc (1.6.0)
rack (2.2.3)
rack-accept (0.4.5)
rack (>= 0.4)
Expand Down Expand Up @@ -680,7 +680,7 @@ DEPENDENCIES
logstash-event (~> 1.2, >= 1.2.02)
logstash-logger (~> 0.26.1)
mailgun-ruby (~> 1.1, >= 1.1.8)
maremma (~> 4.9)
maremma (~> 4.9.6)
mimemagic (= 0.3.7)
mini_magick (~> 4.8)
mysql2 (~> 0.5.3)
Expand Down Expand Up @@ -722,4 +722,4 @@ DEPENDENCIES
webmock (~> 3.1)

BUNDLED WITH
2.2.19
2.2.30
2 changes: 1 addition & 1 deletion app/models/concerns/modelable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def orcid_as_url(orcid)
end

def orcid_from_url(url)
if %r{\A(?:(http|https)://(orcid.org)/)(.+)\z}.match?(url)
if %r{\A(?:(http|https)://(orcid.org|sandbox.orcid.org)/)(.+)\z}.match?(url)
uri = Addressable::URI.parse(url)
uri.path.gsub(%r{^/}, "").upcase
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def self.gql_query(query, options = {})
query = query.gsub(/citationCount/, "citation_count")
query = query.gsub(/viewCount/, "view_count")
query = query.gsub(/downloadCount/, "download_count")
query = query.gsub("/", '\/')
query = query.gsub("/", "\\/")
end

# turn ids into an array if provided as comma-separated string
Expand Down Expand Up @@ -1055,7 +1055,7 @@ def self.query(query, options = {})
query = query.gsub(/citationCount/, "citation_count")
query = query.gsub(/viewCount/, "view_count")
query = query.gsub(/downloadCount/, "download_count")
query = query.gsub("/", '\/')
query = query.gsub("/", "\\/")
end

# turn ids into an array if provided as comma-separated string
Expand Down
8 changes: 4 additions & 4 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def self.find_by_id(id)
return {} if ror_id.blank?

url = "https://api.ror.org/organizations/#{ror_id}"
response = Maremma.get(url, host: true)
response = Maremma.get(url, host: true, skip_encoding: true)

return {} if response.status != 200

Expand All @@ -40,7 +40,7 @@ def self.find_by_grid_id(id)
return {} if grid_id.blank?

url = "https://api.ror.org/organizations?query=\"#{grid_id}\""
response = Maremma.get(url, host: true)
response = Maremma.get(url, host: true, skip_encoding: true)

message = response.body.dig("data", "items", 0) || {}
return {} if message.empty?
Expand All @@ -66,7 +66,7 @@ def self.find_by_crossref_funder_id(id)
"https://api.ror.org/organizations?query=\"#{
crossref_funder_id.split('/', 2).last
}\""
response = Maremma.get(url, host: true)
response = Maremma.get(url, host: true, skip_encoding: true)

message = response.body.dig("data", "items", 0) || {}
return {} if message.empty?
Expand Down Expand Up @@ -103,7 +103,7 @@ def self.query(query, options = {})
url += "&filter=country.country_code:#{country.upcase}"
end

response = Maremma.get(url, host: true)
response = Maremma.get(url, host: true, skip_encoding: true)

return {} if response.status != 200

Expand Down
14 changes: 8 additions & 6 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ def self.find_by_id(id)
{ data: data, errors: errors }
end

def self.api_url
Rails.env.production? ? "https://pub.orcid.org" : "https://pub.sandbox.orcid.org"
end

def self.query(query, options = {})
options[:limit] ||= 25
options[:offset] ||= 0
api_url = Rails.env.production? ? "https://pub.orcid.org" : "https://pub.sandbox.orcid.org"

params = {
q: query || "*",
Expand All @@ -76,10 +79,10 @@ def self.query(query, options = {})
}.compact

url =
"#{api_url}/v3.0/expanded-search/?" +
"#{self.api_url}/v3.0/expanded-search/?" +
URI.encode_www_form(params)

response = Maremma.get(url, accept: "json")
response = Maremma.get(url, accept: "json", skip_encoding: true)
if response.status >= 400
message =
response.body.dig("errors", 0, "title", "developer-message") ||
Expand All @@ -100,9 +103,8 @@ def self.query(query, options = {})
end

def self.get_orcid(orcid: nil, endpoint: nil)
api_url = Rails.env.production? ? "https://pub.orcid.org" : "https://pub.sandbox.orcid.org"
url = "#{api_url}/v3.0/#{orcid}/#{endpoint}"
response = Maremma.get(url, accept: "json")
url = "#{self.api_url}/v3.0/#{orcid}/#{endpoint}"
response = Maremma.get(url, accept: "json", skip_encoding: true)

if response.status >= 405
message =
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions spec/fixtures/vcr_cassettes/Organization/find_by_id/found_utf8.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

115 changes: 115 additions & 0 deletions spec/fixtures/vcr_cassettes/Person/find_by_id/found_with_utf8.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/graphql/types/organization_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@
organization = response.dig("data", "organizations", "nodes", 0)

expect(organization.fetch("id")).to eq("https://ror.org/01856cw59")
expect(organization.fetch("name")).to eq("University Hospital M??nster")
expect(organization.fetch("name")).to eq("University Hospital Münster")
expect(organization.fetch("types")).to eq(%w[Healthcare])
expect(organization.fetch("country")).to eq(
"id" => "DE", "name" => "Germany",
Expand Down Expand Up @@ -1063,7 +1063,7 @@
organization = response.dig("data", "organizations", "nodes", 0)
expect(organization.fetch("id")).to eq("https://ror.org/04bqwzd17")
expect(organization.fetch("name")).to eq(
"Bayerisches Landesamt f??r Gesundheit und Lebensmittelsicherheit",
"Bayerisches Landesamt für Gesundheit und Lebensmittelsicherheit",
)
expect(organization.fetch("types")).to eq(%w[Government])
expect(organization.fetch("country")).to eq(
Expand Down
Loading

0 comments on commit 6d72426

Please sign in to comment.