Class: URI::Acct

Inherits:
Generic
  • Object
show all
Defined in:
lib/bridgetown/webfinger/uri/acct.rb

Overview

A URI for an account on a system

See [RFC7565](datatracker.ietf.org/doc/html/rfc7565) for more information.

Examples:

Parsing an acct URI from a string


URI.parse("acct:[email protected]")

Since:

  • 0.1.0

Constant Summary collapse

COMPONENT =

The components of the URI

Since:

  • 0.1.0

[:scheme, :account, :host].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ URI::Acct

Instantiates a new URI::Acct from a long list of components

Examples:

Manually constructing a URI — with value checking — for the masochistic

URI::Acct.new(["acct", nil, nil, nil, nil, nil, "[email protected]", nil, nil, nil, true])

Parameters:

  • args (Array<String>)

    the components to set for the URI

Raises:

  • (InvalidComponentError)

    when the account name is malformed

Since:

  • 0.1.0



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bridgetown/webfinger/uri/acct.rb', line 72

def initialize(*args)
  super

  raise InvalidComponentError, "missing opaque part for acct URI" unless @opaque

  , _, host = @opaque.rpartition("@")
  @opaque = nil

  if args[10] # arg_check
    self. = 
    self.host = host
  else
    @account = 
    @host = host
  end
end

Instance Attribute Details

#accountString

The account part (also known as the userpart) of the URI

Examples:

Checking the account for a URI


URI.parse("acct:[email protected]"). #=> "bilbo"

Returns:

  • (String)

Since:

  • 0.1.0



99
100
101
# File 'lib/bridgetown/webfinger/uri/acct.rb', line 99

def 
  @account
end

Class Method Details

.build(args) ⇒ URI::Acct

Builds a URI::Acct from components

Note: Do not enter already percent-encoded data as a component for the account because the implementation will do this step for you. If you’re building from components received externally, consider using ‘URI.decode_uri_component` before using it to build a URI with this method.

Examples:

Building an acct URI from an array of attributes


URI::Acct.build(["bilbo", "bagend.com"])

Building an acct URI from a hash of attributes


URI::Acct.build({ account: "bilbo", host: "bagend.com" })

Parameters:

  • args (Hash<Symbol, String>, Array<String>)

    the components to use, either as a Hash of ‘String, host: String` or a positional, 2-element `Array` of the form `[account, host]`

Returns:

Raises:

  • (ArgumentError)

    when the components are incorrect

Since:

  • 0.1.0



50
51
52
53
54
55
56
57
58
59
# File 'lib/bridgetown/webfinger/uri/acct.rb', line 50

def self.build(args)
  components = Util.make_components_hash(self, args)

  components[:account] ||= ""
  components[:account] &&= URI.encode_uri_component(components[:account])
  components[:host] ||= ""
  components[:opaque] = "#{components.delete(:account)}@#{components.delete(:host)}"

  super(components)
end

Instance Method Details

#to_sString

Converts the URI into a string

Examples:

Converting a URI to a string


URI.parse("acct:[email protected]").to_s

Returns:

  • (String)

    the formatted version of the URI::Acct

Since:

  • 0.1.0



132
133
134
# File 'lib/bridgetown/webfinger/uri/acct.rb', line 132

def to_s
  @scheme + ":" + URI.encode_uri_component() + "@" + host
end