Class: OrcidClient::Notification
- Inherits:
-
Object
- Object
- OrcidClient::Notification
- Defined in:
- lib/orcid_client/notification.rb
Constant Summary collapse
- SCHEMA =
File.("../../../resources/notification_#{API_VERSION}/notification-permission-#{API_VERSION}.xsd", __FILE__)
Constants included from Api
Instance Attribute Summary collapse
-
#doi ⇒ Object
readonly
Returns the value of attribute doi.
-
#intro ⇒ Object
readonly
Returns the value of attribute intro.
-
#notification_access_token ⇒ Object
readonly
Returns the value of attribute notification_access_token.
-
#notification_host ⇒ Object
readonly
Returns the value of attribute notification_host.
-
#orcid ⇒ Object
readonly
Returns the value of attribute orcid.
-
#put_code ⇒ Object
readonly
Returns the value of attribute put_code.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#validation_errors ⇒ Object
readonly
Returns the value of attribute validation_errors.
Instance Method Summary collapse
- #data ⇒ Object
- #has_required_elements? ⇒ Boolean
-
#initialize(doi:, orcid:, notification_access_token:, **options) ⇒ Notification
constructor
A new instance of Notification.
- #insert_authorization_url(xml) ⇒ Object
- #insert_id(xml, id_type, value, relationship) ⇒ Object
- #insert_items(xml) ⇒ Object
- #insert_notification(xml) ⇒ Object
- #insert_notification_intro(xml) ⇒ Object
- #insert_notification_subject(xml) ⇒ Object
- #insert_notification_type(xml) ⇒ Object
- #item_name ⇒ Object
- #item_type ⇒ Object
- #metadata ⇒ Object
- #root_attributes ⇒ Object
- #work_notification_path ⇒ Object
Methods included from Api
#create_external_identifier, #create_notification, #create_work, #delete_external_identifier, #delete_notification, #delete_work, #get_notification, #get_notification_access_token, #get_works, #update_work
Methods included from Date
#get_date_parts, #get_date_parts_from_parts, #get_iso8601_from_epoch, #get_iso8601_from_time, #get_parts_from_date_parts, #get_year_month, #get_year_month_day
Methods included from Author
#get_authors, #get_credit_name, #get_full_name, #get_hashed_authors, #get_name_identifier, #get_one_author, #get_one_hashed_author
Methods included from Metadata
#get_crossref_metadata, #get_datacite_metadata, #get_doi_ra, #get_metadata, #get_orcid_metadata
Constructor Details
#initialize(doi:, orcid:, notification_access_token:, **options) ⇒ Notification
Returns a new instance of Notification.
20 21 22 23 24 25 26 27 28 |
# File 'lib/orcid_client/notification.rb', line 20 def initialize(doi:, orcid:, notification_access_token:, **) @doi = doi @orcid = orcid @notification_access_token = notification_access_token @put_code = .fetch(:put_code, nil) @subject = .fetch(:subject, nil) @intro = .fetch(:intro, nil) @notification_host = [:sandbox] ? 'sandbox.orcid.org' : 'orcid.org' end |
Instance Attribute Details
#doi ⇒ Object (readonly)
Returns the value of attribute doi.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def doi @doi end |
#intro ⇒ Object (readonly)
Returns the value of attribute intro.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def intro @intro end |
#notification_access_token ⇒ Object (readonly)
Returns the value of attribute notification_access_token.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def notification_access_token @notification_access_token end |
#notification_host ⇒ Object (readonly)
Returns the value of attribute notification_host.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def notification_host @notification_host end |
#orcid ⇒ Object (readonly)
Returns the value of attribute orcid.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def orcid @orcid end |
#put_code ⇒ Object (readonly)
Returns the value of attribute put_code.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def put_code @put_code end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def schema @schema end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def subject @subject end |
#validation_errors ⇒ Object (readonly)
Returns the value of attribute validation_errors.
18 19 20 |
# File 'lib/orcid_client/notification.rb', line 18 def validation_errors @validation_errors end |
Instance Method Details
#data ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/orcid_client/notification.rb', line 48 def data return nil unless has_required_elements? Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.send(:'notification:notification', root_attributes) do insert_notification(xml) end end.to_xml end |
#has_required_elements? ⇒ Boolean
44 45 46 |
# File 'lib/orcid_client/notification.rb', line 44 def has_required_elements? doi && item_name end |
#insert_authorization_url(xml) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/orcid_client/notification.rb', line 70 def (xml) xml.send(:'notification:authorization-url') do xml.send(:'notification:path', work_notification_path) xml.send(:'notification:host', notification_host) end end |
#insert_id(xml, id_type, value, relationship) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/orcid_client/notification.rb', line 102 def insert_id(xml, id_type, value, relationship) xml.send(:'common:external-id') do xml.send(:'common:external-id-type', id_type) xml.send(:'common:external-id-value', value) xml.send(:'common:external-id-relationship', relationship) end end |
#insert_items(xml) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/orcid_client/notification.rb', line 89 def insert_items(xml) return nil unless has_required_elements? xml.send(:'notification:items') do xml.send(:'notification:item') do xml.send(:'notification:item-type', item_type) xml.send(:'notification:item-name', item_name) insert_id(xml, "doi", doi, "self") end end end |
#insert_notification(xml) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/orcid_client/notification.rb', line 58 def insert_notification(xml) insert_notification_type(xml) (xml) insert_notification_subject(xml) insert_notification_intro(xml) insert_items(xml) end |
#insert_notification_intro(xml) ⇒ Object
85 86 87 |
# File 'lib/orcid_client/notification.rb', line 85 def insert_notification_intro(xml) xml.send(:'notification:notification-intro', intro) end |
#insert_notification_subject(xml) ⇒ Object
81 82 83 |
# File 'lib/orcid_client/notification.rb', line 81 def insert_notification_subject(xml) xml.send(:'notification:notification-subject', subject) end |
#insert_notification_type(xml) ⇒ Object
66 67 68 |
# File 'lib/orcid_client/notification.rb', line 66 def insert_notification_type(xml) xml.send(:'notification:notification-type', "permission") end |
#item_name ⇒ Object
36 37 38 |
# File 'lib/orcid_client/notification.rb', line 36 def item_name .fetch('title', nil) end |
#item_type ⇒ Object
40 41 42 |
# File 'lib/orcid_client/notification.rb', line 40 def item_type "work" end |
#metadata ⇒ Object
32 33 34 |
# File 'lib/orcid_client/notification.rb', line 32 def ||= (doi, 'datacite') end |
#root_attributes ⇒ Object
110 111 112 113 114 115 |
# File 'lib/orcid_client/notification.rb', line 110 def root_attributes { :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', :'xsi:schemaLocation' => 'http://www.orcid.org/ns/notification ../notification-permission-2.0_rc3.xsd', :'xmlns:common' => 'http://www.orcid.org/ns/common', :'xmlns:notification' => 'http://www.orcid.org/ns/notification' } end |
#work_notification_path ⇒ Object
77 78 79 |
# File 'lib/orcid_client/notification.rb', line 77 def work_notification_path "/oauth/authorize?client_id=#{ENV['ORCID_CLIENT_ID']}&response_type=code&scope=/read-limited%20/activities/update%20/person/update&redirect_uri=#{ENV['REDIRECT_URI']}" end |