class OrcidClient::Notification
Constants
- SCHEMA
Attributes
doi[R]
intro[R]
notification_access_token[R]
notification_host[R]
orcid[R]
put_code[R]
schema[R]
subject[R]
validation_errors[R]
Public Class Methods
new(doi:, orcid:, notification_access_token:, **options)
click to toggle source
# File lib/orcid_client/notification.rb, line 18 def initialize(doi:, orcid:, notification_access_token:, **options) @doi = doi @orcid = orcid @notification_access_token = notification_access_token @put_code = options.fetch(:put_code, nil) @subject = options.fetch(:subject, nil) @intro = options.fetch(:intro, nil) @notification_host = options[:sandbox] ? 'sandbox.orcid.org' : 'orcid.org' end
Public Instance Methods
data()
click to toggle source
# File lib/orcid_client/notification.rb, line 46 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?()
click to toggle source
# File lib/orcid_client/notification.rb, line 42 def has_required_elements? doi && item_name end
insert_id(xml, id_type, value, relationship)
click to toggle source
# File lib/orcid_client/notification.rb, line 100 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)
click to toggle source
# File lib/orcid_client/notification.rb, line 87 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)
click to toggle source
# File lib/orcid_client/notification.rb, line 56 def insert_notification(xml) insert_notification_type(xml) insert_authorization_url(xml) insert_notification_subject(xml) insert_notification_intro(xml) insert_items(xml) end
insert_notification_intro(xml)
click to toggle source
# File lib/orcid_client/notification.rb, line 83 def insert_notification_intro(xml) xml.send(:'notification:notification-intro', intro) end
insert_notification_subject(xml)
click to toggle source
# File lib/orcid_client/notification.rb, line 79 def insert_notification_subject(xml) xml.send(:'notification:notification-subject', subject) end
insert_notification_type(xml)
click to toggle source
# File lib/orcid_client/notification.rb, line 64 def insert_notification_type(xml) xml.send(:'notification:notification-type', "permission") end
item_name()
click to toggle source
# File lib/orcid_client/notification.rb, line 34 def item_name parse_attributes(metadata.titles, content: "title", first: true) end
item_type()
click to toggle source
# File lib/orcid_client/notification.rb, line 38 def item_type "work" end
metadata()
click to toggle source
# File lib/orcid_client/notification.rb, line 30 def metadata @metadata ||= Bolognese::Metadata.new(input: doi) end
root_attributes()
click to toggle source
# File lib/orcid_client/notification.rb, line 108 def root_attributes { :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', :'xsi:schemaLocation' => 'http://www.orcid.org/ns/notification ../notification-permission-2.1.xsd', :'xmlns:common' => 'http://www.orcid.org/ns/common', :'xmlns:notification' => 'http://www.orcid.org/ns/notification' } end
work_notification_path()
click to toggle source
# File lib/orcid_client/notification.rb, line 75 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