Class: Bridgetown::Webfinger::Link

Inherits:
Object
  • Object
show all
Extended by:
Logging
Defined in:
lib/bridgetown/webfinger/link.rb

Overview

Wraps a [link] object within a JRD

Links represent links to resources external to the entity. They are optional within a JRD so may not appear in your Webfinger setup.

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, warn

Constructor Details

#initialize(rel:, href: nil, properties: nil, titles: nil, type: nil) ⇒ Link

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.

Creates a new Bridgetown::Webfinger::Link

Parameters:

  • rel (LinkRelationType)

    the type of relation the Bridgetown::Webfinger::Link represents

  • href (Href, nil) (defaults to: nil)

    the optional Href URI of the link

  • properties (Properties, nil) (defaults to: nil)

    the optional list of Properties describing the link

  • titles (Titles, nil) (defaults to: nil)

    the optional list of Titles naming the link

  • type (String, nil) (defaults to: nil)

    the optional media type of the target resource

Since:

  • 0.1.0



53
54
55
56
57
58
59
# File 'lib/bridgetown/webfinger/link.rb', line 53

def initialize(rel:, href: nil, properties: nil, titles: nil, type: nil)
  @href = href
  @properties = properties
  @rel = rel
  @titles = titles
  @type = type
end

Instance Attribute Details

#hrefHref? (readonly)

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.

The optional hypertext reference to a URI for the Bridgetown::Webfinger::Link

Returns:

  • (Href, nil)

    the optional Href URI of the link

Since:

  • 0.1.0



67
68
69
# File 'lib/bridgetown/webfinger/link.rb', line 67

def href
  @href
end

#propertiesProperties? (readonly)

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.

The optional Properties characterizing the Bridgetown::Webfinger::Link

Returns:

Since:

  • 0.1.0



76
77
78
# File 'lib/bridgetown/webfinger/link.rb', line 76

def properties
  @properties
end

#relLinkRelationType (readonly)

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.

The Bridgetown::Webfinger::LinkRelationType describing what the Bridgetown::Webfinger::Link links to

Returns:

Since:

  • 0.1.0



84
85
86
# File 'lib/bridgetown/webfinger/link.rb', line 84

def rel
  @rel
end

#titlesTitles? (readonly)

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.

The optional Titles describing the Bridgetown::Webfinger::Link

Returns:

  • (Titles, nil)

    the optional list of Titles naming the link

Since:

  • 0.1.0



92
93
94
# File 'lib/bridgetown/webfinger/link.rb', line 92

def titles
  @titles
end

#typeString? (readonly)

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.

The optional media type of the #href for the Bridgetown::Webfinger::Link

Returns:

  • (String, nil)

    the optional media type of the target resource

Since:

  • 0.1.0



100
101
102
# File 'lib/bridgetown/webfinger/link.rb', line 100

def type
  @type
end

Class Method Details

.parse(data) ⇒ Link?

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 a Bridgetown::Webfinger::Link when the value is one

Links][1

within the JRD are member objects representing a link to

another resource.

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

Parameters:

  • data (Hash)

    the data to parse as a link object

Returns:

  • (Link, nil)

    the link parsed from the data

Since:

  • 0.1.0



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bridgetown/webfinger/link.rb', line 26

def self.parse(data)
  unless (rel = LinkRelationType.parse(data[:rel]))
    return warn(
      "Webfinger link rel is missing or malformed: #{data.inspect}, ignoring"
    )
  end

  new(
    rel: rel,
    href: Href.parse(data[:href]),
    properties: Properties.parse(data[:properties]),
    titles: Titles.parse(data[:titles]),
    type: data[:type]
  )
end

Instance Method Details

#to_hHash

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.

Converts the Bridgetown::Webfinger::Link into a JSON-serializable Hash

Returns:

  • (Hash)

    the Link as a JSON-compatible Hash

Since:

  • 0.1.0



108
109
110
111
112
113
114
115
# File 'lib/bridgetown/webfinger/link.rb', line 108

def to_h
  result = {rel: rel}
  result[:href] = href if href
  result[:properties] = properties if properties
  result[:titles] = titles if titles
  result[:type] = type if type
  result
end