neverbounce-cli 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +8 -0
  3. data/.gitignore +21 -0
  4. data/.rspec +4 -0
  5. data/.rubocop.yml +1161 -0
  6. data/.travis.yml +27 -0
  7. data/.yardopts +2 -0
  8. data/Gemfile +19 -0
  9. data/Gemfile.lock +60 -0
  10. data/LICENSE +9 -0
  11. data/README.md +138 -0
  12. data/exe/nb-account-info +5 -0
  13. data/exe/nb-jobs-create +5 -0
  14. data/exe/nb-jobs-delete +5 -0
  15. data/exe/nb-jobs-download +5 -0
  16. data/exe/nb-jobs-parse +5 -0
  17. data/exe/nb-jobs-results +5 -0
  18. data/exe/nb-jobs-search +5 -0
  19. data/exe/nb-jobs-start +5 -0
  20. data/exe/nb-jobs-status +5 -0
  21. data/exe/nb-single-check +5 -0
  22. data/lib/never_bounce/cli/feature/basic_initialize.rb +20 -0
  23. data/lib/never_bounce/cli/feature/eigencache.rb +47 -0
  24. data/lib/never_bounce/cli/feature/envars/examples_mapper.rb +38 -0
  25. data/lib/never_bounce/cli/feature/envars/item.rb +41 -0
  26. data/lib/never_bounce/cli/feature/envars.rb +82 -0
  27. data/lib/never_bounce/cli/feature/igetset.rb +41 -0
  28. data/lib/never_bounce/cli/feature/require_attr.rb +25 -0
  29. data/lib/never_bounce/cli/script/account_info.rb +85 -0
  30. data/lib/never_bounce/cli/script/base.rb +101 -0
  31. data/lib/never_bounce/cli/script/error.rb +16 -0
  32. data/lib/never_bounce/cli/script/feature/requires_job_id.rb +28 -0
  33. data/lib/never_bounce/cli/script/feature/uses_pagination.rb +45 -0
  34. data/lib/never_bounce/cli/script/jobs_create/supplied_input_parser.rb +48 -0
  35. data/lib/never_bounce/cli/script/jobs_create.rb +157 -0
  36. data/lib/never_bounce/cli/script/jobs_delete.rb +55 -0
  37. data/lib/never_bounce/cli/script/jobs_download.rb +44 -0
  38. data/lib/never_bounce/cli/script/jobs_parse.rb +73 -0
  39. data/lib/never_bounce/cli/script/jobs_results.rb +105 -0
  40. data/lib/never_bounce/cli/script/jobs_search.rb +135 -0
  41. data/lib/never_bounce/cli/script/jobs_start.rb +73 -0
  42. data/lib/never_bounce/cli/script/jobs_status.rb +96 -0
  43. data/lib/never_bounce/cli/script/manifest.rb +22 -0
  44. data/lib/never_bounce/cli/script/meaningful.rb +233 -0
  45. data/lib/never_bounce/cli/script/request_maker.rb +169 -0
  46. data/lib/never_bounce/cli/script/single_check.rb +146 -0
  47. data/lib/never_bounce/cli/script/table.rb +43 -0
  48. data/lib/never_bounce/cli/user_config/file_content.rb +66 -0
  49. data/lib/never_bounce/cli/user_config.rb +51 -0
  50. data/lib/never_bounce/cli/version.rb +4 -0
  51. data/lib/neverbounce-cli.rb +3 -0
  52. data/neverbounce-cli.gemspec +24 -0
  53. data/spec/lib/never_bounce/cli/feature/basic_initialize_spec.rb +26 -0
  54. data/spec/lib/never_bounce/cli/feature/eigencache_spec.rb +28 -0
  55. data/spec/lib/never_bounce/cli/feature/envars/examples_mapper_spec.rb +26 -0
  56. data/spec/lib/never_bounce/cli/feature/envars/item_spec.rb +9 -0
  57. data/spec/lib/never_bounce/cli/feature/envars_spec.rb +55 -0
  58. data/spec/lib/never_bounce/cli/feature/igetset_spec.rb +45 -0
  59. data/spec/lib/never_bounce/cli/feature/require_attr_spec.rb +25 -0
  60. data/spec/lib/never_bounce/cli/script/account_info_spec.rb +65 -0
  61. data/spec/lib/never_bounce/cli/script/base_spec.rb +56 -0
  62. data/spec/lib/never_bounce/cli/script/feature/requires_job_id_spec.rb +17 -0
  63. data/spec/lib/never_bounce/cli/script/feature/uses_pagination_spec.rb +21 -0
  64. data/spec/lib/never_bounce/cli/script/jobs_create/supplied_input_parser_spec.rb +35 -0
  65. data/spec/lib/never_bounce/cli/script/jobs_create_spec.rb +118 -0
  66. data/spec/lib/never_bounce/cli/script/jobs_delete_spec.rb +33 -0
  67. data/spec/lib/never_bounce/cli/script/jobs_download_spec.rb +37 -0
  68. data/spec/lib/never_bounce/cli/script/jobs_parse_spec.rb +45 -0
  69. data/spec/lib/never_bounce/cli/script/jobs_results_spec.rb +40 -0
  70. data/spec/lib/never_bounce/cli/script/jobs_search_spec.rb +59 -0
  71. data/spec/lib/never_bounce/cli/script/jobs_start_spec.rb +45 -0
  72. data/spec/lib/never_bounce/cli/script/jobs_status_spec.rb +37 -0
  73. data/spec/lib/never_bounce/cli/script/manifest_spec.rb +6 -0
  74. data/spec/lib/never_bounce/cli/script/meaningful_spec.rb +93 -0
  75. data/spec/lib/never_bounce/cli/script/request_maker_spec.rb +67 -0
  76. data/spec/lib/never_bounce/cli/script/single_check_spec.rb +94 -0
  77. data/spec/lib/never_bounce/cli/script/spec_helper.rb +59 -0
  78. data/spec/lib/never_bounce/cli/script/table_spec.rb +6 -0
  79. data/spec/lib/never_bounce/cli/user_config/file_content_spec.rb +43 -0
  80. data/spec/lib/never_bounce/cli/user_config_spec.rb +12 -0
  81. data/spec/lib/never_bounce/cli_spec.rb +6 -0
  82. data/spec/spec_helper.rb +51 -0
  83. metadata +193 -0
