diff --git a/Gemfile b/Gemfile index df6f772a13e2f24f311b16eb7f0ede426128f59a..89bbc1d17c5685b3ff993cb8ca1f209b8371f193 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,8 @@ gem "font-awesome-sass" gem "front_matter_parser" gem "gdpr" gem "gitlab" +gem "hal_openscience", "~> 0.1" +# gem "hal_openscience", path: "../hal_openscience" gem "has_scope", "~> 0.8.0" gem "hash_dot" gem "image_processing" diff --git a/Gemfile.lock b/Gemfile.lock index 7bc762f5d2d38bf20f70172f112b20353a54a7f3..31e6773bd491520519a0a5e7e206ff882b896a8d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -226,6 +226,10 @@ GEM terminal-table (>= 1.5.1) globalid (1.0.0) activesupport (>= 5.0) + hal_openscience (0.1.0) + json + net-http + open-uri has_scope (0.8.0) actionpack (>= 5.2) activesupport (>= 5.2) @@ -307,6 +311,8 @@ GEM mustermann (3.0.0) ruby2_keywords (~> 0.0.1) nesty (1.0.2) + net-http (0.3.2) + uri net-imap (0.3.4) date net-protocol @@ -343,6 +349,10 @@ GEM omniauth-saml (2.1.0) omniauth (~> 2.0) ruby-saml (~> 1.12) + open-uri (0.3.0) + stringio + time + uri orm_adapter (0.5.0) pg (1.4.5) popper_js (2.11.6) @@ -464,10 +474,13 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + stringio (3.0.4) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) thor (1.2.1) tilt (2.0.11) + time (0.2.1) + date timeout (0.3.1) typhoeus (1.4.0) ethon (>= 0.9.0) @@ -482,6 +495,7 @@ GEM faraday-multipart (~> 1.0.4) httparty (~> 0.20) oauth2 (>= 2.0.8) + uri (0.12.0) vcr (6.1.0) version_gem (1.1.1) warden (1.2.9) @@ -543,6 +557,7 @@ DEPENDENCIES front_matter_parser gdpr gitlab + hal_openscience (~> 0.1) has_scope (~> 0.8.0) hash_dot image_processing diff --git a/app/models/university/person/with_research.rb b/app/models/university/person/with_research.rb index b48259c8af9bda29f01d7dc6ac8601739d3d5952..1a22cae8104ae5bdaa684bfb681c04e47eb86d62 100644 --- a/app/models/university/person/with_research.rb +++ b/app/models/university/person/with_research.rb @@ -7,16 +7,16 @@ module University::Person::WithResearch def load_research_documents! return unless hal_person_identifier.present? - url = "https://api.archives-ouvertes.fr/search/?q=authIdPerson_i:#{hal_person_identifier}&fl=docid,title_s,citationRef_s,uri_s&rows=1000" - uri = URI(url) - response = Net::HTTP.get(uri) - data = JSON.parse(response) - data['response']['docs'].each do |doc| - docid = doc['docid'] - document = Research::Document.where(university: university, person: self, docid: docid).first_or_create - document.title = doc['title_s'][0] - document.ref = doc['citationRef_s'] - document.url = doc['uri_s'] + response = HalOpenscience::Document.search_by_person_id( + hal_person_identifier, + fields: ["docid", "title_s", "citationRef_s", "uri_s"], + limit: 1000 + ) + response.results.each do |doc| + document = Research::Document.where(university: university, person: self, docid: doc.docid).first_or_create + document.title = doc.title_s[0] + document.ref = doc.citationRef_s + document.url = doc.uri_s document.save end end