Skip to content

Commit

Permalink
Add skill, job_title and sandbox endpoints support (#7)
Browse files Browse the repository at this point in the history
* add new endpoints

* update readme

* fix readme comment

* feat(Sandbox): allow to hit sandbox urls

* add tests

* add sandbox flag to readme

* sandbox emoji

* switch from people to person

* add breaking change to readme

* emoji for upgrade

* new line

Co-authored-by: james <[email protected]>
  • Loading branch information
vvillait88 and jamesbaez authored Aug 13, 2022
1 parent 4911cdd commit 8fa5547
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/test/version_tmp/
/tmp/
/.idea
.env


# Used by dotenv library to load environment variables.
Expand Down
47 changes: 39 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ This library bundles up PDL API requests into simple function calls, making it e
## Table of Contents
- [🔧 Installation](#installation)
- [🚀 Usage](#usage)
- [🏝 Sandbox Usage](#sandbox)
- [🌐 Endpoints](#endpoints)
- [📘 Documentation](#documentation)
- [⚠️ Upgrading from v1.X.X to v2.0.0](#upgrading)

## Installation <a name="installation"></a>

Expand Down Expand Up @@ -58,19 +60,19 @@ Peopledatalabs.api_key = 'api_key'

Then, send requests to any PDL API Endpoint:

**Getting Person Data**
**Using Person APIs**
```ruby
# By Enrichment
Peopledatalabs::Enrichment.person(params: { phone: '4155688415' })

# By Bulk Enrichment
Peopledatalabs::Bulk.people(params: {requests: [{params: {profile: ['linkedin.com/in/seanthorne']}}, {params: {profile: ['linkedin.com/in/randrewn']}}]})
Peopledatalabs::Bulk.person(params: {requests: [{params: {profile: ['linkedin.com/in/seanthorne']}}, {params: {profile: ['linkedin.com/in/randrewn']}}]})

# By Search (SQL)
Peopledatalabs::Search.people(searchType: 'sql', query: "SELECT * FROM person WHERE job_company_name='people data labs'")
Peopledatalabs::Search.person(searchType: 'sql', query: "SELECT * FROM person WHERE job_company_name='people data labs'")

# By Search (Elasticsearch)
Peopledatalabs::Search.people(searchType: 'elastic', query: {"query": {"term": {"job_company_name": "people data labs"}}})
Peopledatalabs::Search.person(searchType: 'elastic', query: {"query": {"term": {"job_company_name": "people data labs"}}})

# By PDL_ID
Peopledatalabs::Retrieve.person(person_id: 'qEnOZ5Oh0poWnQ1luFBfVw_0000')
Expand All @@ -79,7 +81,7 @@ Peopledatalabs::Retrieve.person(person_id: 'qEnOZ5Oh0poWnQ1luFBfVw_0000')
Peopledatalabs::Identify.person(params: { name: 'sean thorne' })
```

**Getting Company Data**
**Using Company APIs**
```ruby
# By Enrichment
Peopledatalabs::Enrichment.company(params: { website: 'peopledatalabs.com' })
Expand All @@ -91,11 +93,14 @@ Peopledatalabs::Search.company(searchType: 'sql', query: "SELECT * FROM company
Peopledatalabs::Search.company(searchType: 'elastic', query: {"query": "must": [{"term": {"tags": "big data"}}, {"term": {"industry": "financial services"}}, {"term": {"location_country": "united states"}}]})
```

**Using Supporting APIs**
**Using Autocomplete API**
```ruby
# Get Autocomplete Suggestions
Peopledatalabs::Autocomplete.retrieve(field: 'title', text: 'full', size: 10)
```

**Using Cleaner APIs**
```ruby
# Clean Raw Company Strings
Peopledatalabs::Cleaner.company(kind: 'name', value: 'peOple DaTa LabS')

Expand All @@ -106,13 +111,31 @@ Peopledatalabs::Cleaner.location(value: '455 Market Street, San Francisco, Calif
Peopledatalabs::Cleaner.school(kind: 'name', value: 'university of oregon')
```

**Using Job Title Enrichment API**
```ruby
# Get Job Title Enrichment
Peopledatalabs::JobTitle.retrieve(job_title: 'data scientist')
```

**Using Skill Enrichment API**
```ruby
# Get Skill Enrichment
Peopledatalabs::Skill.retrieve(skill: 'c++')
```

## 🏝 Sandbox Usage <a name="sandbox"></a>
```ruby
# To enable sandbox usage, use the following flag
Peopledatalabs.sandbox = true
```

## 🌐 Endpoints <a name="endpoints"></a>

**Person Endpoints**
| API Endpoint | peopledatalabs Function |
|-|-|
| [Person Enrichment API](https://docs.peopledatalabs.com/docs/enrichment-api) | `Peopledatalabs::Enrichment.person(...params)` |
| [Person Bulk Person Enrichment API](https://docs.peopledatalabs.com/docs/bulk-enrichment-api) | `Peopledatalabs::Bulk.people(...records)` |
| [Person Bulk Person Enrichment API](https://docs.peopledatalabs.com/docs/bulk-enrichment-api) | `Peopledatalabs::Bulk.person(...records)` |
| [Person Search API](https://docs.peopledatalabs.com/docs/search-api) | `Peopledatalabs::Search.person(...params)` |
| [Person Retrieve API](https://docs.peopledatalabs.com/docs/person-retrieve-api) | `Peopledatalabs::Autocomplete.retrieve(...params)` |
| [Person Identify API](https://docs.peopledatalabs.com/docs/identify-api) | `Peopledatalabs::Identify.person(...params)` |
Expand All @@ -130,7 +153,8 @@ Peopledatalabs::Cleaner.school(kind: 'name', value: 'university of oregon')
| [Company Cleaner API](https://docs.peopledatalabs.com/docs/cleaner-apis#companyclean) | `Peopledatalabs::Cleaner.company(...params)` |
| [Location Cleaner API](https://docs.peopledatalabs.com/docs/cleaner-apis#locationclean) | `Peopledatalabs::Cleaner.location(...params)` |
| [School Cleaner API](https://docs.peopledatalabs.com/docs/cleaner-apis#schoolclean) | `Peopledatalabs::Cleaner.school(...params)` |

| [Job Title Enrichment API](https://docs.peopledatalabs.com/docs/job-title-enrichment-api) | `Peopledatalabs::JobTitle.retrieve(...params)` |
| [Skill Enrichment API](https://docs.peopledatalabs.com/docs/skill-enrichment-api) | `Peopledatalabs::Skill.retrieve(...params)` |

## 📘 Documentation <a name="documentation"></a>

Expand All @@ -151,3 +175,10 @@ Conversely, this would be **invalid** because `fake_parameter` is not an input p
```ruby
Peopledatalabs::Identify.person(params: { fake_parameter: 'anything' })
```

## ⚠️ Upgrading from v1.X.X to v2.0.0 <a name="upgrading"></a>

Bulk Person and Person Search now use .person instead of .people

i.e. Peopledatalabs::Bulk.people(...records) is now Peopledatalabs::Bulk.person(...records)
<br />i.e. Peopledatalabs::Search.people(...params) is now Peopledatalabs::Search.person(...params)
17 changes: 12 additions & 5 deletions lib/peopledatalabs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,37 @@
require 'peopledatalabs/resources/identify'
require 'peopledatalabs/resources/retrieve'
require 'peopledatalabs/resources/bulk'
require 'peopledatalabs/resources/jobtitle'
require 'peopledatalabs/resources/skill'


# gem build peopledatalabs.gemspec
# gem install ./peopledatalabs-1.0.4.gem
# gem install ./peopledatalabs-2.0.0.gem
# irb
# require 'peopledatalabs'
# rake spec PDL_API_KEY=API_KEY

# Usage
# First set api key
# Peopledatalabs.api_key = 'api_key'
# # Can set sandbox to true. Defaults to false
# # Peopledatalabs.sandbox = false
# Examples Calls:
# Peopledatalabs::Cleaner.company(kind: 'website', value: 'peopledatalabs.com')
# Peopledatalabs::Cleaner.school(kind: 'profile', value: 'linkedin.com/school/ucla')
# Peopledatalabs::Cleaner.location(value: '239 NW 13th Ave, Portland, Oregon 97209, US')
# Peopledatalabs::Search.people(searchType: 'elastic', query: {"query": {"term": {"job_company_name": "people data labs"}}})
# Peopledatalabs::Search.people(searchType: 'sql', query: "SELECT * FROM person WHERE job_company_name='people data labs'")
# Peopledatalabs::Search.person(searchType: 'elastic', query: {"query": {"term": {"job_company_name": "people data labs"}}})
# Peopledatalabs::Search.person(searchType: 'sql', query: "SELECT * FROM person WHERE job_company_name='people data labs'")
# Peopledatalabs::Autocomplete.retrieve(field: 'school', text: 'university of michigan')
# Peopledatalabs::Enrichment.person(params: { name: 'Jennifer C. Jackson', locality: 'Boise' })
# Peopledatalabs::Bulk.people(params: {requests: [{params: {profile: ['linkedin.com/in/seanthorne']}}, {params: {profile: ['linkedin.com/in/randrewn']}}]})
# Peopledatalabs::Bulk.person(params: {requests: [{params: {profile: ['linkedin.com/in/seanthorne']}}, {params: {profile: ['linkedin.com/in/randrewn']}}]})
# Peopledatalabs::Enrichment.company(params: { name: 'Google, Inc.', ticker: 'GOOGL'})
# Peopledatalabs::Identify.person(params: { name: 'Jennifer C. Jackson', location: 'Medford, OR USA' })
# Peopledatalabs::Retrieve.person(person_id: 'qEnOZ5Oh0poWnQ1luFBfVw_0000')
# Peopledatalabs::Search.company(searchType: 'sql', size: 10, query: "SELECT * FROM company WHERE tags='big data' AND industry='financial services' AND location.country='united states';")
# 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++')

module Peopledatalabs
class Error < StandardError; end
Expand All @@ -47,8 +53,9 @@ class << self
attr_reader :config

def_delegators :@config, :api_key, :api_key=
def_delegators :@config, :api_base, :api_base=
def_delegators :@config, :sandbox, :sandbox=
def_delegators :@config, :read_timeout, :read_timeout=
def_delegators :@config, :api_base
end
end

Expand Down
10 changes: 10 additions & 0 deletions lib/peopledatalabs/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ def self.check(params:, path:)
elsif (!VALID_AUTOCOMPLETE_FIELDS.include?(field))
result = { 'status' => 400, 'message' => "Field should be one of: #{VALID_AUTOCOMPLETE_FIELDS.join(', ')}" }
end
elsif path.include? '/job_title'
field = params['job_title']
if (!field)
result = { 'status' => 400, 'message' => 'Missing job_title' }
end
elsif path.include? '/skill'
field = params['skill']
if (!field)
result = { 'status' => 400, 'message' => 'Missing skill' }
end
end
result
end
Expand Down
7 changes: 5 additions & 2 deletions lib/peopledatalabs/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Peopledatalabs
class Configuration
attr_accessor :api_key
attr_accessor :api_base
attr_accessor :sandbox
attr_accessor :read_timeout

def self.setup
Expand All @@ -13,10 +13,13 @@ def self.setup
end

def initialize
@api_base = "https://api.peopledatalabs.com"
@read_timeout = 10
@api_key ||= ENV['PDL_API_KEY']
@sanbox = false
end

def api_base
sandbox ? 'https://sandbox.api.peopledatalabs.com' : 'https://api.peopledatalabs.com'
end
end
end
2 changes: 1 addition & 1 deletion lib/peopledatalabs/resources/bulk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Peopledatalabs
class Bulk < APIResource
def self.people(params:)
def self.person(params:)
headers = {
'Accept-Encoding' => 'gzip',
'User-Agent' => 'PDL-RUBY-SDK',
Expand Down
20 changes: 20 additions & 0 deletions lib/peopledatalabs/resources/jobtitle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Peopledatalabs
class JobTitle < APIResource
def self.retrieve(job_title:, pretty: false)

params = {
'job_title' => job_title,
'pretty' => pretty,
};

headers = {
'Accept-Encoding' => 'gzip',
'User-Agent' => 'PDL-RUBY-SDK',
}
get(path: '/v5/job_title/enrich', headers: headers, params: params)
end
end
end

2 changes: 1 addition & 1 deletion lib/peopledatalabs/resources/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Peopledatalabs
class Search < APIResource
def self.people(searchType:, query: , titlecase: false, dataset: 'all', size: 10, pretty: false, scroll_token: nil)
def self.person(searchType:, query: , titlecase: false, dataset: 'all', size: 10, pretty: false, scroll_token: nil)
search(searchType: searchType,
query: query,
titlecase: titlecase,
Expand Down
20 changes: 20 additions & 0 deletions lib/peopledatalabs/resources/skill.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Peopledatalabs
class Skill < APIResource
def self.retrieve(skill:, pretty: false)

params = {
'skill' => skill,
'pretty' => pretty,
};

headers = {
'Accept-Encoding' => 'gzip',
'User-Agent' => 'PDL-RUBY-SDK',
}
get(path: '/v5/skill/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 = "1.0.4"
VERSION = "2.0.0"
end
Loading

0 comments on commit 8fa5547

Please sign in to comment.