Class: DIDKit::PLCOperation
- Inherits:
-
Object
- Object
- DIDKit::PLCOperation
- Defined in:
- lib/didkit/plc_operation.rb
Defined Under Namespace
Classes: FormatError
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#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.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(json) ⇒ PLCOperation
constructor
A new instance of PLCOperation.
Methods included from Services
#get_service, #labeler_endpoint, #pds_endpoint
Methods included from AtHandles
Constructor Details
#initialize(json) ⇒ PLCOperation
Returns a new instance of PLCOperation.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/didkit/plc_operation.rb', line 17 def initialize(json) @json = json @did = json['did'] raise FormatError, "Missing DID: #{json}" if @did.nil? raise FormatError, "Invalid DID: #{@did}" unless @did.is_a?(String) && @did.start_with?('did:') = json['createdAt'] raise FormatError, "Missing createdAt: #{json}" if .nil? raise FormatError, "Invalid createdAt: #{.inspect}" unless .is_a?(String) @created_at = Time.parse() operation = json['operation'] raise FormatError, "Missing operation key: #{json}" if operation.nil? raise FormatError, "Invalid operation data: #{operation.inspect}" unless operation.is_a?(Hash) type = operation['type'] raise FormatError, "Missing operation type: #{json}" if type.nil? @type = type.to_sym return unless @type == :plc_operation services = operation['services'] raise FormatError, "Missing services key: #{json}" if services.nil? raise FormatError, "Invalid services data: #{services}" unless services.is_a?(Hash) @services = services.map { |k, x| type, endpoint = x.values_at('type', 'endpoint') raise FormatError, "Missing service type" unless type raise FormatError, "Invalid service type: #{type.inspect}" unless type.is_a?(String) raise FormatError, "Missing service endpoint" unless endpoint raise FormatError, "Invalid service endpoint: #{endpoint.inspect}" unless endpoint.is_a?(String) ServiceRecord.new(k, type, endpoint) } @handles = parse_also_known_as(operation['alsoKnownAs']) end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
15 16 17 |
# File 'lib/didkit/plc_operation.rb', line 15 def created_at @created_at end |
#did ⇒ Object (readonly)
Returns the value of attribute did.
15 16 17 |
# File 'lib/didkit/plc_operation.rb', line 15 def did @did end |
#handles ⇒ Object (readonly)
Returns the value of attribute handles.
15 16 17 |
# File 'lib/didkit/plc_operation.rb', line 15 def handles @handles end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
15 16 17 |
# File 'lib/didkit/plc_operation.rb', line 15 def json @json end |
#services ⇒ Object (readonly)
Returns the value of attribute services.
15 16 17 |
# File 'lib/didkit/plc_operation.rb', line 15 def services @services end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/didkit/plc_operation.rb', line 15 def type @type end |