orcid 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/.hound.yml +793 -0
  4. data/.travis.yml +14 -0
  5. data/Gemfile +14 -0
  6. data/README.md +107 -6
  7. data/Rakefile +17 -9
  8. data/app/assets/images/orcid/.keep +0 -0
  9. data/app/controllers/orcid/application_controller.rb +13 -4
  10. data/app/controllers/orcid/profile_connections_controller.rb +34 -6
  11. data/app/controllers/orcid/profile_requests_controller.rb +18 -15
  12. data/app/models/orcid/profile.rb +15 -5
  13. data/app/models/orcid/profile_connection.rb +20 -20
  14. data/app/models/orcid/profile_request.rb +39 -20
  15. data/app/models/orcid/work.rb +45 -55
  16. data/app/models/orcid/work/xml_parser.rb +45 -0
  17. data/app/models/orcid/work/xml_renderer.rb +29 -0
  18. data/app/services/orcid/remote/profile_creation_service.rb +40 -32
  19. data/app/services/orcid/remote/profile_query_service.rb +82 -0
  20. data/app/services/orcid/remote/profile_query_service/query_parameter_builder.rb +43 -0
  21. data/app/services/orcid/remote/profile_query_service/search_response.rb +31 -0
  22. data/app/services/orcid/remote/service.rb +16 -13
  23. data/app/services/orcid/remote/work_service.rb +58 -43
  24. data/app/templates/orcid/work.template.v1.1.xml.erb +32 -1
  25. data/app/views/orcid/profile_connections/_orcid_connector.html.erb +14 -0
  26. data/app/views/orcid/profile_connections/new.html.erb +4 -4
  27. data/bin/rails +8 -0
  28. data/config/{application.yml → application.yml.example} +3 -13
  29. data/config/locales/orcid.en.yml +5 -1
  30. data/config/routes.rb +4 -2
  31. data/lib/generators/orcid/install/install_generator.rb +46 -7
  32. data/lib/orcid.rb +23 -11
  33. data/lib/orcid/configuration.rb +32 -13
  34. data/lib/orcid/configuration/provider.rb +27 -13
  35. data/lib/orcid/engine.rb +20 -4
  36. data/lib/orcid/exceptions.rb +33 -4
  37. data/lib/orcid/named_callbacks.rb +3 -1
  38. data/lib/orcid/spec_support.rb +19 -9
  39. data/lib/orcid/version.rb +1 -1
  40. data/lib/tasks/orcid_tasks.rake +3 -3
  41. data/orcid.gemspec +51 -0
  42. data/rubocop.txt +1164 -0
  43. data/script/fast_specs +22 -0
  44. data/spec/controllers/orcid/profile_connections_controller_spec.rb +101 -0
  45. data/spec/controllers/orcid/profile_requests_controller_spec.rb +116 -0
  46. data/spec/factories/orcid_profile_requests.rb +11 -0
  47. data/spec/factories/users.rb +9 -0
  48. data/spec/fast_helper.rb +12 -0
  49. data/spec/features/batch_profile_spec.rb +31 -0
  50. data/spec/features/non_ui_based_interactions_spec.rb +117 -0
  51. data/spec/features/profile_connection_feature_spec.rb +19 -0
  52. data/spec/features/public_api_query_spec.rb +36 -0
  53. data/spec/fixtures/orcid_works.xml +55 -0
  54. data/spec/lib/orcid/configuration/provider_spec.rb +40 -0
  55. data/spec/lib/orcid/configuration_spec.rb +38 -0
  56. data/spec/lib/orcid/named_callbacks_spec.rb +28 -0
  57. data/spec/lib/orcid_spec.rb +97 -0
  58. data/spec/models/orcid/profile_connection_spec.rb +81 -0
  59. data/spec/models/orcid/profile_request_spec.rb +131 -0
  60. data/spec/models/orcid/profile_spec.rb +76 -0
  61. data/spec/models/orcid/work/xml_parser_spec.rb +40 -0
  62. data/spec/models/orcid/work/xml_renderer_spec.rb +18 -0
  63. data/spec/models/orcid/work_spec.rb +53 -0
  64. data/spec/services/orcid/remote/profile_creation_service_spec.rb +40 -0
  65. data/spec/services/orcid/remote/profile_query_service/query_parameter_builder_spec.rb +44 -0
  66. data/spec/services/orcid/remote/profile_query_service/search_response_spec.rb +14 -0
  67. data/spec/services/orcid/remote/profile_query_service_spec.rb +118 -0
  68. data/spec/services/orcid/remote/service_spec.rb +26 -0
  69. data/spec/services/orcid/remote/work_service_spec.rb +44 -0
  70. data/spec/spec_helper.rb +99 -0
  71. data/spec/support/non_orcid_models.rb +11 -0
  72. data/spec/support/stub_callback.rb +25 -0
  73. data/spec/test_app_templates/Gemfile.extra +3 -0
  74. data/spec/test_app_templates/lib/generators/test_app_generator.rb +36 -0
  75. data/spec/views/orcid/profile_connections/new.html.erb_spec.rb +25 -0
  76. data/spec/views/orcid/profile_requests/new.html.erb_spec.rb +23 -0
  77. metadata +119 -29
  78. data/app/runners/orcid/profile_lookup_runner.rb +0 -33
  79. data/app/runners/orcid/runner.rb +0 -15
  80. data/app/services/orcid/remote/profile_lookup_service.rb +0 -56
  81. data/app/services/orcid/remote/profile_lookup_service/search_response.rb +0 -23
  82. 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
@@ -1,15 +0,0 @@
1
- require 'orcid/named_callbacks'
2
- module Orcid
3
- class Runner
4
- def initialize
5
- @callbacks = NamedCallbacks.new
6
- yield(@callbacks) if block_given?
7
- end
8
-
9
- def callback(name, *args)
10
- @callbacks.call(name, *args)
11
- args
12
- end
13
-
14
- end
15
- end
@@ -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