data/.travis.yml ADDED
@@ -0,0 +1,27 @@
1
+
2
+ language: ruby
3
+
4
+ env:
5
+ global:
6
+ - CC_TEST_REPORTER_ID=c38ec11990e222f0b5aa1254e9d97dd92a2eadbaeef9e5cc1c2eaa93e9322bae
7
+
8
+ install:
9
+ - bundle install --path ~/bundle
10
+
11
+ before_script:
12
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
+ - chmod +x ./cc-test-reporter
14
+ - ./cc-test-reporter before-build
15
+
16
+ script:
17
+ - bundle exec rspec
18
+
19
+ after_script:
20
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
21
+
22
+ rvm:
23
+ - 2.0
24
+ - 2.1
25
+ - 2.2
26
+ - 2.3
27
+ - 2.4
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ --private
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+
2
+ source "https://rubygems.org"
3
+
4
+ # Self.
5
+ gem "neverbounce-cli", path: Pathname(__dir__).realpath
6
+
7
+ gem "neverbounce-api", git: "https://github.com/NeverBounce/NeverBounceApi-Ruby.git"
8
+
9
+ group :development do
10
+ # Code coverage report.
11
+ gem "simplecov"
12
+
13
+ # RSpec.
14
+ gem "rspec"
15
+
16
+ # YARD and friends.
17
+ gem "redcarpet"
18
+ gem "yard"
19
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ GIT
2
+ remote: https://github.com/NeverBounce/NeverBounceApi-Ruby.git
3
+ revision: f7ecf950759aa61b818089cd1a1554bb93cb3851
4
+ specs:
5
+ neverbounce-api (1.0.0)
6
+ httparty (~> 0.15)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ neverbounce-cli (1.0.0)
12
+ neverbounce-api (~> 1.0.0)
13
+ terminal-table (~> 1.8.0)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ diff-lcs (1.3)
19
+ docile (1.1.5)
20
+ httparty (0.15.6)
21
+ multi_xml (>= 0.5.2)
22
+ json (2.1.0)
23
+ multi_xml (0.6.0)
24
+ redcarpet (3.4.0)
25
+ rspec (3.6.0)
26
+ rspec-core (~> 3.6.0)
27
+ rspec-expectations (~> 3.6.0)
28
+ rspec-mocks (~> 3.6.0)
29
+ rspec-core (3.6.0)
30
+ rspec-support (~> 3.6.0)
31
+ rspec-expectations (3.6.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.6.0)
34
+ rspec-mocks (3.6.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.6.0)
37
+ rspec-support (3.6.0)
38
+ simplecov (0.15.0)
39
+ docile (~> 1.1.0)
40
+ json (>= 1.8, < 3)
41
+ simplecov-html (~> 0.10.0)
42
+ simplecov-html (0.10.2)
43
+ terminal-table (1.8.0)
44
+ unicode-display_width (~> 1.1, >= 1.1.1)
45
+ unicode-display_width (1.3.0)
46
+ yard (0.9.9)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ neverbounce-api!
53
+ neverbounce-cli!
54
+ redcarpet
55
+ rspec
56
+ simplecov
57
+ yard
58
+
59
+ BUNDLED WITH
60
+ 1.15.3
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 NeverBounce
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,138 @@
1
+
2
+ <p align="center"><img src="https://neverbounce-marketing.s3.amazonaws.com/neverbounce_color_600px.png"></p>
3
+
4
+ <p align="center">
5
+ <a href="https://travis-ci.org/NeverBounce/NeverBounceCli-Ruby"><img src="https://travis-ci.org/NeverBounce/NeverBounceCli-Ruby.svg" alt="Build Status"></a>
6
+ <a href="https://codeclimate.com/github/NeverBounce/NeverBounceCli-Ruby/coverage"><img src="https://codeclimate.com/github/NeverBounce/NeverBounceCli-Ruby/badges/coverage.svg" /></a>
7
+ <a href="https://codeclimate.com/github/NeverBounce/NeverBounceCli-Ruby"><img src="https://codeclimate.com/github/NeverBounce/NeverBounceCli-Ruby/badges/gpa.svg" /></a>
8
+ </p>
9
+
10
+ NeverBounceCli-Ruby
11
+ ===================
12
+
13
+ This is the official NeverBounce V4 CLI written in Ruby. See also:
14
+
15
+ * Our Ruby API gem: https://github.com/NeverBounce/NeverBounceApi-Ruby.
16
+ * Our full RubyDoc documentation: http://rubydoc.info/github/NeverBounce/NeverBounceCli-Ruby.
17
+
18
+ ## Installation
19
+
20
+ In your `Gemfile`, add:
21
+
22
+ ```ruby
23
+ gem "neverbounce-api", git: "https://github.com/NeverBounce/NeverBounceApi-Ruby.git"
24
+ gem "neverbounce-cli", git: "https://github.com/NeverBounce/NeverBounceCli-Ruby.git"
25
+ ```
26
+
27
+ Install bundle, generate binstubs:
28
+
29
+ ```sh
30
+ $ bundle install
31
+ $ bundle binstub neverbounce-cli
32
+
33
+ $ ls bin
34
+ nb-account-info nb-jobs-delete nb-jobs-parse nb-jobs-search nb-jobs-status
35
+ nb-jobs-create nb-jobs-download nb-jobs-results nb-jobs-start nb-single-check
36
+ ```
37
+
38
+ Create `~/.neverbounce.yml`, add your API key there:
39
+
40
+ ```yaml
41
+ api_key: key123abc
42
+ ```
43
+
44
+ ## Usage
45
+
46
+ Before we begin, here's just 2 things you need to know to become a happy NeverBounce CLI user:
47
+
48
+ 1. Script names consistently map to our [REST API v4](https://developers.neverbounce.com/v4.0/).
49
+ <br />For example, `nb-single-check` calls `single/check`, `nb-jobs-create` calls `jobs/create` and so on.
50
+ 2. Every script supports `--help` and tells everything about itself.
51
+
52
+ Let's see what `nb-single-check` has to offer:
53
+
54
+ ```
55
+ $ bin/nb-single-check --help
56
+ nb-single-check - Check a single e-mail
57
+
58
+ USAGE: nb-single-check [options] [VAR1=value] [VAR2=value] ...
59
+
60
+ -h, --help Show help information
61
+
62
+ Environment variables:
63
+ * API_KEY - API key ("2ed45186c72f9319dc64338cdf16ab76b44cf3d1")
64
+ * EMAIL - E-mail to check ("alice@isp.com", "bob.smith+1@domain.com")
65
+ - ADDRESS_INFO - Request additional address info ("y", "n")
66
+ - API_URL - Custom API URL ("https://staging-api.isp.com/v5")
67
+ - CREDITS_INFO - Request additional credits info ("y", "n")
68
+ - CURL - Print cURL request and exit ("y", ["N"])
69
+ - RAW - Print raw response body ("y", ["N"])
70
+ - TIMEOUT - Timeout in seconds to verify the address ("5")
71
+ ```
72
+
73
+ Now, let's check an e-mail:
74
+
75
+ ```
76
+ $ bin/nb-single-check EMAIL=support@neverbounce.com
77
+
78
+ Response:
79
+ +--------+------------------+----------+----------+
80
+ | Result | Flags | SuggCorr | ExecTime |
81
+ +--------+------------------+----------+----------+
82
+ | valid | has_dns | | 651 |
83
+ | | has_dns_mx | | |
84
+ | | role_account | | |
85
+ | | smtp_connectable | | |
86
+ +--------+------------------+----------+----------+
87
+ ```
88
+
89
+ With a bit of tuning:
90
+
91
+ ```
92
+ $ bin/nb-single-check EMAIL=support@neverbounce.com CREDITS_INFO=y
93
+
94
+ Response:
95
+ <...like above...>
96
+
97
+ CreditsInfo:
98
+ +---------+----------+---------+----------+
99
+ | FreeRmn | FreeUsed | PaidRmn | PaidUsed |
100
+ +---------+----------+---------+----------+
101
+ | 969 | 1 | 1000000 | 0 |
102
+ +---------+----------+---------+----------+
103
+ ```
104
+
105
+ ## Advanced usage
106
+
107
+ ### Print cURL command with `CURL=y`
108
+
109
+ Each of our scripts can print command to make the request using native `curl` binary on your OS. For example:
110
+
111
+ ```
112
+ $ bin/nb-single-check EMAIL=support@neverbounce.com CURL=y
113
+ curl --request GET --url https://api.neverbounce.com/v4/single/check --header Content-Type:\ application/json
114
+ --data-binary \{\"email\":\"support@neverbounce.com\",\"key\":\"key123abc\"\}
115
+ ```
116
+
117
+ You can now pass this command around, use it in scripts etc.
118
+
119
+ ### Print raw response with `RAW=y`
120
+
121
+ Each of our scripts can print raw server response without decoding it. For example:
122
+
123
+ ```
124
+ $ bin/nb-single-check EMAIL=support@neverbounce.com RAW=y
125
+ {"status":"success","result":"valid","flags":["smtp_connectable","has_dns","has_dns_mx","role_account"],
126
+ "suggested_correction":"","execution_time":787}
127
+ ```
128
+
129
+ Although primary users of this feature is us at NeverBounce, you can also find it helpful once you encounter a server glitch and want to send us a meaningful bug report.
130
+
131
+ ## Compatibility
132
+
133
+ Minimum Ruby version is 2.0.
134
+
135
+ ## Copyright
136
+
137
+ NeverBounce CLI in Ruby is free and is licensed under the MIT License.
138
+ Copyright &copy; 2017 NeverBounce.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::AccountInfo.new.main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsCreate.new.main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsDelete.new.main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsDownload.new.main
data/exe/nb-jobs-parse ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsParse.new.main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsResults.new.main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsSearch.new.main
data/exe/nb-jobs-start ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsStart.new.main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::JobsStatus.new.main
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "neverbounce-cli"
4
+
5
+ exit NeverBounce::CLI::Script::SingleCheck.new.main
@@ -0,0 +1,20 @@
1
+
2
+ module NeverBounce; module CLI; module Feature
3
+ # Provide the basic method <tt>#initialize</tt> for the owner class.
4
+ # @see InstanceMethods#initialize
5
+ module BasicInitialize
6
+ # @param owner [Class]
7
+ # @return [nil]
8
+ def self.load(owner)
9
+ return if owner < InstanceMethods
10
+ owner.send(:include, InstanceMethods)
11
+ end
12
+
13
+ module InstanceMethods
14
+ # See source for details.
15
+ def initialize(attrs = {})
16
+ attrs.each { |k, v| public_send("#{k}=", v) }
17
+ end
18
+ end
19
+ end
20
+ end; end; end
@@ -0,0 +1,47 @@
1
+
2
+ module NeverBounce; module CLI; module Feature
3
+ # Eigenclass (singleton class)-based cache which allows to handle "hidden" instance variables.
4
+ # @see InstanceMethods#_cache
5
+ module Eigencache
6
+ # @param owner [Class]
7
+ # @return [nil]
8
+ def self.load(owner)
9
+ return if owner < InstanceMethods
10
+ owner.send(:include, InstanceMethods)
11
+ end
12
+
13
+ module InstanceMethods
14
+ # Hidden cache.
15
+ #
16
+ # def body
17
+ # _cache[:body] ||= File.read("my-bulky-body.csv")
18
+ # end
19
+ #
20
+ # def body=(v)
21
+ # _cache[:body] = v
22
+ # end
23
+ #
24
+ # @return [Hash]
25
+ def _cache
26
+ if eigen.instance_variable_defined?(k = :@cache)
27
+ eigen.instance_variable_get(k)
28
+ else
29
+ eigen.instance_variable_set(k, {})
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ # Object's eigenclass (singleton class).
36
+ # @return [Class]
37
+ def eigen
38
+ class << self; self; end
39
+ end
40
+ end
41
+ end
42
+ end; end; end
43
+
44
+ #
45
+ # Implementation notes:
46
+ #
47
+ # * As of Ruby 2.1 `Object#singleton_class` is introduced. We use our own compatible implementation, `eigen`.
@@ -0,0 +1,38 @@
1
+
2
+ require_relative "../envars"
3
+
4
+ module NeverBounce; module CLI; module Feature; module Envars
5
+ # A simple transformer/validator for <tt>examples</tt> argument.
6
+ #
7
+ # @see #process
8
+ class ExamplesMapper
9
+ # Process input, render output.
10
+ #
11
+ # process([1, 2, 3]) # => {values: [1, 2, 3]}
12
+ # process([1, 2, default: 3]) # => {values: [1, 2, 3], default: 3}
13
+ #
14
+ # @param input [Array] Items to process.
15
+ # @return [Hash] A hash with <tt>values</tt> and optionally <tt>default</tt>.
16
+ def process(input)
17
+ values, default = [], nil
18
+
19
+ input.each do |elem|
20
+ if elem.is_a? Hash
21
+ # Validate, then use.
22
+ raise ArgumentError, "Unknown element format: #{elem.inspect}" if elem.keys != [:default]
23
+ values << (default = elem[:default])
24
+ else
25
+ values << elem
26
+ end
27
+ end
28
+
29
+ # Return result.
30
+ {}.tap do |h|
31
+ h[:values] = values
32
+ h[:default] = default if default
33
+ end
34
+ end
35
+
36
+ alias_method :[], :process
37
+ end
38
+ end; end; end; end