class NeverBounce::CLI::Script::JobsSearch

Attributes

job_id[W]

Public Instance Methods

job_id() click to toggle source

Job ID. Default is env["ID"]. @!attribute job_id @return [String]

# File lib/never_bounce/cli/script/jobs_search.rb, line 19
def job_id
  igetset(:job_id) { env["ID"] }
end
manifest() click to toggle source

@!attribute manifest @return [Manifest]

# File lib/never_bounce/cli/script/jobs_search.rb, line 39
def manifest
  @manifest ||= Manifest.new(
    name: "nb-jobs-search",
    function: "List jobs",
    cmdline: "[options] [VAR1=value] [VAR2=value] ...",
  )
end
request() click to toggle source

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

# File lib/never_bounce/cli/script/jobs_search.rb, line 26
def request
  @request ||= API::Request::JobsSearch.new({
    api_key: api_key,
    job_id: job_id,
    page: page,
    per_page: per_page,
  })
end
slim_main() click to toggle source

@return [Integer]

# File lib/never_bounce/cli/script/jobs_search.rb, line 50
def slim_main
  "Response".tap do |label|
    headings = [
      ["nPages", :total_pages, :right],
      ["nResults", :total_results, :right],

      ["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

  "Query".tap do |label|
    headings = [
      ["Page", :page, :right],
      ["PerPage", :items_per_page, :right],
    ]

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

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

  "Results".tap do |label|
    headings = [
      ["ID", :id, :right],
      ["JobStatus", :job_status, :center],
      ["Filename", :filename, :center],
      ["BncEst", ->(r) { r.bounce_estimate.round(2) }, :right],
      ["Complete%", :percent_complete, :right],

      [
        "At",
        ->(r) { [
          "Created:#{inil(r.created_at)}",
          "Started:#{inil(r.started_at)}",
          "Finished:#{inil(r.finished_at)}",
        ].join("\n") },
        :right,
      ],

      [
        "Total",
        ->(r) { [
          "BadSynt:#{inil(r.total.bad_syntax)}",
          "Billable:#{inil(r.total.billable)}",
          "Catchall:#{inil(r.total.catchall)}",
          "Disp:#{inil(r.total.disposable)}",
          "Dup:#{inil(r.total.duplicates)}",
          "Invalid:#{inil(r.total.invalid)}",
          "Proc'd:#{inil(r.total.processed)}",
          "Records:#{inil(r.total.records)}",
          "Unknown:#{inil(r.total.unknown)}",
          "Valid:#{inil(r.total.valid)}",
        ].join("\n") },
        :right,
      ],
    ]

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

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

  0
end