Class: NeverBounce::CLI::Script::SingleCheck
- Inherits:
-
RequestMaker
- Object
- Base
- Meaningful
- RequestMaker
- NeverBounce::CLI::Script::SingleCheck
- Defined in:
- lib/never_bounce/cli/script/single_check.rb
Constant Summary
Constants inherited from RequestMaker
Instance Attribute Summary collapse
- #address_info ⇒ true, ...
- #credits_info ⇒ true, ...
- #email ⇒ Object
- #manifest ⇒ Manifest
-
#request ⇒ Object
An
API::Request::SingleCheck
. - #timeout ⇒ Object
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
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
#address_info ⇒ true, ...
18 19 20 21 22 23 24 |
# 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 ⇒ true, ...
29 30 31 32 33 34 35 |
# 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 ⇒ Object
37 38 39 |
# 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 ⇒ Manifest
70 71 72 73 74 75 76 |
# 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 ⇒ Object
An API::Request::SingleCheck
.
44 45 46 47 48 49 50 51 52 |
# 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 |
#timeout ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# 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. end end end end |
Instance Method Details
#slim_main ⇒ Integer
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 134 135 136 137 138 139 140 141 142 143 144 |
# 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 |