Module: DIDKit::Services Private
- Included in:
- Document, PLCOperation
- Defined in:
- lib/didkit/services.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
-
#get_service(key, type) ⇒ ServiceRecord?
Finds a service entry matching the given key and type.
-
#labeler_endpoint ⇒ String?
(also: #labeller_endpoint)
Returns the labeler service endpoint, if present and valid.
-
#labeler_host ⇒ String?
(also: #labeller_host)
Returns the hostname of the labeler service, if present.
-
#pds_endpoint ⇒ String?
Returns the PDS service endpoint, if present and valid.
-
#pds_host ⇒ String?
Returns the hostname of the PDS service, if present.
Instance Method Details
#get_service(key, type) ⇒ ServiceRecord?
Finds a service entry matching the given key and type.
20 21 22 |
# File 'lib/didkit/services.rb', line 20 def get_service(key, type) @services&.detect { |s| s.key == key && s.type == type } end |
#labeler_endpoint ⇒ String? Also known as: labeller_endpoint
Returns the labeler service endpoint, if present and valid.
If the DID has an #atproto_labeler service declared in its service section,
returns the URL in its serviceEndpoint field.
Returns nil if the service record is present, but the URL is not an HTTP(S) URL.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/didkit/services.rb', line 63 def labeler_endpoint return @labeler_endpoint if @labeler_endpoint endpoint = get_service('atproto_labeler', 'AtprotoLabeler')&.endpoint return nil if endpoint.nil? uri = URI(endpoint) return nil if uri.scheme !~ /^https?$/ || uri.host.nil? || uri.host.empty? @labeler_endpoint = endpoint end |
#labeler_host ⇒ String? Also known as: labeller_host
Returns the hostname of the labeler service, if present.
If the endpoint URL includes a port number, it is excluded.
93 94 95 |
# File 'lib/didkit/services.rb', line 93 def labeler_host labeler_endpoint&.then { |x| URI(x).host } end |
#pds_endpoint ⇒ String?
Returns the PDS service endpoint, if present and valid.
If the DID has an #atproto_pds service declared in its service section,
returns the URL in its serviceEndpoint field. In other words, this is the URL
of the PDS assigned to a given user, which stores the user's account and repo.
Returns nil if the service record is present, but the URL is not a valid HTTP(S) URL. For PDS endpoint specifically, the URL should only contain the scheme, hostname, and optional port number, but no userinfo, path, query or other components. As an exception, a path in the form of a single trailing slash is also allowed.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/didkit/services.rb', line 38 def pds_endpoint return @pds_endpoint if @pds_endpoint endpoint = get_service('atproto_pds', 'AtprotoPersonalDataServer')&.endpoint return nil if endpoint.nil? uri = URI(endpoint) return nil if uri.scheme !~ /^https?$/ || uri.host.nil? || uri.host.empty? return nil if uri.userinfo || uri.query || uri.fragment return nil unless uri.path.empty? || uri.path == '/' @pds_endpoint = endpoint end |
#pds_host ⇒ String?
Returns the hostname of the PDS service, if present.
If the endpoint URL includes a port number, it is excluded.
82 83 84 |
# File 'lib/didkit/services.rb', line 82 def pds_host pds_endpoint&.then { |x| URI(x).host } end |