Module: BIMI

Defined in:
lib/bimi.rb,
lib/bimi/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

SPINNER =
%w[         ].freeze
STEPS =
[
  "Looking up DMARC policy",
  "Resolving default._bimi TXT record",
  "Fetching SVG Tiny PS logo",
  "Validating VMC certificate chain",
  "Verifying mark ownership",
  "Polishing your brand indicator"
].freeze
RAINBOW =
[196, 208, 220, 190, 82, 51, 63, 129, 201].freeze
SPARKLES =
%w[          ·].freeze
TAGLINES =
[
  "your brand is beautiful",
  "looking sharp, inbox-ready",
  "logos to the moon",
  "ship it with style",
  "now that's a brand indicator",
  "deliverability and vibes",
  "fresh off the mark",
  "your logo, but make it verified",
  "authenticated drip"
].freeze
48
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

._banner(out) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/bimi.rb', line 70

def self._banner(out)
  letters = %w[B I M I]
  revealed = +""
  letters.each_with_index do |ch, i|
    color = RAINBOW[(i * 2) % RAINBOW.length]
    revealed << "\e[38;5;#{color};1m #{ch} "
    4.times do
      trail = "#{_sparkle} #{_sparkle} #{_sparkle}"
      out.print("\r   #{revealed}\e[0m   #{trail}\e[K")
      sleep(0.05)
    end
  end
  12.times do |frame|
    tinted = letters.each_with_index.map do |ch, i|
      color = RAINBOW[(frame + i * 2) % RAINBOW.length]
      "\e[38;5;#{color};1m #{ch} "
    end.join
    left = _sparkle
    right = _sparkle
    out.print("\r  #{left} #{tinted}\e[0m#{right}\e[K")
    sleep(0.06)
  end
  out.puts("\e[0m")
  out.puts("   \e[2mbrand indicators for message identification\e[0m\n\n")
end

._confetti_line(width, density) ⇒ Object



58
59
60
# File 'lib/bimi.rb', line 58

def self._confetti_line(width, density)
  Array.new(width) { rand < density ? _sparkle : " " }.join
end

._fanfare(out) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/bimi.rb', line 62

def self._fanfare(out)
  8.times do
    out.print("\r#{_confetti_line(BANNER_WIDTH, 0.25)}")
    sleep(0.05)
  end
  out.print("\r#{" " * BANNER_WIDTH}\r")
end

._finale(domain, out) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/bimi.rb', line 110

def self._finale(domain, out)
  canvas_h = 4
  canvas_h.times { out.puts }
  12.times do
    out.print("\e[#{canvas_h}A")
    canvas_h.times do
      out.print("\r#{_confetti_line(BANNER_WIDTH, 0.28)}\e[K\n")
    end
    sleep(0.06)
  end
  out.print("\e[#{canvas_h}A")
  canvas_h.times { out.print("\r\e[K\n") }
  out.print("\e[#{canvas_h}A")

  msg = "  BIMI IS LIT for #{domain}  "
  bar = "" * msg.length
  out.puts("\e[38;5;82m╔#{bar}╗\e[0m")
  14.times do |frame|
    tinted = msg.each_char.with_index.map do |ch, i|
      color = RAINBOW[(frame + i) % RAINBOW.length]
      "\e[38;5;#{color};1m#{ch}"
    end.join
    out.print("\e[38;5;82m║\e[0m#{tinted}\e[0m\e[38;5;82m║\e[0m\r")
    sleep(0.08)
  end
  out.puts
  out.puts("\e[38;5;82m╚#{bar}╝\e[0m")
  out.puts("\n  \e[3m\e[38;5;#{RAINBOW.sample}m#{SPARKLES.sample} #{TAGLINES.sample} #{SPARKLES.sample}\e[0m")
  out.puts("\n  \e[2mpreview release — real record, SVG, and VMC checks coming in a future version\e[0m\n\n")
end

._run_steps(domain, out) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/bimi.rb', line 96

def self._run_steps(domain, out)
  STEPS.each_with_index do |step, idx|
    label = "#{step} for \e[1m#{domain}\e[0m"
    frames = 10 + rand(6)
    frames.times do |f|
      color = RAINBOW[(f + idx) % RAINBOW.length]
      out.print("\r\e[38;5;#{color}m#{SPINNER[f % SPINNER.length]}\e[0m  #{label}\e[K")
      sleep(0.04)
    end
    out.puts("\r\e[32m✓\e[0m  #{label}  #{_sparkle}#{_sparkle}\e[K")
  end
  out.puts
end

._sparkleObject



54
55
56
# File 'lib/bimi.rb', line 54

def self._sparkle
  "\e[38;5;#{RAINBOW.sample}m#{SPARKLES.sample}\e[0m"
end

._static(domain, out) ⇒ Object



141
142
143
144
145
# File 'lib/bimi.rb', line 141

def self._static(domain, out)
  out.puts("BIMI check for #{domain}")
  STEPS.each { |s| out.puts("  ok  #{s}") }
  out.puts("BIMI is lit for #{domain}#{TAGLINES.sample}!")
end

.check(domain = "yourdomain.example") ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bimi.rb', line 37

def self.check(domain = "yourdomain.example")
  out = $stdout
  return _static(domain, out) unless out.tty?

  out.sync = true
  out.print("\e[?25l")
  begin
    _fanfare(out)
    _banner(out)
    _run_steps(domain, out)
    _finale(domain, out)
  ensure
    out.print("\e[?25h")
  end
  true
end