orcid 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.hound.yml +793 -0
- data/.travis.yml +14 -0
- data/Gemfile +14 -0
- data/README.md +107 -6
- data/Rakefile +17 -9
- data/app/assets/images/orcid/.keep +0 -0
- data/app/controllers/orcid/application_controller.rb +13 -4
- data/app/controllers/orcid/profile_connections_controller.rb +34 -6
- data/app/controllers/orcid/profile_requests_controller.rb +18 -15
- data/app/models/orcid/profile.rb +15 -5
- data/app/models/orcid/profile_connection.rb +20 -20
- data/app/models/orcid/profile_request.rb +39 -20
- data/app/models/orcid/work.rb +45 -55
- data/app/models/orcid/work/xml_parser.rb +45 -0
- data/app/models/orcid/work/xml_renderer.rb +29 -0
- data/app/services/orcid/remote/profile_creation_service.rb +40 -32
- data/app/services/orcid/remote/profile_query_service.rb +82 -0
- data/app/services/orcid/remote/profile_query_service/query_parameter_builder.rb +43 -0
- data/app/services/orcid/remote/profile_query_service/search_response.rb +31 -0
- data/app/services/orcid/remote/service.rb +16 -13
- data/app/services/orcid/remote/work_service.rb +58 -43
- data/app/templates/orcid/work.template.v1.1.xml.erb +32 -1
- data/app/views/orcid/profile_connections/_orcid_connector.html.erb +14 -0
- data/app/views/orcid/profile_connections/new.html.erb +4 -4
- data/bin/rails +8 -0
- data/config/{application.yml → application.yml.example} +3 -13
- data/config/locales/orcid.en.yml +5 -1
- data/config/routes.rb +4 -2
- data/lib/generators/orcid/install/install_generator.rb +46 -7
- data/lib/orcid.rb +23 -11
- data/lib/orcid/configuration.rb +32 -13
- data/lib/orcid/configuration/provider.rb +27 -13
- data/lib/orcid/engine.rb +20 -4
- data/lib/orcid/exceptions.rb +33 -4
- data/lib/orcid/named_callbacks.rb +3 -1
- data/lib/orcid/spec_support.rb +19 -9
- data/lib/orcid/version.rb +1 -1
- data/lib/tasks/orcid_tasks.rake +3 -3
- data/orcid.gemspec +51 -0
- data/rubocop.txt +1164 -0
- data/script/fast_specs +22 -0
- data/spec/controllers/orcid/profile_connections_controller_spec.rb +101 -0
- data/spec/controllers/orcid/profile_requests_controller_spec.rb +116 -0
- data/spec/factories/orcid_profile_requests.rb +11 -0
- data/spec/factories/users.rb +9 -0
- data/spec/fast_helper.rb +12 -0
- data/spec/features/batch_profile_spec.rb +31 -0
- data/spec/features/non_ui_based_interactions_spec.rb +117 -0
- data/spec/features/profile_connection_feature_spec.rb +19 -0
- data/spec/features/public_api_query_spec.rb +36 -0
- data/spec/fixtures/orcid_works.xml +55 -0
- data/spec/lib/orcid/configuration/provider_spec.rb +40 -0
- data/spec/lib/orcid/configuration_spec.rb +38 -0
- data/spec/lib/orcid/named_callbacks_spec.rb +28 -0
- data/spec/lib/orcid_spec.rb +97 -0
- data/spec/models/orcid/profile_connection_spec.rb +81 -0
- data/spec/models/orcid/profile_request_spec.rb +131 -0
- data/spec/models/orcid/profile_spec.rb +76 -0
- data/spec/models/orcid/work/xml_parser_spec.rb +40 -0
- data/spec/models/orcid/work/xml_renderer_spec.rb +18 -0
- data/spec/models/orcid/work_spec.rb +53 -0
- data/spec/services/orcid/remote/profile_creation_service_spec.rb +40 -0
- data/spec/services/orcid/remote/profile_query_service/query_parameter_builder_spec.rb +44 -0
- data/spec/services/orcid/remote/profile_query_service/search_response_spec.rb +14 -0
- data/spec/services/orcid/remote/profile_query_service_spec.rb +118 -0
- data/spec/services/orcid/remote/service_spec.rb +26 -0
- data/spec/services/orcid/remote/work_service_spec.rb +44 -0
- data/spec/spec_helper.rb +99 -0
- data/spec/support/non_orcid_models.rb +11 -0
- data/spec/support/stub_callback.rb +25 -0
- data/spec/test_app_templates/Gemfile.extra +3 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +36 -0
- data/spec/views/orcid/profile_connections/new.html.erb_spec.rb +25 -0
- data/spec/views/orcid/profile_requests/new.html.erb_spec.rb +23 -0
- metadata +119 -29
- data/app/runners/orcid/profile_lookup_runner.rb +0 -33
- data/app/runners/orcid/runner.rb +0 -15
- data/app/services/orcid/remote/profile_lookup_service.rb +0 -56
- data/app/services/orcid/remote/profile_lookup_service/search_response.rb +0 -23
- data/lib/orcid/query_parameter_builder.rb +0 -38
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'orcid/runner'
|
2
|
-
module Orcid
|
3
|
-
class ProfileLookupRunner < Runner
|
4
|
-
|
5
|
-
def initialize(config = {}, &block)
|
6
|
-
super(&block)
|
7
|
-
@query_service = config.fetch(:query_service) { Remote::ProfileLookupService }
|
8
|
-
@query_builder = config.fetch(:query_parameter_builder) {
|
9
|
-
require 'orcid/query_parameter_builder'
|
10
|
-
Orcid::QueryParameterBuilder
|
11
|
-
}
|
12
|
-
end
|
13
|
-
attr_reader :query_service, :query_builder
|
14
|
-
private :query_service, :query_builder
|
15
|
-
|
16
|
-
def call(raw_parameters)
|
17
|
-
query_parameters = query_builder.call(raw_parameters)
|
18
|
-
response = query_service.call(query_parameters)
|
19
|
-
handle(response)
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
def handle(response)
|
24
|
-
if response.any?
|
25
|
-
callback(:found, response)
|
26
|
-
else
|
27
|
-
callback(:not_found)
|
28
|
-
end
|
29
|
-
response
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
data/app/runners/orcid/runner.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require_dependency 'json'
|
2
|
-
module Orcid::Remote
|
3
|
-
class ProfileLookupService
|
4
|
-
|
5
|
-
def self.call(query, config = {})
|
6
|
-
new(config).call(query)
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :token, :path, :headers, :response_builder
|
10
|
-
def initialize(config = {})
|
11
|
-
@token = config.fetch(:token) { Orcid.client_credentials_token('/read-public') }
|
12
|
-
@response_builder = config.fetch(:response_builder) { SearchResponse }
|
13
|
-
@path = config.fetch(:path) { "v1.1/search/orcid-bio/" }
|
14
|
-
@headers = config.fetch(:headers) {
|
15
|
-
{
|
16
|
-
:accept => 'application/orcid+json',
|
17
|
-
'Content-Type'=>'application/orcid+xml'
|
18
|
-
}
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def call(parameters)
|
23
|
-
response = deliver(parameters)
|
24
|
-
parse(response.body)
|
25
|
-
end
|
26
|
-
alias_method :search, :call
|
27
|
-
|
28
|
-
protected
|
29
|
-
attr_reader :host, :access_token
|
30
|
-
def deliver(parameters)
|
31
|
-
token.get(path, headers: headers, params: parameters)
|
32
|
-
end
|
33
|
-
|
34
|
-
def parse(document)
|
35
|
-
json = JSON.parse(document)
|
36
|
-
|
37
|
-
json.fetch('orcid-search-results').fetch('orcid-search-result').each_with_object([]) do |result, returning_value|
|
38
|
-
profile = result.fetch('orcid-profile')
|
39
|
-
identifier = profile.fetch('orcid-identifier').fetch('path')
|
40
|
-
orcid_bio = profile.fetch('orcid-bio')
|
41
|
-
given_names = orcid_bio.fetch('personal-details').fetch('given-names').fetch('value')
|
42
|
-
family_name = orcid_bio.fetch('personal-details').fetch('family-name').fetch('value')
|
43
|
-
emails = []
|
44
|
-
if contact_details = orcid_bio['contact-details']
|
45
|
-
emails = (contact_details['email'] || []).collect {|email| email.fetch('value') }
|
46
|
-
end
|
47
|
-
label = "#{given_names} #{family_name}"
|
48
|
-
label << " (" << emails.join(", ") << ")" if emails.any?
|
49
|
-
label << " [ORCID: #{identifier}]"
|
50
|
-
|
51
|
-
returning_value << response_builder.new("id" => identifier, "label" => label)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
|
2
|
-
module Orcid::Remote
|
3
|
-
class ProfileLookupService
|
4
|
-
class SearchResponse
|
5
|
-
delegate :[], :has_key?, :fetch, to: :@records
|
6
|
-
def initialize(attributes = {})
|
7
|
-
@attributes = attributes.with_indifferent_access
|
8
|
-
end
|
9
|
-
|
10
|
-
def id
|
11
|
-
@attributes.fetch(:id)
|
12
|
-
end
|
13
|
-
|
14
|
-
def orcid_profile_id
|
15
|
-
@attributes.fetch(:id)
|
16
|
-
end
|
17
|
-
|
18
|
-
def label
|
19
|
-
@attributes.fetch(:label)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Orcid
|
2
|
-
# http://support.orcid.org/knowledgebase/articles/132354-searching-with-the-public-api
|
3
|
-
module QueryParameterBuilder
|
4
|
-
|
5
|
-
module_function
|
6
|
-
# Responsible for converting an arbitrary query string to the acceptable
|
7
|
-
# Orcid query format.
|
8
|
-
#
|
9
|
-
# @TODO - Note this is likely not correct, but is providing the singular
|
10
|
-
# point of entry
|
11
|
-
def call(input = {})
|
12
|
-
params = {}
|
13
|
-
q_params = []
|
14
|
-
text_params = []
|
15
|
-
input.each do |key, value|
|
16
|
-
next if value.nil? || value.to_s.strip == ''
|
17
|
-
case key.to_s
|
18
|
-
when 'start', 'row'
|
19
|
-
params[key] = value
|
20
|
-
when 'q', 'text'
|
21
|
-
text_params << "#{value}"
|
22
|
-
else
|
23
|
-
q_params << "#{key.to_s.gsub('_', '-')}:#{value}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
case text_params.size
|
28
|
-
when 0; then nil
|
29
|
-
when 1
|
30
|
-
q_params << "text:#{text_params.first}"
|
31
|
-
else
|
32
|
-
q_params << "text:((#{text_params.join(') AND (')}))"
|
33
|
-
end
|
34
|
-
params[:q] = q_params.join(" AND ")
|
35
|
-
params
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|