diff --git a/README.md b/README.md index aab2e29..d33989b 100644 --- a/README.md +++ b/README.md @@ -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 ```ruby # To enable sandbox usage, use the following flag @@ -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 | |-|-| diff --git a/lib/peopledatalabs.rb b/lib/peopledatalabs.rb index c2b1526..d199399 100644 --- a/lib/peopledatalabs.rb +++ b/lib/peopledatalabs.rb @@ -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 @@ -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 diff --git a/lib/peopledatalabs/api_resource.rb b/lib/peopledatalabs/api_resource.rb index c33053a..294fe99 100644 --- a/lib/peopledatalabs/api_resource.rb +++ b/lib/peopledatalabs/api_resource.rb @@ -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 diff --git a/lib/peopledatalabs/resources/enrichment.rb b/lib/peopledatalabs/resources/enrichment.rb index 4fc1f00..36e5e74 100644 --- a/lib/peopledatalabs/resources/enrichment.rb +++ b/lib/peopledatalabs/resources/enrichment.rb @@ -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 diff --git a/lib/peopledatalabs/version.rb b/lib/peopledatalabs/version.rb index e3c1a5e..9f1df01 100644 --- a/lib/peopledatalabs/version.rb +++ b/lib/peopledatalabs/version.rb @@ -1,3 +1,3 @@ module Peopledatalabs - VERSION = "2.0.2" + VERSION = "2.1.0" end diff --git a/spec/peopledatalabs_spec.rb b/spec/peopledatalabs_spec.rb index 7573089..779a93f 100644 --- a/spec/peopledatalabs_spec.rb +++ b/spec/peopledatalabs_spec.rb @@ -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')