class NeverBounce::CLI::Script::SingleCheck

Attributes

address_info[W]
credits_info[W]
email[W]
timeout[W]

Public Instance Methods

address_info() click to toggle source

@return [true] @return [false] @return [nil]

# File lib/never_bounce/cli/script/single_check.rb, line 18
def address_info
  igetset(:address_info) do
    if env.has_key?(k = "ADDRESS_INFO")
      env_truthy?(k)
    end
  end
end
credits_info() click to toggle source

@return [true] @return [false] @return [nil]

# File lib/never_bounce/cli/script/single_check.rb, line 29
def credits_info
  igetset(:credits_info) do
    if env.has_key?(k = "CREDITS_INFO")
      env_truthy?(k)
    end
  end
end
email() click to toggle source
# File lib/never_bounce/cli/script/single_check.rb, line 37
def email
  @email ||= env[k = "EMAIL"] or raise UsageError, "E-mail address not given, use `#{k}=`"
end
manifest() click to toggle source

@!attribute manifest @return [Manifest]

# File lib/never_bounce/cli/script/single_check.rb, line 70
def manifest
  @manifest ||= Manifest.new(
    name: "nb-single-check",
    function: "Check a single e-mail",
    cmdline: "[options] [VAR1=value] [VAR2=value] ...",
  )
end
request() click to toggle source

An API::Request::SingleCheck. @!attribute request @return [Object]

# File lib/never_bounce/cli/script/single_check.rb, line 44
def request
  @request ||= API::Request::SingleCheck.new({
    address_info: address_info,
    api_key: api_key,
    credits_info: credits_info,
    email: email,
    timeout: timeout,
  })
end
slim_main() click to toggle source

@return [Integer]

# File lib/never_bounce/cli/script/single_check.rb, line 81
def slim_main
  "Response".tap do |label|
    headings = [
      ["Result", :result, :center],
      [
        "Flags",
        ->(r) { r.flags.sort.join("\n") },
      ],
      ["SuggCorr", :suggested_correction],

      ["ExecTime", :execution_time, :right],
    ]

    table = Table.new(
      headings: headings.map { |ar| ar[0] },
      rows: [headings.map { |ar| get_table_value(response, ar) }],
    ).align!(headings)

    stdout.puts "\n#{label}:"
    stdout.puts table
  end

  response.address_info? and "AddressInfo".tap do |label|
    headings = [
      ["Addr", :addr],
      ["Alias", :alias],
      ["Domain", :domain],
      ["FQDN", :fqdn],
      ["Host", :host],
      ["NormEmail", :normalized_email],
      ["OrigEmail", :original_email],
      ["Subdomain", :subdomain],
      ["TLD", :tld],
    ]

    table = Table.new(
      headings: headings.map { |ar| ar[0] },
      rows: [headings.map { |ar| get_table_value(response.address_info, ar) }],
    ).align!(headings)

    stdout.puts "\n#{label}:"
    stdout.puts table
  end # response.address_info?

  response.credits_info? and "CreditsInfo".tap do |label|
    headings = [
      ["FreeRmn", :free_credits_remaining, :right],
      ["FreeUsed", :free_credits_used, :right],
      (["MonthlyUsage", :monthly_api_usage, :right] if response.credits_info.monthly?),
      (["PaidRmn", :paid_credits_remaining, :right] if response.credits_info.paid?),
      (["PaidUsed", :paid_credits_used, :right] if response.credits_info.paid?),
    ].compact

    table = Table.new(
      headings: headings.map { |ar| ar[0] },
      rows: [headings.map { |ar| get_table_value(response.credits_info, ar) }],
    ).align!(headings)

    stdout.puts "\n#{label}:"
    stdout.puts table
  end # response.credits_info?

  0
end
timeout() click to toggle source
# File lib/never_bounce/cli/script/single_check.rb, line 54
def timeout
  igetset(:timeout) do
    if (v = env["TIMEOUT"])
      begin
        Integer(v)
      rescue ArgumentError => e
        raise UsageError, e.message
      end
    end
  end
end