Skip to content

Commit ab72146

Browse files
ROR V2 API changes (#223)
* ROR V2 API changes * Fixed VCR cassettes * Deleted unused files * Fixed Affiliation identifier vcr * Added comment for V2 API change * Use ror_display instead of label
1 parent 1df370d commit ab72146

14 files changed

Lines changed: 92 additions & 708 deletions

File tree

app/models/affiliation_identifier.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,30 @@ def self.push_item(item)
134134
def self.get_ror_metadata(id)
135135
return {} if id.blank?
136136

137-
url = "https://api.ror.org/v1/organizations/#{id[8..]}"
137+
url = "https://api.ror.org/v2/organizations/#{id.delete_prefix('https://ror.org/')}"
138138
response = Maremma.get(url, host: true)
139139
return {} if response.status != 200
140140

141141
message = response.body.fetch("data", {})
142142

143+
# ROR v2 replaced the single "name" field with a "names" array.
144+
# Prefer long-form, human-readable names (type: "ror_display") over short forms like "EBI".
145+
# Fallback to "alias" or "primary" if no "ror_display" exists.
146+
147+
name_entry = message["names"].find { |n| n["types"].include?("ror_display") } ||
148+
message["names"].find { |n| n["types"].include?("alias") } ||
149+
message["names"].find { |n| n["types"].include?("primary") } ||
150+
message["names"].first
151+
143152
location = {
144153
"type" => "postalAddress",
145-
"addressCountry" => message.dig("country", "country_name"),
154+
"addressCountry" => message.dig("locations", 0, "geonames_details", "country_name"),
146155
}
147156

148157
{
149158
"@id" => id,
150159
"@type" => "Organization",
151-
"name" => message["name"],
160+
"name" => name_entry&.dig("value"),
152161
"location" => location,
153162
}.compact
154163
end

app/models/orcid_affiliation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def self.push_item(item)
141141
def self.get_ror_metadata(id)
142142
return {} if id.blank?
143143

144-
url = "https://api.ror.org/v1/organizations/#{id[8..]}"
144+
url = "https://api.ror.org/v2/organizations/#{id[8..]}"
145145
response = Maremma.get(url, host: true)
146146
return {} if response.status != 200
147147

spec/fixtures/vcr_cassettes/AffiliationIdentifier/import_affiliation_identifiers/_get_ror_metadata/returns_ROR_metadata_for_a_given_ROR_ID.yml

Lines changed: 25 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/vcr_cassettes/AffiliationIdentifier/import_affiliation_identifiers/_import/queues_jobs_for_DOIs_created_within_the_specified_date_range.yml

Lines changed: 11 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/vcr_cassettes/AffiliationIdentifier/import_affiliation_identifiers/fetch_ror_metadata.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

spec/fixtures/vcr_cassettes/AffiliationIdentifier/import_affiliation_identifiers/import.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

spec/fixtures/vcr_cassettes/AffiliationIdentifier/import_affiliation_identifiers/import_zero.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)