Class: DIDKit::Document
- Inherits:
-
Object
- Object
- DIDKit::Document
- Defined in:
- lib/didkit/document.rb
Defined Under Namespace
Classes: FormatError
Instance Attribute Summary collapse
-
#did ⇒ Object
readonly
Returns the value of attribute did.
-
#handles ⇒ Object
readonly
Returns the value of attribute handles.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Instance Method Summary collapse
- #get_validated_handle ⇒ Object
-
#initialize(did, json) ⇒ Document
constructor
A new instance of Document.
Methods included from Services
#get_service, #labeler_endpoint, #pds_endpoint
Methods included from AtHandles
Constructor Details
#initialize(did, json) ⇒ Document
Returns a new instance of Document.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/didkit/document.rb', line 16 def initialize(did, json) raise FormatError, "Missing id field" if json['id'].nil? raise FormatError, "Invalid id field" unless json['id'].is_a?(String) raise FormatError, "id field doesn't match expected DID" unless json['id'] == did.to_s @did = did @json = json if service = json['service'] raise FormatError, "Invalid service data" unless service.is_a?(Array) && service.all? { |x| x.is_a?(Hash) } @services = service.filter_map { |x| id, type, endpoint = x.values_at('id', 'type', 'serviceEndpoint') next unless id.is_a?(String) && id.start_with?('#') && type.is_a?(String) && endpoint.is_a?(String) ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint) } else @services = [] end @handles = parse_also_known_as(json['alsoKnownAs'] || []) end |
Instance Attribute Details
#did ⇒ Object (readonly)
Returns the value of attribute did.
14 15 16 |
# File 'lib/didkit/document.rb', line 14 def did @did end |
#handles ⇒ Object (readonly)
Returns the value of attribute handles.
14 15 16 |
# File 'lib/didkit/document.rb', line 14 def handles @handles end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
14 15 16 |
# File 'lib/didkit/document.rb', line 14 def json @json end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
14 15 16 |
# File 'lib/didkit/document.rb', line 14 def services @services end |
Instance Method Details
#get_validated_handle ⇒ Object
40 41 42 |
# File 'lib/didkit/document.rb', line 40 def get_validated_handle Resolver.new.pick_valid_handle(did, handles) end |