snov 0.4.0 → 0.6.2

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: 7f589444e92f1101b625086d9e1d440952b52e1de3c9996183bc3908f7ec43c2
4
- data.tar.gz: cd4df386dd42c6c4f8c226526c0f42145b24b2bcdafb59019c12c6a01c417afe
3
+ metadata.gz: d7545d8e5ad029e0dcfe3c6070d81ecd37074a7b341dbffd7a49d1fb57de5b15
4
+ data.tar.gz: 0d78ebcc861f2daa89b8bcb684f2eed5357b388ae8d69a1546fa36946b19f4e4
5
5
  SHA512:
6
- metadata.gz: 4e53b2ea16a6ca434adaee244620863510b245c2dd48fd379f806bbe4ccb82e1e424b8992a351b34789da00410889312205486ec8917c509165f16f3e7751a21
7
- data.tar.gz: 338af6443df4e833f662934940a87e8dcb9ac43ffe7b9be6710c3a1c237e4ef2ce68196ff066d287e8f4cc508ee7207119746f4b0767d9477506d4fbbb28f21a
6
+ metadata.gz: aaa1ea3abffa6e35551c0a10532f080735660eb153f79ccc62aa379c42d28da8cebc914805276a17d451d4423e6344133ece32cf6a01933cc23f0670a7b573c0
7
+ data.tar.gz: a1cba7a4909499108923a8b2c9ec55ad741f64a6e561a35c95f2c169d4caa416788ef4b464fc662c55ce586c459b8fcb136205acd515d08115131746d8b32316
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,11 @@
1
+ * add OutOfCreditsError
2
+
3
+ ## [0.5.0]
4
+ * support for https://snov.io/api#EmailFinder (GetEmailsFromName)
5
+
6
+ ## [0.4.1]
7
+ * allow forward slash for test response files while using fake client
8
+
1
9
  ## [0.4.0]
2
10
  * search prospect emails with /v1/get-emails-from-url
3
11
 
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)
@@ -46,7 +46,7 @@ module Snov
46
46
  def filename(method, path, payload_hash)
47
47
  add = payload_hash.to_a.map { |v| v.join("=") }.join("&").tr(".", "_")
48
48
  add = "default" if add == ""
49
- "#{self.class.folder}/#{method}#{path.tr("/", "_")}/#{add}.json"
49
+ "#{self.class.folder}/#{method}#{path.tr("/", "_")}/#{add.gsub('/', '-')}.json"
50
50
  end
51
51
  end
52
52
  end
@@ -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
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.0"
2
+ VERSION = "0.6.2"
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.0
4
+ version: 0.6.2
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-11 00:00:00.000000000 Z
12
+ date: 2021-06-27 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
@@ -177,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
180
  - !ruby/object:Gem::Version
178
181
  version: '0'
179
182
  requirements: []
180
- rubygems_version: 3.2.3
183
+ rubygems_version: 3.2.15
181
184
  signing_key:
182
185
  specification_version: 4
183
186
  summary: Snov client to interact with snov api