Class: Rails::Command::OpengraphCommand

Inherits:
Base
  • Object
show all
Defined in:
lib/rails/commands/opengraph/opengraph_command.rb

Instance Method Summary collapse

Instance Method Details

#verify(url) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rails/commands/opengraph/opengraph_command.rb', line 11

def verify(url)
  require "opengraphplus"

  say "Verifying OpenGraph tags at #{url}..."
  say ""

  begin
    parser = OpenGraphPlus::Verifier.new(url).verify
  rescue OpenGraphPlus::Verifier::FetchError => e
    say_error e.message
    exit 1
  end

  tags = parser.all_tags

  if tags.any?
    say "Found tags:"
    max_key_length = tags.keys.map(&:length).max
    tags.each do |property, content|
      say "  #{property.ljust(max_key_length)}#{content.inspect}"
    end
    say ""
  else
    say "No OpenGraph or Twitter tags found."
    say ""
  end

  if parser.errors.any?
    say "Missing required tags:"
    parser.errors.each do |tag|
      say "#{tag}"
    end
    say ""
  end

  if parser.warnings.any?
    say "Missing recommended tags:"
    parser.warnings.each do |tag|
      say "  - #{tag}"
    end
    say ""
  end

  if parser.valid?
    say "✓ All required OpenGraph tags present"
  else
    say "Verification failed: #{parser.errors.length} required tag(s) missing"
    exit 1
  end
end