neverbounce-api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +8 -0
- data/.gitignore +21 -0
- data/.rspec +4 -0
- data/.rubocop.yml +1161 -0
- data/.travis.yml +27 -0
- data/.yardopts +2 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +48 -0
- data/LICENSE +9 -0
- data/README.md +235 -0
- data/lib/never_bounce/api/client.rb +259 -0
- data/lib/never_bounce/api/error.rb +21 -0
- data/lib/never_bounce/api/feature/basic_initialize.rb +20 -0
- data/lib/never_bounce/api/feature/eigencache.rb +48 -0
- data/lib/never_bounce/api/feature/igetset.rb +41 -0
- data/lib/never_bounce/api/feature/oattrs.rb +100 -0
- data/lib/never_bounce/api/feature/require_attr.rb +27 -0
- data/lib/never_bounce/api/request/account_info.rb +29 -0
- data/lib/never_bounce/api/request/base.rb +102 -0
- data/lib/never_bounce/api/request/jobs_create.rb +90 -0
- data/lib/never_bounce/api/request/jobs_delete.rb +34 -0
- data/lib/never_bounce/api/request/jobs_download.rb +34 -0
- data/lib/never_bounce/api/request/jobs_parse.rb +55 -0
- data/lib/never_bounce/api/request/jobs_results.rb +53 -0
- data/lib/never_bounce/api/request/jobs_search.rb +57 -0
- data/lib/never_bounce/api/request/jobs_start.rb +47 -0
- data/lib/never_bounce/api/request/jobs_status.rb +37 -0
- data/lib/never_bounce/api/request/single_check.rb +67 -0
- data/lib/never_bounce/api/response/account_info.rb +39 -0
- data/lib/never_bounce/api/response/account_info/job_counts.rb +26 -0
- data/lib/never_bounce/api/response/address_info.rb +43 -0
- data/lib/never_bounce/api/response/base.rb +15 -0
- data/lib/never_bounce/api/response/container.rb +126 -0
- data/lib/never_bounce/api/response/credits_info/base.rb +30 -0
- data/lib/never_bounce/api/response/credits_info/monthly.rb +16 -0
- data/lib/never_bounce/api/response/credits_info/paid.rb +20 -0
- data/lib/never_bounce/api/response/error_message.rb +17 -0
- data/lib/never_bounce/api/response/feature/job_status_fields.rb +68 -0
- data/lib/never_bounce/api/response/feature/job_status_fields/total.rb +46 -0
- data/lib/never_bounce/api/response/jobs_create.rb +10 -0
- data/lib/never_bounce/api/response/jobs_delete.rb +8 -0
- data/lib/never_bounce/api/response/jobs_download.rb +19 -0
- data/lib/never_bounce/api/response/jobs_parse.rb +10 -0
- data/lib/never_bounce/api/response/jobs_results.rb +34 -0
- data/lib/never_bounce/api/response/jobs_results/item.rb +65 -0
- data/lib/never_bounce/api/response/jobs_results/query.rb +20 -0
- data/lib/never_bounce/api/response/jobs_search.rb +33 -0
- data/lib/never_bounce/api/response/jobs_search/query.rb +16 -0
- data/lib/never_bounce/api/response/jobs_search/result.rb +13 -0
- data/lib/never_bounce/api/response/jobs_start.rb +10 -0
- data/lib/never_bounce/api/response/jobs_status.rb +11 -0
- data/lib/never_bounce/api/response/message.rb +32 -0
- data/lib/never_bounce/api/response/single_check.rb +68 -0
- data/lib/never_bounce/api/response/status_message.rb +17 -0
- data/lib/never_bounce/api/response/success_message.rb +12 -0
- data/lib/never_bounce/api/session.rb +141 -0
- data/lib/never_bounce/api/version.rb +4 -0
- data/lib/neverbounce-api.rb +4 -0
- data/lib/neverbounce.rb +3 -0
- data/neverbounce-api.gemspec +20 -0
- data/spec/lib/never_bounce/api/client_spec.rb +199 -0
- data/spec/lib/never_bounce/api/feature/basic_initialize_spec.rb +25 -0
- data/spec/lib/never_bounce/api/feature/eigencache_spec.rb +28 -0
- data/spec/lib/never_bounce/api/feature/igetset_spec.rb +45 -0
- data/spec/lib/never_bounce/api/feature/oattrs_spec.rb +72 -0
- data/spec/lib/never_bounce/api/feature/require_attr_spec.rb +25 -0
- data/spec/lib/never_bounce/api/request/account_info_spec.rb +29 -0
- data/spec/lib/never_bounce/api/request/base_spec.rb +6 -0
- data/spec/lib/never_bounce/api/request/jobs_create_spec.rb +89 -0
- data/spec/lib/never_bounce/api/request/jobs_delete_spec.rb +31 -0
- data/spec/lib/never_bounce/api/request/jobs_download_spec.rb +31 -0
- data/spec/lib/never_bounce/api/request/jobs_parse_spec.rb +44 -0
- data/spec/lib/never_bounce/api/request/jobs_results_spec.rb +42 -0
- data/spec/lib/never_bounce/api/request/jobs_search_spec.rb +40 -0
- data/spec/lib/never_bounce/api/request/jobs_start_spec.rb +44 -0
- data/spec/lib/never_bounce/api/request/jobs_status_spec.rb +31 -0
- data/spec/lib/never_bounce/api/request/single_check_spec.rb +44 -0
- data/spec/lib/never_bounce/api/response/account_info/job_counts_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/account_info_spec.rb +9 -0
- data/spec/lib/never_bounce/api/response/address_info_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/base_spec.rb +6 -0
- data/spec/lib/never_bounce/api/response/container_spec.rb +142 -0
- data/spec/lib/never_bounce/api/response/credits_info/base_spec.rb +31 -0
- data/spec/lib/never_bounce/api/response/credits_info/monthly_spec.rb +11 -0
- data/spec/lib/never_bounce/api/response/credits_info/paid_spec.rb +11 -0
- data/spec/lib/never_bounce/api/response/feature/job_status_fields/total_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/feature/job_status_fields_spec.rb +42 -0
- data/spec/lib/never_bounce/api/response/jobs_create_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_delete_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_download_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_parse_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_results/jobs_results_item_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_results/jobs_results_query_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_results_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_search/jobs_search_query_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_search/jobs_search_result_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_search_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_start_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/jobs_status_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/single_check_spec.rb +7 -0
- data/spec/lib/never_bounce/api/response/spec_helper.rb +8 -0
- data/spec/lib/never_bounce/api/session_spec.rb +140 -0
- data/spec/lib/never_bounce/api_spec.rb +8 -0
- data/spec/spec_helper.rb +49 -0
- data/spec/spec_support/include_dir_context.rb +22 -0
- data/spec/spec_support/simplecov.rb +18 -0
- metadata +210 -0
data/.travis.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
language: ruby
|
3
|
+
|
4
|
+
env:
|
5
|
+
global:
|
6
|
+
- CC_TEST_REPORTER_ID=9300cb7898e254e78099399acbb2796471fde0e5c1873899273a583d56c9d740
|
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
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
source "https://rubygems.org"
|
3
|
+
|
4
|
+
# Self.
|
5
|
+
gem "neverbounce-api", path: Pathname(__dir__).realpath
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
# Code coverage report.
|
9
|
+
gem "simplecov"
|
10
|
+
|
11
|
+
# RSpec.
|
12
|
+
gem "rspec"
|
13
|
+
|
14
|
+
# YARD and friends.
|
15
|
+
gem "redcarpet"
|
16
|
+
gem "yard"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
neverbounce-api (1.0.0)
|
5
|
+
httparty (~> 0.15)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
docile (1.1.5)
|
12
|
+
httparty (0.15.6)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
json (2.1.0)
|
15
|
+
multi_xml (0.6.0)
|
16
|
+
redcarpet (3.4.0)
|
17
|
+
rspec (3.6.0)
|
18
|
+
rspec-core (~> 3.6.0)
|
19
|
+
rspec-expectations (~> 3.6.0)
|
20
|
+
rspec-mocks (~> 3.6.0)
|
21
|
+
rspec-core (3.6.0)
|
22
|
+
rspec-support (~> 3.6.0)
|
23
|
+
rspec-expectations (3.6.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.6.0)
|
26
|
+
rspec-mocks (3.6.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.6.0)
|
29
|
+
rspec-support (3.6.0)
|
30
|
+
simplecov (0.15.0)
|
31
|
+
docile (~> 1.1.0)
|
32
|
+
json (>= 1.8, < 3)
|
33
|
+
simplecov-html (~> 0.10.0)
|
34
|
+
simplecov-html (0.10.2)
|
35
|
+
yard (0.9.9)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
neverbounce-api!
|
42
|
+
redcarpet
|
43
|
+
rspec
|
44
|
+
simplecov
|
45
|
+
yard
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
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,235 @@
|
|
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/NeverBounceApi-Ruby"><img src="https://travis-ci.org/NeverBounce/NeverBounceApi-Ruby.svg" alt="Build Status"></a>
|
6
|
+
<a href="https://codeclimate.com/github/NeverBounce/NeverBounceApi-Ruby/coverage"><img src="https://codeclimate.com/github/NeverBounce/NeverBounceApi-Ruby/badges/coverage.svg" /></a>
|
7
|
+
<a href="https://codeclimate.com/github/NeverBounce/NeverBounceApi-Ruby"><img src="https://codeclimate.com/github/NeverBounce/NeverBounceApi-Ruby/badges/gpa.svg" /></a>
|
8
|
+
</p>
|
9
|
+
|
10
|
+
NeverBounceApi-Ruby
|
11
|
+
===================
|
12
|
+
|
13
|
+
This is the official NeverBounce V4 API for Ruby. See also:
|
14
|
+
|
15
|
+
* Our full RubyDoc documentation: http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby.
|
16
|
+
* Our full REST API documentation: https://developers.neverbounce.com/v4.0/.
|
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
|
+
```
|
25
|
+
|
26
|
+
Install bundle:
|
27
|
+
|
28
|
+
```sh
|
29
|
+
$ bundle install
|
30
|
+
```
|
31
|
+
|
32
|
+
In your Ruby code, do a:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require "neverbounce"
|
36
|
+
```
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
To talk to the API, create a `Client` object and call one of its request methods.
|
41
|
+
For example, let's get account info:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
client = NeverBounce::API::Client.new(api_key: "key123abc") # Insert YOUR key here.
|
45
|
+
resp = client.account_info
|
46
|
+
|
47
|
+
if resp.ok?
|
48
|
+
puts "Free credits used: #{resp.credits_info.free_credits_used}"
|
49
|
+
puts "Free credits remaining: #{resp.credits_info.free_credits_remaining}"
|
50
|
+
else
|
51
|
+
# This is a `Response::ErrorMessage`.
|
52
|
+
puts "Error: #{resp.status}: #{resp.message}"
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Now, let's check a single e-mail:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
resp = client.single_check(email: "support@neverbounce.com")
|
60
|
+
if resp.ok?
|
61
|
+
puts "Result: #{resp.result}"
|
62
|
+
puts "Flags: #{resp.flags.join(' ')}"
|
63
|
+
else
|
64
|
+
puts "Error: #{resp.status}: #{resp.message}"
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
### Error handling
|
69
|
+
|
70
|
+
Our API library raises subclasses of `API::Error` for higher-level errors and subclasses of `StandardError` in all other cases. This wrapper guarantees that you catch all errors from the API library:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
begin
|
74
|
+
client = NeverBounce::API::Client.new(...)
|
75
|
+
resp = client.jobs_create(...)
|
76
|
+
...
|
77
|
+
rescue => e
|
78
|
+
# Log the error with full backtrace.
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
If you're running a background job, it's generally better to **log the full backtrace** in case you encounter unexpected server behaviour or something like that.
|
83
|
+
|
84
|
+
## Client requests
|
85
|
+
|
86
|
+
This a is complete list of requests supported by `API::Client`.
|
87
|
+
|
88
|
+
### Get account information
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
resp = client.account_info
|
92
|
+
```
|
93
|
+
|
94
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#account_info-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#account-info).
|
95
|
+
|
96
|
+
### Check a single address
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
resp = client.single_check(email: "alice@isp.com")
|
100
|
+
resp = client.single_check(email: "alice@isp.com", address_info: true, credits_info: true, timeout: 3)
|
101
|
+
```
|
102
|
+
|
103
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#single_check-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#single-check).
|
104
|
+
|
105
|
+
### Create a bulk job
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
resp = client.jobs_create(supplied_input: [["alice@isp.com", "Alice Roberts"], ["bob.smith@gmail.com", "Bob Smith"]])
|
109
|
+
resp = client.jobs_create(remote_input: "http://isp.com/emails.csv")
|
110
|
+
resp = client.jobs_create(remote_input: "http://isp.com/emails.csv", filename: "emails.csv", run_sample: true)
|
111
|
+
resp = client.jobs_create(remote_input: "http://isp.com/emails.csv", filename: "emails.csv", auto_start: true)
|
112
|
+
```
|
113
|
+
|
114
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_create-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-create).
|
115
|
+
|
116
|
+
### Get bulk job status
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
resp = client.jobs_status(job_id: 123)
|
120
|
+
```
|
121
|
+
|
122
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_status-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-status).
|
123
|
+
|
124
|
+
### Get bulk job results
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
resp = client.jobs_results(job_id: 123)
|
128
|
+
resp = client.jobs_results(job_id: 123, page: 1, per_page: 20) # Grab the first 20.
|
129
|
+
|
130
|
+
# Process items:
|
131
|
+
resp.results.items.each do |item| ...
|
132
|
+
```
|
133
|
+
|
134
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_results-instance_method), [Item](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Response/JobsResults/Item.html), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-results).
|
135
|
+
|
136
|
+
### Download bulk job result as CSV
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
resp = client.jobs_download(job_id: 123)
|
140
|
+
|
141
|
+
# Parse:
|
142
|
+
emails = CSV.parse(resp.raw)
|
143
|
+
```
|
144
|
+
|
145
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_download-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-download).
|
146
|
+
|
147
|
+
### List/search bulk jobs
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
resp = client.jobs_search
|
151
|
+
resp = client.jobs_search(page: 1, per_page: 20) # Grab the first 20.
|
152
|
+
|
153
|
+
# Process items:
|
154
|
+
resp.results.each do |item|
|
155
|
+
```
|
156
|
+
|
157
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_search-instance_method), [Result](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Response/JobsSearch/Result.html), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-search).
|
158
|
+
|
159
|
+
### Start an existing bulk job
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
resp = client.jobs_start(job_id: 123)
|
163
|
+
```
|
164
|
+
|
165
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_start-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-start).
|
166
|
+
|
167
|
+
### Parse an existing bulk job
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
resp = client.jobs_parse(job_id: 123)
|
171
|
+
```
|
172
|
+
|
173
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_parse-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-parse).
|
174
|
+
|
175
|
+
### Delete a bulk job
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
resp = client.jobs_delete(job_id: 123)
|
179
|
+
```
|
180
|
+
|
181
|
+
See also: [method](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Client.html#jobs_delete-instance_method), [REST](https://developers.neverbounce.com/v4.0/reference#jobs-delete).
|
182
|
+
|
183
|
+
## Debugging in the console
|
184
|
+
|
185
|
+
When you make requests from the console, you'll notice that the responses don't show you any content, i.e. instance variables:
|
186
|
+
|
187
|
+
```
|
188
|
+
irb> resp = client.account_info
|
189
|
+
=> #<NeverBounce::API::Response::AccountInfo:0x0056245c3e56f8>
|
190
|
+
irb> resp.inspect
|
191
|
+
=> "#<NeverBounce::API::Response::AccountInfo:0x0056245c3e56f8>"
|
192
|
+
```
|
193
|
+
|
194
|
+
It happens because by design our response containers **lazy-load their attributes** upon first access. Let's request an attribute:
|
195
|
+
|
196
|
+
```
|
197
|
+
irb> resp.status
|
198
|
+
=> "success"
|
199
|
+
irb> resp
|
200
|
+
=> #<NeverBounce::API::Response::AccountInfo:0x0056245c3e56f8 @status="success">
|
201
|
+
```
|
202
|
+
|
203
|
+
In order to load **all** attributes use method `.touch`, like this:
|
204
|
+
|
205
|
+
```
|
206
|
+
irb> resp.touch
|
207
|
+
=> #<NeverBounce::API::Response::AccountInfo:0x0056245c3e56f8 @status="success",
|
208
|
+
@execution_time=98, @credits_info=#<NeverBounce::API::Response::CreditsInfo::Paid:0x0056245c430478
|
209
|
+
@paid_credits_used=0, @free_credits_used=0, @paid_credits_remaining=1000000,
|
210
|
+
@free_credits_remaining=973>,@job_counts=#<NeverBounce::API::Response::AccountInfo::JobCounts:0x0056245c430310
|
211
|
+
@completed=10, @processing=0, @queued=0, @under_review=0>>
|
212
|
+
```
|
213
|
+
|
214
|
+
This is true for all API response containers and sub-containers. See [#touch](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Feature/Oattrs/InstanceMethods.html#touch-instance_method) in the docs.
|
215
|
+
|
216
|
+
## Advanced usage
|
217
|
+
|
218
|
+
For most regular tasks `Client` is powerful enough. However, if you need more control, you can use [Request](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Request.html), [Session](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Session.html) and [Response](http://rubydoc.info/github/NeverBounce/NeverBounceApi-Ruby/NeverBounce/API/Response/SuccessMessage.html) classes directly. Please refer to the online docs.
|
219
|
+
|
220
|
+
For example, our [CLI gem](https://github.com/NeverBounce/NeverBounceCli-Ruby) uses them.
|
221
|
+
|
222
|
+
## Command line interface
|
223
|
+
|
224
|
+
We've got a gem called [neverbounce-cli](https://github.com/NeverBounce/NeverBounceCli-Ruby) which gives you a set of powerful CLI scripts to use our API.
|
225
|
+
|
226
|
+
We recommend to install the CLI to have these tools at hand.
|
227
|
+
|
228
|
+
## Compatibility
|
229
|
+
|
230
|
+
Minimum Ruby version is 2.0.
|
231
|
+
|
232
|
+
## Copyright
|
233
|
+
|
234
|
+
NeverBounce API for Ruby is free and is licensed under the MIT License.
|
235
|
+
Copyright © 2017 NeverBounce.
|
@@ -0,0 +1,259 @@
|
|
1
|
+
|
2
|
+
require "never_bounce/api/error"
|
3
|
+
require "never_bounce/api/feature/basic_initialize"
|
4
|
+
require "never_bounce/api/feature/require_attr"
|
5
|
+
|
6
|
+
module NeverBounce; module API
|
7
|
+
# API client.
|
8
|
+
#
|
9
|
+
# client = NeverBounce::API::Client.new(api_key: "api_key")
|
10
|
+
#
|
11
|
+
# response = client.account_info
|
12
|
+
# # => #<NeverBounce::API::Response::AccountInfo> or
|
13
|
+
# # => #<NeverBounce::API::ErrorMessage>
|
14
|
+
#
|
15
|
+
# response = client.single_check(credits_info: true, email: "support@neverbounce.com", timeout: 3)
|
16
|
+
# # => #<NeverBounce::API::Response::JobsDownload> or
|
17
|
+
# # => #<NeverBounce::API::ErrorMessage>
|
18
|
+
#
|
19
|
+
# response = client.jobs_search(page: 1, per_page: 10)
|
20
|
+
# # => #<NeverBounce::API::Response::JobsSearch> or
|
21
|
+
# # => #<NeverBounce::API::ErrorMessage>
|
22
|
+
#
|
23
|
+
# # ...
|
24
|
+
#
|
25
|
+
# @see #account_info
|
26
|
+
# @see #jobs_create
|
27
|
+
# @see #jobs_delete
|
28
|
+
# @see #jobs_download
|
29
|
+
# @see #jobs_parse
|
30
|
+
# @see #jobs_results
|
31
|
+
# @see #jobs_search
|
32
|
+
# @see #jobs_start
|
33
|
+
# @see #jobs_status
|
34
|
+
# @see #single_check
|
35
|
+
# @see https://developers.neverbounce.com/v4.0/reference
|
36
|
+
class Client
|
37
|
+
Feature::BasicInitialize.load(self)
|
38
|
+
Feature::RequireAttr.load(self)
|
39
|
+
|
40
|
+
attr_writer :api_key
|
41
|
+
|
42
|
+
# API key.
|
43
|
+
# @return [String]
|
44
|
+
def api_key
|
45
|
+
@api_key or raise AttributeError, "Attribute must be set: api_key"
|
46
|
+
end
|
47
|
+
|
48
|
+
#--------------------------------------- Misc
|
49
|
+
|
50
|
+
# Wrap request in a session, return response.
|
51
|
+
# @param request [Object] An instance of {Request::Base} successor.
|
52
|
+
# @return [Object] Result of {Session#response}.
|
53
|
+
def response_to(request)
|
54
|
+
Session.new(request: request).response
|
55
|
+
end
|
56
|
+
private :response_to
|
57
|
+
|
58
|
+
#--------------------------------------- Requests
|
59
|
+
|
60
|
+
# Make an <tt>account/info</tt> request.
|
61
|
+
# @return [Response::AccountInfo]
|
62
|
+
# @return [Response::ErrorMessage]
|
63
|
+
# @raise [API::Error]
|
64
|
+
# @raise [StandardError]
|
65
|
+
# @see Request::AccountInfo
|
66
|
+
# @see https://developers.neverbounce.com/v4.0/reference#account-info
|
67
|
+
def account_info
|
68
|
+
response_to(Request::AccountInfo.new({
|
69
|
+
api_key: api_key,
|
70
|
+
}))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Make a <tt>jobs/create</tt> request.
|
74
|
+
# @param auto_parse [Boolean]
|
75
|
+
# @param auto_start [Boolean]
|
76
|
+
# @param filename [Boolean] Default is <tt>"YYYYMMDD-HHMMSS.csv"</tt> based on current time.
|
77
|
+
# @param remote_input [String] E.g. <tt>"http://isp.com/emails.csv"</tt>.
|
78
|
+
# @param run_sample [Boolean]
|
79
|
+
# @param supplied_input [Array<Array<email, name>>] E.g. <tt>[["alice@isp.com", "Alice Roberts"], ["bob.smith@gmail.com", "Bob Smith"]]</tt>.
|
80
|
+
# @return [Response::JobsCreate]
|
81
|
+
# @return [Response::ErrorMessage]
|
82
|
+
# @raise [API::Error]
|
83
|
+
# @raise [StandardError]
|
84
|
+
# @see Request::JobsCreate
|
85
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-create
|
86
|
+
def jobs_create(auto_parse: nil, auto_start: nil, filename: nil, remote_input: nil, run_sample: nil, supplied_input: nil)
|
87
|
+
raise ArgumentError, "`remote_input` and `supplied_input` can't both be given" if remote_input && supplied_input
|
88
|
+
|
89
|
+
input_location = if (v = remote_input)
|
90
|
+
# NOTE: Logical order: type, then value.
|
91
|
+
input = v
|
92
|
+
"remote_url"
|
93
|
+
elsif (v = supplied_input)
|
94
|
+
input = v
|
95
|
+
"supplied"
|
96
|
+
else
|
97
|
+
# NOTE: Not exactly sure what to raise here. From procedure standpoint missing argument is an `ArgumentError`.
|
98
|
+
raise ArgumentError, "Input not given, use `remote_input` or `supplied_input`"
|
99
|
+
end
|
100
|
+
|
101
|
+
filename ||= Time.now.strftime("%Y%m%d-%H%M%S.csv")
|
102
|
+
|
103
|
+
response_to(API::Request::JobsCreate.new({
|
104
|
+
api_key: api_key,
|
105
|
+
auto_parse: auto_parse,
|
106
|
+
auto_start: auto_start,
|
107
|
+
filename: filename,
|
108
|
+
input: input,
|
109
|
+
input_location: input_location,
|
110
|
+
run_sample: run_sample,
|
111
|
+
}))
|
112
|
+
end
|
113
|
+
|
114
|
+
# Make a <tt>jobs/delete</tt> request.
|
115
|
+
# @param job_id [Integer]
|
116
|
+
# @return [Response::JobsDelete]
|
117
|
+
# @return [Response::ErrorMessage]
|
118
|
+
# @raise [API::Error]
|
119
|
+
# @raise [StandardError]
|
120
|
+
# @see Request::JobsDelete
|
121
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-delete
|
122
|
+
def jobs_delete(job_id: nil)
|
123
|
+
response_to(Request::JobsDelete.new({
|
124
|
+
api_key: api_key,
|
125
|
+
job_id: job_id,
|
126
|
+
}))
|
127
|
+
end
|
128
|
+
|
129
|
+
# Make a <tt>jobs/download</tt> request.
|
130
|
+
# @param job_id [Integer]
|
131
|
+
# @return [Response::JobsDownload]
|
132
|
+
# @return [Response::ErrorMessage]
|
133
|
+
# @raise [API::Error]
|
134
|
+
# @raise [StandardError]
|
135
|
+
# @see Request::JobsDownload
|
136
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-download
|
137
|
+
def jobs_download(job_id: nil)
|
138
|
+
response_to(Request::JobsDownload.new({
|
139
|
+
api_key: api_key,
|
140
|
+
job_id: job_id,
|
141
|
+
}))
|
142
|
+
end
|
143
|
+
|
144
|
+
# Make a <tt>jobs/parse</tt> request.
|
145
|
+
# @param auto_start [Boolean]
|
146
|
+
# @param job_id [Integer]
|
147
|
+
# @return [Response::JobsParse]
|
148
|
+
# @return [Response::ErrorMessage]
|
149
|
+
# @raise [API::Error]
|
150
|
+
# @raise [StandardError]
|
151
|
+
# @see Request::JobsParse
|
152
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-parse
|
153
|
+
def jobs_parse(auto_start: nil, job_id: nil)
|
154
|
+
response_to(Request::JobsParse.new({
|
155
|
+
api_key: api_key,
|
156
|
+
auto_start: auto_start,
|
157
|
+
job_id: job_id,
|
158
|
+
}))
|
159
|
+
end
|
160
|
+
|
161
|
+
# Make a <tt>jobs/results</tt> request.
|
162
|
+
# @param job_id [Integer]
|
163
|
+
# @param page [Integer]
|
164
|
+
# @param per_page [Integer]
|
165
|
+
# @return [Response::JobsResults]
|
166
|
+
# @return [Response::ErrorMessage]
|
167
|
+
# @raise [API::Error]
|
168
|
+
# @raise [StandardError]
|
169
|
+
# @see Request::JobsResults
|
170
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-results
|
171
|
+
def jobs_results(job_id: nil, page: 1, per_page: nil)
|
172
|
+
response_to(Request::JobsResults.new({
|
173
|
+
api_key: api_key,
|
174
|
+
job_id: job_id,
|
175
|
+
page: page,
|
176
|
+
per_page: per_page,
|
177
|
+
}))
|
178
|
+
end
|
179
|
+
|
180
|
+
# Make a <tt>jobs/search</tt> request.
|
181
|
+
# @param job_id [Integer]
|
182
|
+
# @param page [Integer]
|
183
|
+
# @param per_page [Integer]
|
184
|
+
# @return [Response::JobsSearch]
|
185
|
+
# @return [Response::ErrorMessage]
|
186
|
+
# @raise [API::Error]
|
187
|
+
# @raise [StandardError]
|
188
|
+
# @see Request::JobsSearch
|
189
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-search
|
190
|
+
def jobs_search(job_id: nil, page: 1, per_page: nil)
|
191
|
+
response_to(Request::JobsSearch.new({
|
192
|
+
api_key: api_key,
|
193
|
+
job_id: job_id,
|
194
|
+
page: page,
|
195
|
+
per_page: per_page,
|
196
|
+
}))
|
197
|
+
end
|
198
|
+
|
199
|
+
# Make a <tt>jobs/start</tt> request.
|
200
|
+
# @param job_id [Integer]
|
201
|
+
# @param run_sample [Boolean]
|
202
|
+
# @return [Response::JobsResults]
|
203
|
+
# @return [Response::ErrorMessage]
|
204
|
+
# @raise [API::Error]
|
205
|
+
# @raise [StandardError]
|
206
|
+
# @see Request::JobsResults
|
207
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-start
|
208
|
+
def jobs_start(job_id: nil, run_sample: nil)
|
209
|
+
response_to(Request::JobsStart.new({
|
210
|
+
api_key: api_key,
|
211
|
+
job_id: job_id,
|
212
|
+
run_sample: run_sample,
|
213
|
+
}))
|
214
|
+
end
|
215
|
+
|
216
|
+
# Make a <tt>jobs/status</tt> request.
|
217
|
+
# @param job_id [Integer]
|
218
|
+
# @return [Response::JobsStatus]
|
219
|
+
# @return [Response::ErrorMessage]
|
220
|
+
# @raise [API::Error]
|
221
|
+
# @raise [StandardError]
|
222
|
+
# @see Request::JobsStatus
|
223
|
+
# @see https://developers.neverbounce.com/v4.0/reference#jobs-status
|
224
|
+
def jobs_status(job_id: nil)
|
225
|
+
response_to(Request::JobsStatus.new({
|
226
|
+
api_key: api_key,
|
227
|
+
job_id: job_id,
|
228
|
+
}))
|
229
|
+
end
|
230
|
+
|
231
|
+
# Make a <tt>single/check</tt> request.
|
232
|
+
# @param address_info [Boolean]
|
233
|
+
# @param credits_info [Boolean]
|
234
|
+
# @param email [String]
|
235
|
+
# @param timeout [Integer]
|
236
|
+
# @return [Response::SingleCheck]
|
237
|
+
# @return [Response::ErrorMessage]
|
238
|
+
# @raise [API::Error]
|
239
|
+
# @raise [StandardError]
|
240
|
+
# @see Request::SingleCheck
|
241
|
+
# @see https://developers.neverbounce.com/v4.0/reference#single-check
|
242
|
+
def single_check(address_info: nil, credits_info: nil, email: nil, timeout: nil)
|
243
|
+
response_to(Request::SingleCheck.new({
|
244
|
+
address_info: address_info,
|
245
|
+
api_key: api_key,
|
246
|
+
credits_info: credits_info,
|
247
|
+
email: email,
|
248
|
+
timeout: timeout,
|
249
|
+
}))
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end; end
|
253
|
+
|
254
|
+
#
|
255
|
+
# Implementation notes:
|
256
|
+
#
|
257
|
+
# * `api_key` is so common that we validate its presence in reader method rather than elsewhere.
|
258
|
+
# Hence there isn't a `require_attr(:api_key)` anywhere.
|
259
|
+
# `api_key` is Client's own business, hence the presence validation at this level.
|