enrich-api 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 37f45990f1be5bce18af3ddf71d80511a5ed49e4
4
+ data.tar.gz: 54401a9dc12c152106112931515d60b819264ad4
5
+ SHA512:
6
+ metadata.gz: 5953fe739691b0e09c7e29202d22efa55f059cfdad942e92fe37ec169e1087ccfc172126fc7a739d978fef75757a5372872c1a1cfe2f6042f1e8ed2ea66ecd3f
7
+ data.tar.gz: d92dfa40089fba33c72c28c3c4002f2f0b7fe8acb39776dc902effaa0459d21a27fdc6f146eb47818d6393427dc7f86f6f4089703f3ae4b8e2beb0b327387088
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ *.rbc
3
+
4
+ /.bundle/
5
+ /vendor/
6
+
7
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gem "rest-client"
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Enrich
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,100 @@
1
+ # enrich-api-ruby
2
+
3
+ The Enrich API Ruby wrapper. Enrich, Search and Verify data from your Ruby services.
4
+
5
+ Copyright 2017 Enrich. See LICENSE for copying information.
6
+
7
+ * **📝 Implements**: [Enrich REST API ~ v1](https://docs.enrichdata.com/api/v1/) at reference revision: 07/24/2017
8
+ * **😘 Maintainer**: [@valeriansaliou](https://github.com/valeriansaliou)
9
+
10
+ ## Usage
11
+
12
+ Add the library to your `Gemfile`:
13
+
14
+ ```bash
15
+ gem 'enrich-api', '~> 1.0'
16
+ ```
17
+
18
+ Then, import it:
19
+
20
+ ```ruby
21
+ require 'enrich-api'
22
+ ```
23
+
24
+ Construct a new authenticated Enrich client with your `user_id` and `secret_key` tokens (you can generate those from your Enrich Dashboard, [see the docs](https://docs.enrichdata.com/api/v1/)).
25
+
26
+ ```ruby
27
+ client = Enrich::Client.new
28
+
29
+ client.authenticate("ui_xxxxxx", "sk_xxxxxx")
30
+ ```
31
+
32
+ Then, consume the client eg. to enrich an email address:
33
+
34
+ ```ruby
35
+ data = client.enrich.person({
36
+ email: "valerian@crisp.chat"
37
+ })
38
+ ```
39
+
40
+ ## Authentication
41
+
42
+ To authenticate against the API, generate your tokens (`user_id` and `secret_key`) **once** from your [Enrich Dashboard](https://dashboard.enrichdata.com/).
43
+
44
+ Then, pass those tokens **once** when you instanciate the Enrich client as following:
45
+
46
+ ```ruby
47
+ # Make sure to replace 'user_id' and 'secret_key' with your tokens
48
+ client.authenticate("user_id", "secret_key")
49
+ ```
50
+
51
+ ## Data Discovery
52
+
53
+ **When Enrich doesn't know about a given data point, eg. an email that was never enriched before, it launches a discovery. Discoveries can take a few seconds, and sometimes more than 10 seconds.**
54
+
55
+ This library implements a retry logic with a timeout if the discovery takes too long, or if the item wasn't found.
56
+
57
+ Thus, you can expect some requests, especially the Enrich requests, to take more time than expected. This is normal, and is not a performance issue on your side, or on our side. Under the hood, when you request a data point (eg. enrich a person given an email) that doesn't yet exist in our databases, the Enrich API returns the HTTP response `201 Created`. Then, this library will poll the enrich resource for results, with intervals of a few seconds. The API will return `404 Not Found` as the discovery is still processing and no result is yet known at this point. Once a result is found, the API will reply with `200 OK` and return discovered data. If the discovery fails and no data can be aggregated for this email, the library aborts the retry after some time (less than 20 seconds), and returns a `not_found` error.
58
+
59
+ If a requested data point is already known by the Enrich API, it will be immediately returned, which won't induce any delay.
60
+
61
+ ## Resource Methods
62
+
63
+ This library implements all methods the Enrich API provides. See the [API docs](https://docs.enrichdata.com/api/v1/) for a reference of available methods, as well as how returned data is formatted.
64
+
65
+ ### Verify API
66
+
67
+ #### Validate an Email
68
+
69
+ * **Method:** `client.verify.validate_email(query)`
70
+ * **Docs:** [https://docs.enrichdata.com/api/v1/#validate-an-email](https://docs.enrichdata.com/api/v1/#validate-an-email)
71
+
72
+ ```ruby
73
+ data = client.verify.validate_email({
74
+ email: "valerian@crisp.chat"
75
+ })
76
+ ```
77
+
78
+ ### Enrich API
79
+
80
+ #### Enrich a Person
81
+
82
+ * **Method:** `client.enrich.person(query)`
83
+ * **Docs:** [https://docs.enrichdata.com/api/v1/#enrich-a-person](https://docs.enrichdata.com/api/v1/#enrich-a-person)
84
+
85
+ ```ruby
86
+ data = client.enrich.person({
87
+ email: "valerian@crisp.chat"
88
+ })
89
+ ```
90
+
91
+ #### Enrich a Network
92
+
93
+ * **Method:** `client.enrich.network(query)`
94
+ * **Docs:** [https://docs.enrichdata.com/api/v1/#enrich-a-network](https://docs.enrichdata.com/api/v1/#enrich-a-network)
95
+
96
+ ```ruby
97
+ data = client.enrich.network({
98
+ ip: "178.62.89.169"
99
+ })
100
+ ```
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'enrich-api'
3
+ s.version = '1.1.3'
4
+ s.date = Date.today
5
+ s.summary = "Enrich API Ruby"
6
+ s.description = "Enrich API Ruby"
7
+ s.authors = ["Valerian Saliou"]
8
+ s.email = 'valerian@valeriansaliou.name'
9
+ s.files = `git ls-files`.split($/)
10
+ s.homepage = 'https://enrichdata.com'
11
+ s.license = 'MIT'
12
+ s.require_paths = ['lib']
13
+
14
+ s.add_dependency 'rest-client', '~> 2.0.0'
15
+ end
@@ -0,0 +1,21 @@
1
+ ##
2
+ # enrich-api-ruby
3
+ #
4
+ # Copyright 2017, Valerian Saliou
5
+ # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
+ ##
7
+
8
+ require 'enrich-api'
9
+
10
+ client = Enrich::Client.new
11
+
12
+ client.authenticate(
13
+ "ui_a311da78-6b89-459c-8028-b331efab20d5",
14
+ "sk_f293d44f-675d-4cb1-9c78-52b8a9af0df2"
15
+ )
16
+
17
+ data = client.enrich.network({
18
+ ip: "178.62.89.169"
19
+ })
20
+
21
+ puts data.inspect
@@ -0,0 +1,21 @@
1
+ ##
2
+ # enrich-api-ruby
3
+ #
4
+ # Copyright 2017, Valerian Saliou
5
+ # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
+ ##
7
+
8
+ require 'enrich-api'
9
+
10
+ client = Enrich::Client.new
11
+
12
+ client.authenticate(
13
+ "ui_a311da78-6b89-459c-8028-b331efab20d5",
14
+ "sk_f293d44f-675d-4cb1-9c78-52b8a9af0df2"
15
+ )
16
+
17
+ data = client.enrich.person({
18
+ email: "valerian@crisp.chat"
19
+ })
20
+
21
+ puts data.inspect
@@ -0,0 +1,21 @@
1
+ ##
2
+ # enrich-api-ruby
3
+ #
4
+ # Copyright 2017, Valerian Saliou
5
+ # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
+ ##
7
+
8
+ require 'enrich-api'
9
+
10
+ client = Enrich::Client.new
11
+
12
+ client.authenticate(
13
+ "ui_a311da78-6b89-459c-8028-b331efab20d5",
14
+ "sk_f293d44f-675d-4cb1-9c78-52b8a9af0df2"
15
+ )
16
+
17
+ data = client.verify.validate_email({
18
+ email: "valerian@crisp.chat"
19
+ })
20
+
21
+ puts data.inspect
@@ -0,0 +1,113 @@
1
+ ##
2
+ # enrich-api-ruby
3
+ #
4
+ # Copyright 2017, Valerian Saliou
5
+ # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
+ ##
7
+
8
+ require 'rest-client'
9
+ require 'json'
10
+
11
+ require_relative 'resources/enrich'
12
+ require_relative 'resources/verify'
13
+
14
+ module Enrich
15
+ class Client
16
+ attr_writer :rest_host
17
+ attr_writer :rest_base_path
18
+
19
+ attr_accessor :enrich
20
+ attr_accessor :verify
21
+
22
+ @@created_status_code = 201
23
+ @@not_found_status_code = 404
24
+ @@created_retry_count_max = 2
25
+
26
+ def initialize()
27
+ @auth = {}
28
+
29
+ @enrich = Enrich::EnrichResource.new(self)
30
+ @verify = Enrich::VerifyResource.new(self)
31
+ end
32
+
33
+ public
34
+
35
+ def authenticate(user_id, secret_key)
36
+ @auth["user_id"] = user_id
37
+ @auth["secret_key"] = secret_key
38
+ end
39
+
40
+ def rest_host
41
+ @rest_host || "https://api.enrichdata.com"
42
+ end
43
+
44
+ def rest_base_path
45
+ @rest_base_path || "/v1"
46
+ end
47
+
48
+ def timeout
49
+ @timeout || 5
50
+ end
51
+
52
+ def _get(resource, query)
53
+ self._do_get(resource, query, 0, 0)
54
+ end
55
+
56
+ protected
57
+
58
+ def _do_get(resource, query, retry_count, hold_for_seconds)
59
+ # Abort?
60
+ if retry_count > @@created_retry_count_max
61
+ raise RestClient::NotFound
62
+ else
63
+ # Hold.
64
+ sleep hold_for_seconds
65
+
66
+ begin
67
+ response = RestClient::Request.execute(
68
+ :url => self._prepare_rest_url(resource),
69
+ :method => :get,
70
+ :timeout => self.timeout,
71
+
72
+ :user => @auth["user_id"],
73
+ :password => @auth["secret_key"],
74
+
75
+ :headers => {
76
+ :user_agent => "enrich-api-ruby/1.1.3",
77
+ :accept => :json,
78
+ :content_type => :json,
79
+ :params => query
80
+ }
81
+ )
82
+
83
+ status = response.code
84
+ rescue RestClient::NotFound
85
+ status = @@not_found_status_code
86
+ end
87
+
88
+ # Re-schedule request? (created)
89
+ if status == @@created_status_code || (retry_count > 0 &&
90
+ status == @@not_found_status_code)
91
+ if response && response.headers[:retry_after]
92
+ hold_for_seconds = Integer(response.headers[:retry_after])
93
+ end
94
+
95
+ return self._do_get(
96
+ resource, query, retry_count + 1, hold_for_seconds
97
+ )
98
+ end
99
+
100
+ # Not found?
101
+ if status == @@not_found_status_code
102
+ raise RestClient::NotFound
103
+ end
104
+
105
+ return JSON.parse(response)
106
+ end
107
+ end
108
+
109
+ def _prepare_rest_url(resource)
110
+ return self.rest_host + self.rest_base_path + resource
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,24 @@
1
+ ##
2
+ # enrich-api-ruby
3
+ #
4
+ # Copyright 2017, Valerian Saliou
5
+ # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
+ ##
7
+
8
+ require 'rest-client'
9
+
10
+ module Enrich
11
+ class EnrichResource
12
+ def initialize(parent)
13
+ @parent = parent
14
+ end
15
+
16
+ def person(query)
17
+ return @parent._get("/enrich/person", query)
18
+ end
19
+
20
+ def network(query)
21
+ return @parent._get("/enrich/network", query)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ ##
2
+ # enrich-api-ruby
3
+ #
4
+ # Copyright 2017, Valerian Saliou
5
+ # Author: Valerian Saliou <valerian@valeriansaliou.name>
6
+ ##
7
+
8
+ require 'rest-client'
9
+
10
+ module Enrich
11
+ class VerifyResource
12
+ def initialize(parent)
13
+ @parent = parent
14
+ end
15
+
16
+ def validate_email(query)
17
+ return @parent._get("/verify/validate/email", query)
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enrich-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Valerian Saliou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0
27
+ description: Enrich API Ruby
28
+ email: valerian@valeriansaliou.name
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - enrich-api.gemspec
38
+ - examples/enrich_network.rb
39
+ - examples/enrich_person.rb
40
+ - examples/verify_validate_email.rb
41
+ - lib/enrich.rb
42
+ - lib/resources/enrich.rb
43
+ - lib/resources/verify.rb
44
+ homepage: https://enrichdata.com
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.6.11
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Enrich API Ruby
68
+ test_files: []