-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5493 from samvera/geonames_labels
Geonames labels
- Loading branch information
Showing
11 changed files
with
705 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
class LocationService < ::Qa::Authorities::Geonames | ||
CACHE_KEY_PREFIX = 'hyrax_geonames_label-v1-' | ||
CACHE_EXPIRATION = 1.week | ||
|
||
def full_label(uri) | ||
return if uri.blank? | ||
id = extract_id uri | ||
Rails.cache.fetch(cache_key(id), expires_in: CACHE_EXPIRATION) do | ||
label.call(find(id)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def extract_id(obj) | ||
uri = case obj | ||
when String | ||
URI(obj) | ||
when URI | ||
obj | ||
else | ||
raise ArgumentError, "#{obj} is not a valid type" | ||
end | ||
uri.path.split('/').last | ||
end | ||
|
||
def cache_key(id) | ||
"#{CACHE_KEY_PREFIX}#{id}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.