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](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.
-
#handles ⇒ Array<String>
readonly
Returns a list of handles assigned to the DID in this operation.
-
#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”`).
Instance Method Summary collapse
-
#initialize(json) ⇒ PLCOperation
constructor
Creates a PLCOperation object.
Methods included from Services
#get_service, #labeler_endpoint, #labeler_host, #pds_endpoint, #pds_host
Constructor Details
#initialize(json) ⇒ PLCOperation
Creates a PLCOperation object.
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/didkit/plc_operation.rb', line 59 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 return unless @type == :plc_operation services = operation['services'] raise FormatError, "Missing services key: #{json}" if services.nil? raise FormatError, "Invalid services data: #{services.inspect}" 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
#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 |
#handles ⇒ Array<String> (readonly)
Returns a list of handles assigned to the DID in this operation.
Note: the handles aren’t guaranteed to be verified (validated in the other direction). Use DID#get_verified_handle or Document#get_verified_handle to find a handle that is correctly verified.
48 49 50 |
# File 'lib/didkit/plc_operation.rb', line 48 def handles @handles 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.
51 52 53 |
# File 'lib/didkit/plc_operation.rb', line 51 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 |