Class: NeverBounce::CLI::Script::JobsCreate

Inherits:
RequestMaker show all
Defined in:
lib/never_bounce/cli/script/jobs_create.rb,
lib/never_bounce/cli/script/jobs_create/supplied_input_parser.rb

Defined Under Namespace

Classes: SuppliedInputParser

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

#auto_parsetrue, ...

Returns:

  • (true)
  • (false)
  • (nil)


22
23
24
25
26
27
28
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 22

def auto_parse
  igetset(:auto_parse) do
    if env.has_key?(k = "AUTO_PARSE")
      env_truthy?(k)
    end
  end
end

#auto_starttrue, ...

Returns:

  • (true)
  • (false)
  • (nil)


33
34
35
36
37
38
39
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 33

def auto_start
  igetset(:auto_start) do
    if env.has_key?(k = "AUTO_START")
      env_truthy?(k)
    end
  end
end

#filenameObject



41
42
43
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 41

def filename
  igetset(:filename) { env["FILENAME"] || now.strftime("%Y%m%d-%H%M%S.csv") }
end

#inputString, Array

Returns:

  • (String)

    An URL if remote input.

  • (Array)

    An array of e-mails if supplied input.



47
48
49
50
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 47

def input
  input_location    # Touch for sanity/completeness checks etc.
  remote_input || supplied_input_array
end

#input_locationString

Returns "remote_url" or "supplied".

Returns:

  • (String)

    "remote_url" or "supplied"



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 53

def input_location
  @input_location ||= begin
    # Sanity check.
    raise UsageError, "`REMOTE_INPUT` and `SUPPLIED_INPUT` can't both be given" if remote_input? && supplied_input?

    if remote_input?
      "remote_url"
    elsif supplied_input?
      "supplied"
    else
      raise UsageError, "Input not given, use `REMOTE_INPUT=` or `SUPPLIED_INPUT=`"
    end
  end
end

#manifestManifest

Returns:



126
127
128
129
130
131
132
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 126

def manifest
  @manifest ||= Manifest.new(
    name: "nb-jobs-create",
    function: "Create a job",
    cmdline: "[options] [VAR1=value] [VAR2=value] ...",
  )
end

#nowObject



68
69
70
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 68

def now
  @now ||= Time.now
end

#remote_inputObject



72
73
74
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 72

def remote_input
  igetset(:remote_input) { env["REMOTE_INPUT"] }
end

#requestObject

An API::Request::JobsCreate.

Returns:

  • (Object)


110
111
112
113
114
115
116
117
118
119
120
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 110

def request
  @request ||= API::Request::JobsCreate.new({
    api_key: api_key,
    auto_parse: auto_parse,
    auto_start: auto_start,
    filename: filename,
    input: input,
    input_location: input_location,
    run_sample: run_sample,
  })
end

#run_sampletrue, ...

Returns:

  • (true)
  • (false)
  • (nil)


83
84
85
86
87
88
89
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 83

def run_sample
  igetset(:run_sample) do
    if env.has_key?(k = "RUN_SAMPLE")
      env_truthy?(k)
    end
  end
end

#supplied_inputObject



91
92
93
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 91

def supplied_input
  igetset(:supplied_input) { env["SUPPLIED_INPUT"] }
end

#supplied_input_arrayObject



99
100
101
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 99

def supplied_input_array
  @supplied_input_array ||= require_attr(:supplied_input_parser)[require_attr(:supplied_input)]
end

#supplied_input_parserObject



103
104
105
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 103

def supplied_input_parser
  @supplied_input_parser ||= SuppliedInputParser.new
end

Instance Method Details

#remote_input?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 76

def remote_input?
  !!remote_input
end

#slim_mainInteger

Returns:

  • (Integer)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 137

def slim_main
  "Response".tap do |label|
    headings = [
      ["JobId", :job_id],

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

  0
end

#supplied_input?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/never_bounce/cli/script/jobs_create.rb', line 95

def supplied_input?
  !!supplied_input
end