Class: Bridgetown::Webfinger::Properties

Inherits:
Model
  • Object
show all
Defined in:
lib/bridgetown/webfinger/properties.rb

Overview

Wraps a ‘properties` member within a Link or JRD

Class Method Summary collapse

Methods included from Logging

included, #warn

Class Method Details

.parse(data) ⇒ Properties?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses and maybe-returns Bridgetown::Webfinger::Properties when the value is one

Properties within the JRD are name/value pairs [with URIs for names and strings or nulls for values].

[1]: datatracker.ietf.org/doc/html/rfc7033#section-4.4.4.5

Parameters:

  • data (Hash)

    the data to parse as a properties object

Returns:

  • (Properties, nil)

    the properties parsed from the data

Since:

  • 0.1.0



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bridgetown/webfinger/properties.rb', line 19

def self.parse(data)
  return unless data

  unless data.is_a?(Hash)
    return warn("Webfinger link properties are malformed: #{data.inspect}, ignoring")
  end

  properties = data.select do |name, value|
    if !Webfinger.uri?(name)
      next warn("Webfinger property name is not a URI: #{name}, ignoring")
    elsif !value.is_a?(String) || value.nil?
      next warn("Webfinger property value is not a nullable string: #{value}, ignoring")
    else
      true
    end
  end

  if !properties.empty?
    new(properties)
  else
    warn("All Webfinger link properties pruned: #{data.inspect}, ignoring")
  end
end