Class: NeverBounce::CLI::Script::JobsSearch

Inherits:
RequestMaker show all
Defined in:
lib/never_bounce/cli/script/jobs_search.rb

Constant Summary

Constants inherited from RequestMaker

RequestMaker::SHARED_ENVARS

Instance Attribute Summary collapse

Attributes inherited from RequestMaker

#api_key, #api_url, #request_curl, #response, #server_raw, #session, #user_config

Attributes inherited from Meaningful

#banner_text, #envar_text, #help_text, #options_text

Attributes inherited from Base

#argv, #env, #stderr, #stdout

Instance Method Summary collapse

Methods inherited from RequestMaker

#get_table_value, #inil, #print_curl_request, #print_error_response, #print_server_raw, #slim_main1

Methods inherited from Meaningful

#call_slim_main, error_klasses, format_envar_examples, #handle_help_and_options, #help?, #main, #option_parser, #options

Methods inherited from Base

#env_falsey?, #env_truthy?, env_value_truthy?, #main, #system, #verbose?

Instance Attribute Details

#job_idString

Job ID. Default is env["ID"].

Returns:

  • (String)


19
20
21
# File 'lib/never_bounce/cli/script/jobs_search.rb', line 19

def job_id
  igetset(:job_id) { env["ID"] }
end

#manifestManifest

Returns:



39
40
41
42
43
44
45
# 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

#requestObject

An API::Request::JobsSearch.

Returns:

  • (Object)


26
27
28
29
30
31
32
33
# 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

Instance Method Details

#slim_mainInteger

Returns:

  • (Integer)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# 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