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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29a980f1ec57e85a5f0fbf089fdcb646e5a66454c91515d90e33b7aaec042ac6
4
- data.tar.gz: 17e52baa847e7f42eba8696e35509f7478582696092a8e0cd229cf108c097d5c
3
+ metadata.gz: 83ba4d0a62cbaa8174ff7b35a0ec270fa9d1b5381743aedc80dd0d6d834f021e
4
+ data.tar.gz: d3d598766a17f72df681ab1cccdc951f7582647dfadc45642d9679953d501636
5
5
  SHA512:
6
- metadata.gz: 9ce75c52ecf8c7bd180ad2a2b4ea510acb494b59060f779424c0d5db7888ca18c75d9eb16ed8b66b58e46555a193e89f41b8df760177f0bd70f6076e3b94a9b9
7
- data.tar.gz: 41e171a1eaa943b01e82369979939f2f28523ed3a2835029453918965b324946a1507e8dae64df88980e603073d50d8d9c1de9612fd9f0017745cfca96733e0b
6
+ metadata.gz: a9a3b218b1d8689904f37e579e71349bb5ef29caf3f9360ed854fd346c0cad55255a989cbf877e561dce09bf0225bc3cdd4302a6004faa73602b59409b68a4e9
7
+ data.tar.gz: 1d713a008faccc5cbb2487c324c0451d5181e23752b5571f6338af584c99795c5cdb0ace999986db278df2dae1e17b3ae0420f9cfb4118b7732f6a435571aa72
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ * add OutOfCreditsError
2
+
3
+ ## [0.5.0]
4
+ * support for https://snov.io/api#EmailFinder (GetEmailsFromName)
5
+
1
6
  ## [0.4.1]
2
7
  * allow forward slash for test response files while using fake client
3
8
 
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
@@ -26,4 +26,5 @@ require 'snov/get_prospect_list'
26
26
  require 'snov/get_user_lists'
27
27
  require 'snov/get_emails_by_social_url'
28
28
  require 'snov/get_emails_from_name'
29
+ require 'snov/add_names_to_find_emails'
29
30
  require 'snov/domain_search'
@@ -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 = ERROR_CLASSES.fetch(resp.status, ResponseError)
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
@@ -1,3 +1,3 @@
1
1
  module Snov
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
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.5.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-18 00:00:00.000000000 Z
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