Class: DIDKit::PLCOperation

Inherits:
Object
  • Object
show all
Includes:
AtHandles, Services
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

Attributes included from AtHandles

#also_known_as, #handles

Instance Method Summary collapse

Methods included from Services

#get_service, #labeler_endpoint, #labeler_host, #pds_endpoint, #pds_host

Constructor Details

#initialize(json) ⇒ PLCOperation

Creates a PLCOperation object.

Parameters:

  • json (Hash)

    operation JSON

Raises:

  • (FormatError)

    when required fields are missing or invalid



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)

  timestamp = json['createdAt']
  raise FormatError, "Missing createdAt: #{json}" if timestamp.nil?
  raise FormatError, "Invalid createdAt: #{timestamp.inspect}" unless timestamp.is_a?(String)

  @created_at = Time.parse(timestamp)

  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

#cidString (readonly)

Returns CID (Content Identifier) of the operation.

Returns:

  • (String)

    CID (Content Identifier) of the operation



28
29
30
# File 'lib/didkit/plc_operation.rb', line 28

def cid
  @cid
end

#created_atTime (readonly)

Returns time when the operation was created.

Returns:

  • (Time)

    time when the operation was created



35
36
37
# File 'lib/didkit/plc_operation.rb', line 35

def created_at
  @created_at
end

#didString (readonly)

Returns the DID which the operation concerns.

Returns:

  • (String)

    the DID which the operation concerns



25
26
27
# File 'lib/didkit/plc_operation.rb', line 25

def did
  @did
end

#jsonHash (readonly)

Returns the JSON from which the operation is parsed.

Returns:

  • (Hash)

    the JSON from which the operation is parsed



22
23
24
# File 'lib/didkit/plc_operation.rb', line 22

def json
  @json
end

#seqInteger? (readonly)

Returns a sequential number of the operation (only used in the new export API).

Returns:

  • (Integer, nil)

    sequential number of the operation



32
33
34
# File 'lib/didkit/plc_operation.rb', line 32

def seq
  @seq
end

#servicesArray<ServiceRecords> (readonly)

Returns service records like PDS details assigned to the DID.

Returns:

  • (Array<ServiceRecords>)

    service records like PDS details assigned to the DID



42
43
44
# File 'lib/didkit/plc_operation.rb', line 42

def services
  @services
end

#typeString (readonly)

Returns the type field of the operation (usually "plc_operation").

Returns:

  • (String)

    the operation type



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.

Returns:

  • (Boolean)

    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