class Metamatter::Authors
Attributes
repository[RW]
Public Class Methods
new(repository)
click to toggle source
# File lib/metamatter/authors.rb, line 11 def initialize(repository) @repository = repository end
Public Instance Methods
github_response()
click to toggle source
# File lib/metamatter/authors.rb, line 72 def github_response @contributors_response ||= client.contributors(repository.name_with_owner) end
list()
click to toggle source
# File lib/metamatter/authors.rb, line 15 def list authors = [] contribs = github_response contribs.each do |c| user = client.user(c.login) orcid = lookup_orcid(user.name) authors << {:name => user.name, :orcid => orcid, :email => user.email, :login => user.login, :contributions => c.contributions} end return authors.sort_by { |a| a[:contributions] }.reverse end
log_orcids(orcids)
click to toggle source
# File lib/metamatter/authors.rb, line 67 def log_orcids(orcids) puts "Warning: More than one ORCID from search returned" orcids.each { |orcid| puts orcid } end
lookup_orcid(name)
click to toggle source
# File lib/metamatter/authors.rb, line 28 def lookup_orcid(name) return "" unless name family_name = name.split(' ').last given_names = name.gsub(family_name, '').strip # hackety hack hack url = orcid_search_url(given_names, family_name) begin response = HTTParty.get(url, :headers => { "Accept" => "application/json"}).body rescue => e response = {} end orcids = orcids_for(response) if orcids.empty? return nil else return orcids.first end end
orcid_search_url(given_names, family_name)
click to toggle source
# File lib/metamatter/authors.rb, line 49 def orcid_search_url(given_names, family_name) "https://orcid.org/v1.2/search/orcid-bio/?q=given-names%3A#{given_names}%20AND%20family-name%3A#{family_name}&rows=50" end
orcids_for(response)
click to toggle source
# File lib/metamatter/authors.rb, line 53 def orcids_for(response) parsed = JSON.parse(response) return nil unless parsed["orcid-search-results"] results = parsed["orcid-search-results"]["orcid-search-result"] return nil if results.empty? detected_orcids = Array(results).map do |result| orcid = result['orcid-profile']['orcid-identifier'].fetch("path", nil) end.compact log_orcids(detected_orcids) if detected_orcids.size > 1 return detected_orcids end