Class: Webmention::Verification

Inherits:
Object
  • Object
show all
Defined in:
lib/webmention/verification.rb

Instance Method Summary collapse

Constructor Details

#initialize(source_url, target_url, vouch_url: nil) ⇒ Verification

Returns a new instance of Verification.

Parameters:



8
9
10
11
12
# File 'lib/webmention/verification.rb', line 8

def initialize(source_url, target_url, vouch_url: nil)
  @source_url = source_url
  @target_url = target_url
  @vouch_url = vouch_url
end

Instance Method Details

#inspectString

:nocov:

Returns:

  • (String)


16
17
18
19
20
21
# File 'lib/webmention/verification.rb', line 16

def inspect
  "#<#{self.class}:#{format("%#0x", object_id)} " \
    "source_url: #{source_url} " \
    "target_url: #{target_url} " \
    "vouch_url: #{vouch_url}>"
end

#source_mentions_target?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/webmention/verification.rb', line 25

def source_mentions_target?
  @source_mentions_target ||= mentioned_urls(source_url.response).any?(target_url.to_s)
end

#verified?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/webmention/verification.rb', line 30

def verified?
  return source_mentions_target? unless verify_vouch?

  source_mentions_target? && vouch_mentions_source?
end

#verify_vouch?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/webmention/verification.rb', line 37

def verify_vouch?
  !vouch_url.nil? && !vouch_url.to_s.strip.empty?
end

#vouch_mentions_source?Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/webmention/verification.rb', line 42

def vouch_mentions_source?
  @vouch_mentions_source ||=
    verify_vouch? && mentioned_domains(vouch_url.response).any?(source_url.uri.host)
end