snov 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +13 -0
- data/lib/snov.rb +1 -0
- data/lib/snov/add_names_to_find_emails.rb +30 -0
- data/lib/snov/client.rb +11 -1
- data/lib/snov/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83ba4d0a62cbaa8174ff7b35a0ec270fa9d1b5381743aedc80dd0d6d834f021e
|
4
|
+
data.tar.gz: d3d598766a17f72df681ab1cccdc951f7582647dfadc45642d9679953d501636
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9a3b218b1d8689904f37e579e71349bb5ef29caf3f9360ed854fd346c0cad55255a989cbf877e561dce09bf0225bc3cdd4302a6004faa73602b59409b68a4e9
|
7
|
+
data.tar.gz: 1d713a008faccc5cbb2487c324c0451d5181e23752b5571f6338af584c99795c5cdb0ace999986db278df2dae1e17b3ae0420f9cfb4118b7732f6a435571aa72
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -198,6 +198,19 @@ see https://snov.io/api#EmailFinder
|
|
198
198
|
end
|
199
199
|
```
|
200
200
|
|
201
|
+
### AddNamesToFindEmails
|
202
|
+
|
203
|
+
convenience wrapper for `AddNamesToFindEmails` to add a prospect with name
|
204
|
+
|
205
|
+
see https://snov.io/api#AddNamestoFindEmails
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
added_name = Snov::AddNamesToFindEmails.new(first_name: "gavin", last_name: "vanrooyen", domain: "octagon.com").add
|
209
|
+
|
210
|
+
puts added_name.sent # true added to snov queue for searching
|
211
|
+
puts added_name.success
|
212
|
+
```
|
213
|
+
|
201
214
|
## Development
|
202
215
|
|
203
216
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/snov.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Snov
|
2
|
+
class AddNamesToFindEmails
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(client: Snov.client, first_name:, last_name:, domain:)
|
6
|
+
@client = client
|
7
|
+
@first_name = first_name
|
8
|
+
@last_name = last_name
|
9
|
+
@domain = domain
|
10
|
+
end
|
11
|
+
|
12
|
+
def add
|
13
|
+
@add ||= ProspectResult.new(raw_result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def raw_result
|
17
|
+
@raw_result ||= client.post("/v1/add-names-to-find-emails",
|
18
|
+
"firstName" => @first_name,
|
19
|
+
"lastName" => @last_name,
|
20
|
+
"domain" => @domain)
|
21
|
+
.deep_transform_keys! { |key| key.underscore }
|
22
|
+
end
|
23
|
+
|
24
|
+
class ProspectResult
|
25
|
+
include ActiveModel::Model
|
26
|
+
|
27
|
+
attr_accessor :success, :first_name, :last_name, :domain, :user_id, :sent
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/snov/client.rb
CHANGED
@@ -22,6 +22,8 @@ module Snov
|
|
22
22
|
|
23
23
|
class BadGatewayError < ResponseError; end
|
24
24
|
|
25
|
+
class OutOfCreditsError < BadGatewayError; end
|
26
|
+
|
25
27
|
class ForbiddenError < ResponseError; end
|
26
28
|
|
27
29
|
class GatewayTimeOut < ResponseError; end
|
@@ -33,6 +35,14 @@ module Snov
|
|
33
35
|
ERROR_CLASSES = { 401 => UnauthorizedError, 502 => BadGatewayError, 403 => ForbiddenError,
|
34
36
|
504 => GatewayTimeOut, 400 => BadRequest, 405 => MethodNotAllowed }
|
35
37
|
|
38
|
+
def self.select_error_class(resp, fallback: ResponseError)
|
39
|
+
if resp&.body.to_s.include?('you ran out of credits')
|
40
|
+
OutOfCreditsError
|
41
|
+
else
|
42
|
+
ERROR_CLASSES.fetch(resp.status, fallback)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
36
46
|
def initialize(client_id:, client_secret:, access_token: nil, timeout_seconds: 90)
|
37
47
|
self.client_id = client_id.to_str
|
38
48
|
self.client_secret = client_secret.to_str
|
@@ -66,7 +76,7 @@ module Snov
|
|
66
76
|
|
67
77
|
def parse_response(resp, path, _params)
|
68
78
|
unless resp.success?
|
69
|
-
error_class =
|
79
|
+
error_class = Client.select_error_class(resp, fallback: ResponseError)
|
70
80
|
raise error_class.new("#{path} (#{resp.status})", response: resp&.body)
|
71
81
|
end
|
72
82
|
MultiJson.load(resp.body)
|
data/lib/snov/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Petersen-Speelman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-06-
|
12
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- bin/setup
|
135
135
|
- gems.rb
|
136
136
|
- lib/snov.rb
|
137
|
+
- lib/snov/add_names_to_find_emails.rb
|
137
138
|
- lib/snov/client.rb
|
138
139
|
- lib/snov/domain_search.rb
|
139
140
|
- lib/snov/fake_client.rb
|