Skip to content

Commit

Permalink
Add IP Enrichment API (#14)
Browse files Browse the repository at this point in the history
* add ip enrichment

* add more tests

* fix tests
  • Loading branch information
vvillait88 authored Aug 1, 2023
1 parent b944725 commit 7f65444
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ Peopledatalabs::JobTitle.retrieve(job_title: 'data scientist')
Peopledatalabs::Skill.retrieve(skill: 'c++')
```

**Using IP Enrichment API**
```ruby
# Get IP Enrichment
Peopledatalabs::Enrichment.ip(ip: '72.212.42.169')
```

## 🏝 Sandbox Usage <a name="sandbox"></a>
```ruby
# To enable sandbox usage, use the following flag
Expand All @@ -146,6 +152,11 @@ Peopledatalabs.sandbox = true
| [Company Enrichment API](https://docs.peopledatalabs.com/docs/company-enrichment-api) | `Peopledatalabs::Enrichment.company(...params)` |
| [Company Search API](https://docs.peopledatalabs.com/docs/company-search-api) | `Peopledatalabs::Search.company(...params)` |

**IP Endpoints**
| API Endpoint | peopledatalabs Function |
|-|-|
| [IP Enrichment API](https://docs.peopledatalabs.com/docs/ip-enrichment-api) | `Peopledatalabs::Enrichment.ip(...params)` |

**Supporting Endpoints**
| API Endpoint | peopledatalabs Function |
|-|-|
Expand Down
3 changes: 2 additions & 1 deletion lib/peopledatalabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


# gem build peopledatalabs.gemspec
# gem install ./peopledatalabs-2.0.2.gem
# gem install ./peopledatalabs-2.1.0.gem
# irb
# require 'peopledatalabs'
# rake spec PDL_API_KEY=API_KEY
Expand All @@ -41,6 +41,7 @@
# Peopledatalabs::Search.company(searchType: 'elastic', size: 10, query: { query: { bool: { must: [{term: {location_country: 'mexico'}}, {term: {job_title_role: 'health'}}, {exists: {field: 'phone_numbers'}}]}}})
# Peopledatalabs::JobTitle.retrieve(job_title: 'data scientist')
# Peopledatalabs::Skill.retrieve(skill: 'c++')
# Peopledatalabs::Enrichment.ip(ip: '72.212.42.169')

module Peopledatalabs
class Error < StandardError; end
Expand Down
5 changes: 5 additions & 0 deletions lib/peopledatalabs/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def self.check(params:, path:)
if (!field)
result = { 'status' => 400, 'message' => 'Missing skill' }
end
elsif path.include? '/ip'
field = params['ip']
if (!field)
result = { 'status' => 400, 'message' => 'Missing ip' }
end
end
result
end
Expand Down
14 changes: 14 additions & 0 deletions lib/peopledatalabs/resources/enrichment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,19 @@ def self.company(params:)
get(path: '/v5/company/enrich', headers: headers, params: params)
end

def self.ip(ip:, return_ip_location: false, return_ip_metadata: false, return_person: false)
params = {
'ip' => ip,
'return_ip_location' => return_ip_location,
'return_ip_metadata' => return_ip_metadata,
'return_person' => return_person,
}
headers = {
'Accept-Encoding' => 'gzip',
'User-Agent' => 'PDL-RUBY-SDK',
}
get(path: '/v5/ip/enrich', headers: headers, params: params)
end

end
end
2 changes: 1 addition & 1 deletion lib/peopledatalabs/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Peopledatalabs
VERSION = "2.0.2"
VERSION = "2.1.0"
end
36 changes: 36 additions & 0 deletions spec/peopledatalabs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,42 @@
end
end

describe 'ip' do
it "should return ip record" do
result = Peopledatalabs::Enrichment.ip(ip: '72.212.42.169')
expect(result['status']).to eq(200)
expect(result).to be_an_instance_of(Hash)
expect(result['data']['company']).to be_an_instance_of(Hash)
end

it "should return ip record with location" do
result = Peopledatalabs::Enrichment.ip(ip: '72.212.42.169', return_ip_location: true)
expect(result['status']).to eq(200)
expect(result).to be_an_instance_of(Hash)
expect(result['data']['ip']['location']).to be_an_instance_of(Hash)
end

it "should return ip record with metadata" do
result = Peopledatalabs::Enrichment.ip(ip: '72.212.42.169', return_ip_metadata: true)
expect(result['status']).to eq(200)
expect(result).to be_an_instance_of(Hash)
expect(result['data']['ip']['location']).to be_an_instance_of(Hash)
end

it "should return ip record with person" do
result = Peopledatalabs::Enrichment.ip(ip: '72.212.42.169', return_person: true)
expect(result['status']).to eq(200)
expect(result).to be_an_instance_of(Hash)
expect(result['data']['person']).to be_an_instance_of(Hash)
end

it "should error" do
result = Peopledatalabs::Enrichment.ip(ip: nil)
expect(result['status']).to eq(400)
expect(result).to be_an_instance_of(Hash)
end
end

describe 'cleaner apis' do
it "it should return company cleaner records" do
result = Peopledatalabs::Cleaner.company(kind: 'name', value: 'peopledatalabs')
Expand Down

0 comments on commit 7f65444

Please sign in to comment.