snov 0.4.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67d94e3b6c521ed1d7d4d2c85dee46fe46309db78e3323bdd476a8f6fb62c33d
4
- data.tar.gz: ce1bb1e0ced90ae3d6f54ae92cc135d84171f5112143af9da3f3027e1cf5ad65
3
+ metadata.gz: bdda24419a71774b94883aeb77b4997e19b83534ba9d1bf8161c1fac641904d2
4
+ data.tar.gz: 7993cfb1396ed737663ccf3cde155124c4cbdefb14d6d6f92beb2c811fd22be5
5
5
  SHA512:
6
- metadata.gz: 7915a6077c1a7ca1920564060a7a6b298a70e36e10f103c97500bf4b01a6805bfc87e25be700526ad8dc835fc8913f61d253f0bd1b31e26468ee0c7995effd5b
7
- data.tar.gz: 1b9250834a8ef6e22928f1e141ad4b6bc126698a5438ad4833734a54ca40043d888f4336349b4ef2e9028cc6d3b307becf8a729be4239cad714d8fc6f1b34ed9
6
+ metadata.gz: bda2fe671da64c54230fc2e1d973e8f7a925c12d0caed733bcdb28da274fd0d58026848b96e31986b9bb8ecdc2545cbf5d4db6bef0046d86319396d7bfa6eaad
7
+ data.tar.gz: 167e4558d9bfdd2d89a0c817e4b53c29522ecf2432638d0ae4607a4e4b0559900feec167f38216fa69bb1803d6ea254bb90b95afe358e8c7878f6ee4054f5541
data/.byebug_history ADDED
@@ -0,0 +1,5 @@
1
+ continue
2
+ subject
3
+ exit
4
+ val["emails"]
5
+ val
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
@@ -183,6 +183,34 @@ see https://snov.io/api#GetEmailsFromUrl
183
183
  end
184
184
  ```
185
185
 
186
+ ### GetEmailsFromName
187
+
188
+ convenience wrapper for `GetEmailsFromName` to get a prospect with name
189
+
190
+ see https://snov.io/api#EmailFinder
191
+
192
+ ```ruby
193
+ prospect = Snov::GetEmailsFromName.new(first_name: "gavin", last_name: "vanrooyen", domain: "octagon.com").prospect
194
+
195
+ prospect.data.emails.each do |value|
196
+ puts value.email
197
+ puts value.email_status
198
+ end
199
+ ```
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
+
186
214
  ## Development
187
215
 
188
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
@@ -25,4 +25,6 @@ require 'snov/get_prospects_by_email'
25
25
  require 'snov/get_prospect_list'
26
26
  require 'snov/get_user_lists'
27
27
  require 'snov/get_emails_by_social_url'
28
+ require 'snov/get_emails_from_name'
29
+ require 'snov/add_names_to_find_emails'
28
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, :access_token
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)
@@ -0,0 +1,76 @@
1
+ module Snov
2
+ class GetEmailsFromName
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 prospect
13
+ @prospect ||= ProspectResult.new(raw_result)
14
+ end
15
+
16
+ def raw_result
17
+ @raw_result ||= client.post("/v1/get-emails-from-names",
18
+ "firstName" => @first_name,
19
+ "lastName" => @last_name,
20
+ "domain" => @domain)
21
+ .deep_transform_keys! { |key| key.underscore }
22
+ end
23
+
24
+ class ProspectData
25
+ include ActiveModel::Model
26
+
27
+ attr_accessor :first_name, :last_name, :domain, :name
28
+ attr_reader :emails
29
+
30
+ def emails=(val)
31
+ @emails = Array.wrap(val).map do |rel|
32
+ ProspectEmail.new(rel)
33
+ end
34
+ end
35
+ end
36
+
37
+ class ProspectEmail
38
+ include ActiveModel::Model
39
+
40
+ attr_accessor :email, :email_status
41
+ end
42
+
43
+ class ProspectStatus
44
+ include ActiveModel::Model
45
+
46
+ attr_accessor :identifier, :description
47
+
48
+ def completed?
49
+ identifier == 'complete'
50
+ end
51
+
52
+ def in_progress?
53
+ identifier == 'in_progress'
54
+ end
55
+
56
+ def not_found?
57
+ identifier == 'not_found'
58
+ end
59
+ end
60
+
61
+ class ProspectResult
62
+ include ActiveModel::Model
63
+
64
+ attr_accessor :success, :message, :params
65
+ attr_reader :data, :status
66
+
67
+ def data=(val)
68
+ @data = ProspectData.new(val)
69
+ end
70
+
71
+ def status=(val)
72
+ @status = ProspectStatus.new(val)
73
+ end
74
+ end
75
+ end
76
+ end
data/lib/snov/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Snov
2
- VERSION = "0.4.1"
2
+ VERSION = "0.6.3"
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.4.1
4
+ version: 0.6.3
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-05-17 00:00:00.000000000 Z
12
+ date: 2021-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -119,6 +119,7 @@ executables: []
119
119
  extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
+ - ".byebug_history"
122
123
  - ".gitignore"
123
124
  - ".rspec"
124
125
  - ".rubocop.yml"
@@ -133,6 +134,7 @@ files:
133
134
  - bin/setup
134
135
  - gems.rb
135
136
  - lib/snov.rb
137
+ - lib/snov/add_names_to_find_emails.rb
136
138
  - lib/snov/client.rb
137
139
  - lib/snov/domain_search.rb
138
140
  - lib/snov/fake_client.rb
@@ -148,6 +150,7 @@ files:
148
150
  - lib/snov/fake_client/post_v1_prospect-list/listId=1818597&page=1&perPage=100.json
149
151
  - lib/snov/get_all_prospects_from_list.rb
150
152
  - lib/snov/get_emails_by_social_url.rb
153
+ - lib/snov/get_emails_from_name.rb
151
154
  - lib/snov/get_profile_by_email.rb
152
155
  - lib/snov/get_prospect_list.rb
153
156
  - lib/snov/get_prospects_by_email.rb