Class: IndieAuthDiscovery::URL

Inherits:
Object
  • Object
show all
Defined in:
lib/indieauth_discovery/url.rb

Overview

Canonicalization for IndieAuth client and user profile URLs.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_url) ⇒ URL

Returns a new instance of URL.



14
15
16
17
18
# File 'lib/indieauth_discovery/url.rb', line 14

def initialize(original_url)
  @original_url = original_url.to_s
  @canonical_url = original_url.to_s
  @redirects = []
end

Instance Attribute Details

#canonical_urlObject (readonly)

Returns the value of attribute canonical_url.



12
13
14
# File 'lib/indieauth_discovery/url.rb', line 12

def canonical_url
  @canonical_url
end

#original_urlObject (readonly)

Returns the value of attribute original_url.



12
13
14
# File 'lib/indieauth_discovery/url.rb', line 12

def original_url
  @original_url
end

#redirectsObject (readonly)

Returns the value of attribute redirects.



12
13
14
# File 'lib/indieauth_discovery/url.rb', line 12

def redirects
  @redirects
end

Class Method Details

.canonicalize(original_url) ⇒ Object



20
21
22
23
24
# File 'lib/indieauth_discovery/url.rb', line 20

def self.canonicalize(original_url)
  url = new(original_url)
  url.canonicalize
  url
end

Instance Method Details

#canonicalizeObject

Canonicalizes and verifies the URL.



30
31
32
33
34
35
36
37
38
39
# File 'lib/indieauth_discovery/url.rb', line 30

def canonicalize
  canonical = normalize_url(original_url)
  canonical, verify_response = verify_url(canonical)
  canonical = ensure_path(canonical)
  canonical = follow_redirects(canonical, verify_response)

  @canonical_url = canonical
rescue URI::InvalidURIError, *FARADAY_ERRORS
  raise_invalid_url_error(original_url)
end

#to_sObject

Returns the canonical URL as a string.



42
43
44
# File 'lib/indieauth_discovery/url.rb', line 42

def to_s
  @canonical_url
end

#to_uriObject

Returns the canonical URL as a URI.



47
48
49
# File 'lib/indieauth_discovery/url.rb', line 47

def to_uri
  URI.parse(@canonical_url)
end