Class: DIDKit::PLCOperation
- Inherits:
-
Object
- Object
- DIDKit::PLCOperation
- Defined in:
- lib/didkit/plc_operation.rb
Overview
Represents a single operation of changing a specific DID's data in the plc.directory (e.g. changing assigned handles or migrating to a different PDS).
Instance Attribute Summary collapse
-
#cid ⇒ String
readonly
CID (Content Identifier) of the operation.
-
#created_at ⇒ Time
readonly
Time when the operation was created.
-
#did ⇒ String
readonly
The DID which the operation concerns.
-
#json ⇒ Hash
readonly
The JSON from which the operation is parsed.
-
#seq ⇒ Integer?
readonly
Returns a sequential number of the operation (only used in the new export API).
-
#services ⇒ Array<ServiceRecords>
readonly
Service records like PDS details assigned to the DID.
-
#type ⇒ String
readonly
Returns the
typefield of the operation (usually"plc_operation").
Attributes included from AtHandles
Instance Method Summary collapse
-
#initialize(json) ⇒ PLCOperation
constructor
Creates a PLCOperation object.
-
#nullified? ⇒ Boolean
If the operation has been nullified through a rotation operation.
Methods included from Services
#get_service, #labeler_endpoint, #labeler_host, #pds_endpoint, #pds_host
Constructor Details
#initialize(json) ⇒ PLCOperation
Creates a PLCOperation object.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/didkit/plc_operation.rb', line 50 def initialize(json) @json = json raise FormatError, "Expected argument to be a Hash, got a #{json.class}" unless @json.is_a?(Hash) @seq = json['seq'] @did = json['did'] raise FormatError, "Missing DID: #{json}" if @did.nil? raise FormatError, "Invalid DID: #{@did.inspect}" unless @did.is_a?(String) && @did.start_with?('did:') @cid = json['cid'] raise FormatError, "Missing CID: #{json}" if @cid.nil? raise FormatError, "Invalid CID: #{@cid}" unless @cid.is_a?(String) = 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? raise FormatError, "Invalid operation type: #{type.inspect}" unless type.is_a?(String) @type = type.to_sym case @type when :plc_operation raise FormatError, "Missing services key: #{json}" if operation['services'].nil? parse_services(operation['services']) parse_also_known_as(operation['alsoKnownAs']) when :create parse_legacy_ops(operation) end end |
Instance Attribute Details
#cid ⇒ String (readonly)
Returns CID (Content Identifier) of the operation.
28 29 30 |
# File 'lib/didkit/plc_operation.rb', line 28 def cid @cid end |
#created_at ⇒ Time (readonly)
Returns time when the operation was created.
35 36 37 |
# File 'lib/didkit/plc_operation.rb', line 35 def created_at @created_at end |
#did ⇒ String (readonly)
Returns the DID which the operation concerns.
25 26 27 |
# File 'lib/didkit/plc_operation.rb', line 25 def did @did end |
#json ⇒ Hash (readonly)
Returns the JSON from which the operation is parsed.
22 23 24 |
# File 'lib/didkit/plc_operation.rb', line 22 def json @json end |
#seq ⇒ Integer? (readonly)
Returns a sequential number of the operation (only used in the new export API).
32 33 34 |
# File 'lib/didkit/plc_operation.rb', line 32 def seq @seq end |
#services ⇒ Array<ServiceRecords> (readonly)
Returns service records like PDS details assigned to the DID.
42 43 44 |
# File 'lib/didkit/plc_operation.rb', line 42 def services @services end |
#type ⇒ String (readonly)
Returns the type field of the operation (usually "plc_operation").
39 40 41 |
# File 'lib/didkit/plc_operation.rb', line 39 def type @type end |
Instance Method Details
#nullified? ⇒ Boolean
Returns if the operation has been nullified through a rotation operation.
91 92 93 |
# File 'lib/didkit/plc_operation.rb', line 91 def nullified? @json['nullified'] == true end |