Class: OrcidClient::ExternalIdentifier

Inherits:
Object
  • Object
show all
Includes:
Api, Base
Defined in:
lib/orcid_client/external_identifier.rb

Constant Summary collapse

SCHEMA =
File.expand_path("../../../resources/record_#{API_VERSION}/person-external-identifier-#{API_VERSION}.xsd", __FILE__)

Constants included from Api

Api::API_VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Constructor Details

#initialize(type:, value:, url:, orcid:, orcid_token:, **options) ⇒ ExternalIdentifier

Returns a new instance of ExternalIdentifier.



14
15
16
17
18
19
20
21
# File 'lib/orcid_client/external_identifier.rb', line 14

def initialize(type:, value:, url:, orcid:, orcid_token:, **options)
  @type = type
  @value = value
  @url = url
  @orcid = orcid
  @orcid_token = orcid_token
  @put_code = options.fetch(:put_code, nil)
end

Instance Attribute Details

#orcidObject (readonly)

Returns the value of attribute orcid.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def orcid
  @orcid
end

#orcid_tokenObject (readonly)

Returns the value of attribute orcid_token.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def orcid_token
  @orcid_token
end

#put_codeObject (readonly)

Returns the value of attribute put_code.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def put_code
  @put_code
end

#schemaObject (readonly)

Returns the value of attribute schema.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def schema
  @schema
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def url
  @url
end

#validation_errorsObject (readonly)

Returns the value of attribute validation_errors.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def validation_errors
  @validation_errors
end

#valueObject (readonly)

Returns the value of attribute value.



12
13
14
# File 'lib/orcid_client/external_identifier.rb', line 12

def value
  @value
end

Instance Method Details

#dataObject



25
26
27
28
29
30
31
# File 'lib/orcid_client/external_identifier.rb', line 25

def data
  Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml.send(:'external-identifier:external-identifier', root_attributes) do
      insert_external_identifier(xml)
    end
  end.to_xml
end

#insert_external_identifier(xml) ⇒ Object



33
34
35
# File 'lib/orcid_client/external_identifier.rb', line 33

def insert_external_identifier(xml)
  insert_id(xml)
end

#insert_id(xml) ⇒ Object



37
38
39
40
41
42
# File 'lib/orcid_client/external_identifier.rb', line 37

def insert_id(xml)
  xml.send(:'common:external-id-type', type)
  xml.send(:'common:external-id-value', value)
  xml.send(:'common:external-id-url', url)
  xml.send(:'common:external-id-relationship', "self")
end

#root_attributesObject



44
45
46
47
48
49
50
51
# File 'lib/orcid_client/external_identifier.rb', line 44

def root_attributes
  { :'put-code' => put_code,
    :'visibility' => 'public',
    :'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
    :'xsi:schemaLocation' => 'http://www.orcid.org/ns/external-identifier ../person-external-identifier-3.0.xsd',
    :'xmlns:common' => 'http://www.orcid.org/ns/common',
    :'xmlns:external-identifier' => 'http://www.orcid.org/ns/external-identifier' }.compact
end