Class: DIDKit::ServiceRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/didkit/service_record.rb

Overview

A parsed service record from either a DID document’s service field or a PLC directory operation’s services field.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, type, endpoint) ⇒ ServiceRecord

Create a service record from DID document fields.

Parameters:

  • key (String)

    service identifier (without ‘#`)

  • type (String)

    service type

  • endpoint (String)

    service endpoint URL

Raises:

  • (FormatError)

    when the endpoint is not a valid URI



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/didkit/service_record.rb', line 31

def initialize(key, type, endpoint)
  begin
    uri = URI(endpoint)
  rescue URI::Error
    raise FormatError, "Invalid service endpoint: #{endpoint.inspect}"
  end

  @key = key
  @type = type
  @endpoint = endpoint
end

Instance Attribute Details

#endpointString (readonly)

Returns service’s endpoint URL.

Returns:

  • (String)

    service’s endpoint URL



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

def endpoint
  @endpoint
end

#keyString (readonly)

Returns the service’s identifier (without ‘#`), like “atproto_pds”.

Returns:

  • (String)

    service’s identifier



15
16
17
# File 'lib/didkit/service_record.rb', line 15

def key
  @key
end

#typeString (readonly)

Returns the service’s type field, like “AtprotoPersonalDataServer”.

Returns:

  • (String)

    service’s type



19
20
21
# File 'lib/didkit/service_record.rb', line 19

def type
  @type
end