-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updating unpaywall_last_checked_at whenever a publications is checked regardless of doi or title match (since we are now checking all publications no matter what). Requiring title match for oa status update. * niftany
- Loading branch information
Showing
6 changed files
with
183 additions
and
163 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,8 @@ def update_publication(publication, unpaywall_json) | |
unpaywall_locations = unpaywall_json['oa_locations'].presence || [] | ||
existing_doi = true | ||
else | ||
unpaywall_title = unpaywall_json['results'].nil? ? '' : unpaywall_json['results'].first['response']['title'] | ||
unpaywall_result = unpaywall_json['results'].nil? ? '' : unpaywall_json['results'].first | ||
unpaywall_title = unpaywall_result.present? ? unpaywall_result['response']['title'] : '' | ||
unpaywall_locations = if title_match?(unpaywall_title, publication.title) | ||
publication.doi = DOISanitizer.new(unpaywall_json['results'].first['response']['doi']).url | ||
unpaywall_json['results'].first['response']['oa_locations'].presence || [] | ||
|
@@ -95,14 +96,13 @@ def update_publication(publication, unpaywall_json) | |
|
||
publication.open_access_status = if existing_doi | ||
unpaywall_json['oa_status'] | ||
else | ||
unpaywall_json['results'].nil? ? nil : unpaywall_json['results'].first['response']['oa_status'] | ||
elsif title_match?(unpaywall_title, publication.title) | ||
unpaywall_result = unpaywall_json['results'].nil? ? nil : unpaywall_json['results'].first | ||
unpaywall_result.present? ? unpaywall_result['response']['oa_status'] : nil | ||
end | ||
publication.unpaywall_last_checked_at = Time.zone.now | ||
|
||
if publication.doi.present? || title_match?(unpaywall_title, publication.title) | ||
publication.save! | ||
end | ||
publication.save! | ||
end | ||
end | ||
|
||
|
@@ -111,7 +111,7 @@ def query_unpaywall_for(publication) | |
doi_url_path = Addressable::URI.encode(publication.doi_url_path) | ||
find_url = "https://api.unpaywall.org/v2/#{doi_url_path}[email protected]" | ||
else | ||
find_url = "https://api.unpaywall.org/v2/search/?query=#{publication.title}&[email protected]" | ||
find_url = "https://api.unpaywall.org/v2/search/?query=#{CGI.escape(publication.title)}&[email protected]" | ||
end | ||
|
||
JSON.parse(HttpService.get(find_url)) | ||
|
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.