Class: Orcid::Profile
- Inherits:
-
Object
- Object
- Orcid::Profile
- Defined in:
- app/models/orcid/profile.rb
Overview
Provides a container around an Orcid Profile and its relation to the Orcid Works.
Instance Attribute Summary collapse
-
#orcid_profile_id ⇒ Object
readonly
Returns the value of attribute orcid_profile_id.
-
#remote_service ⇒ Object
readonly
Returns the value of attribute remote_service.
-
#xml_parser ⇒ Object
readonly
Returns the value of attribute xml_parser.
-
#xml_renderer ⇒ Object
readonly
Returns the value of attribute xml_renderer.
Instance Method Summary collapse
- #append_new_work(*works) ⇒ Object
-
#initialize(orcid_profile_id, config = {}) ⇒ Profile
constructor
A new instance of Profile.
- #remote_works(options = {}) ⇒ Object
- #replace_works_with(*works) ⇒ Object
-
#verified_authentication? ⇒ Boolean
Answers the question: Has the user been authenticated via the ORCID system.
Constructor Details
#initialize(orcid_profile_id, config = {}) ⇒ Profile
Returns a new instance of Profile.
9 10 11 12 13 14 15 16 17 |
# File 'app/models/orcid/profile.rb', line 9 def initialize(orcid_profile_id, config = {}) @orcid_profile_id = orcid_profile_id @mapper = config.fetch(:mapper) { Orcid.mapper } @remote_service = config.fetch(:remote_service) do Orcid::Remote::WorkService end @xml_renderer = config.fetch(:xml_renderer) { Orcid::Work::XmlRenderer } @xml_parser = config.fetch(:xml_parser) { Orcid::Work::XmlParser } end |
Instance Attribute Details
#orcid_profile_id ⇒ Object (readonly)
Returns the value of attribute orcid_profile_id.
5 6 7 |
# File 'app/models/orcid/profile.rb', line 5 def orcid_profile_id @orcid_profile_id end |
#remote_service ⇒ Object (readonly)
Returns the value of attribute remote_service.
5 6 7 |
# File 'app/models/orcid/profile.rb', line 5 def remote_service @remote_service end |
#xml_parser ⇒ Object (readonly)
Returns the value of attribute xml_parser.
5 6 7 |
# File 'app/models/orcid/profile.rb', line 5 def xml_parser @xml_parser end |
#xml_renderer ⇒ Object (readonly)
Returns the value of attribute xml_renderer.
5 6 7 |
# File 'app/models/orcid/profile.rb', line 5 def xml_renderer @xml_renderer end |
Instance Method Details
#append_new_work(*works) ⇒ Object
33 34 35 36 37 |
# File 'app/models/orcid/profile.rb', line 33 def append_new_work(*works) orcid_works = normalize_work(*works) xml = xml_renderer.call(orcid_works) remote_service.call(orcid_profile_id, request_method: :post, body: xml) end |
#remote_works(options = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/models/orcid/profile.rb', line 25 def remote_works( = {}) @remote_works = nil if .fetch(:force, false) @remote_works ||= begin response = remote_service.call(orcid_profile_id, request_method: :get) xml_parser.call(response) end end |
#replace_works_with(*works) ⇒ Object
39 40 41 42 43 |
# File 'app/models/orcid/profile.rb', line 39 def replace_works_with(*works) orcid_works = normalize_work(*works) xml = xml_renderer.call(orcid_works) remote_service.call(orcid_profile_id, request_method: :put, body: xml) end |
#verified_authentication? ⇒ Boolean
Answers the question: Has the user been authenticated via the ORCID system.
21 22 23 |
# File 'app/models/orcid/profile.rb', line 21 def verified_authentication? Orcid.authenticated_orcid?(orcid_profile_id) end |