Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 7f4b425

Browse files
initial implementation
1 parent 0a88932 commit 7f4b425

File tree

11 files changed

+4945
-1
lines changed

11 files changed

+4945
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
.idea
107+
.vscode

README.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,83 @@
1-
# emsi-skills-api-wrapper
1+
# emsi-skills-api-wrapper
2+
Wrapper library for EMSI skills API: https://api.lightcast.io/apis/skills#overview
3+
4+
This EMSI API wrapper exposes the following functions to interact with EMSI api:
5+
1. getApiToken() - Generate a jwt token to use with subsequent EMSI API calls
6+
2. getSkillById(skillId, token) - Get the EMSI skill details by emsi skill id
7+
3. extractSkillsFromText(text, token) - Extract the EMSI skills from the given text
8+
4. getRelatedSkills(skillIds, token) - Get the skills related to given skills ids
9+
5. searchSkills(criteria, token) - Get all EMSI skills matching the given criteria, the search criteria is an
10+
object which has the same fields as the url parameters of the GET /skills endpoint
11+
see query parameters names at https://api.lightcast.io/apis/skills#get-list-all-skills
12+
13+
Sample criteria object for searching for skills is:
14+
```javascript
15+
const criteria = {
16+
q: 'Java',
17+
typeIds: 'ST1,ST2',
18+
fields: 'id,name',
19+
limit:5
20+
}
21+
```
22+
23+
# Configuration:
24+
The configuration of the application using this library should have the following structure:
25+
26+
```bash
27+
EMSI_SKILLS_API: {
28+
AUTH_URL: process.env.EMSI_AUTH_URL || 'https://auth.emsicloud.com/connect/token',
29+
BASE_URL: process.env.EMSI_SKILLS_BASE_URL || 'https://emsiservices.com/skills',
30+
CLIENT_ID: process.env.EMSI_SKILLS_API_CLIENT_ID,
31+
CLIENT_SECRET: process.env.EMSI_SKILLS_API_CLIENT_SECRET,
32+
GRANT_TYPE: process.env.EMSI_AUTH_GRANT_TYPE || 'client_credentials',
33+
SCOPE: process.env.EMSI_AUTH_SCOPE || 'emsi_open',
34+
VERSION: process.env.EMSI_SKILLS_API_VERSION || 'latest',
35+
SKILLS_EXTRACTION_CONFIDENCE_THRESHOLD: process.env.EMSI_SKILLS_EXTRACTION_CONFIDENCE_THRESHOLD || '0.6',
36+
MAXIMUM_RELATED_SKILLS_TO_RETRIEVE_PER_REQUEST: process.env.MAXIMUM_RELATED_SKILLS_TO_RETRIEVE_PER_REQUEST || 5
37+
}
38+
```
39+
40+
The above configuration parameters can be used for accessing the EMSI API, only need to additionally set the following parameters in the application environment
41+
```bash
42+
export EMSI_SKILLS_API_CLIENT_ID=<client_id>
43+
export EMSI_SKILLS_API_CLIENT_SECRET=<client_secret>
44+
```
45+
46+
# Usage:
47+
1. In order to use this wrapper, it needs to be included in the application `package.json`
48+
```
49+
"emsi-api-wrapper": "topcoder-platform/emsi-api-wrapper.git#develop"
50+
```
51+
52+
2. Create an instance of the wrapper:
53+
```javascript
54+
const emsiApiWrapper = require('emsi-api-wrapper')
55+
const config = require('config')
56+
const client = emsiApiWrapper(config);
57+
```
58+
59+
3. Call the wrapper functions:
60+
```javascript
61+
const token = await client.getApiToken()
62+
const text = 'Java Backend API'
63+
64+
const emsiSkills = await client.extractSkillsFromText(text, token)
65+
66+
for(const emsiSkill of emsiSkills) {
67+
console.log(`Get the skill details, skillId = ${emsiSkill.skillId} `)
68+
const details = await client.getSkillById(emsiSkill.skillId, token)
69+
console.log(`Skill details = ${JSON.stringify(details, null, 2)}`)
70+
}
71+
72+
console.log('Search all skills with Javascript name, limited to 5 skills')
73+
const searchCriteria = {
74+
q: 'Javascript',
75+
limit: 5
76+
}
77+
78+
const searchSkillsResult = await client.searchSkills(searchCriteria, token)
79+
console.log(`The searched skills are = ${JSON.stringify(searchSkillsResult, null, 2)}`)
80+
```
81+
82+
83+
A sample application which shows how to use the wrapper is provided at [sample-app](./docs/sample-app)

docs/sample-app/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1. Set environment variables:
2+
```bash
3+
export EMSI_SKILLS_API_CLIENT_ID=<client_id>
4+
export EMSI_SKILLS_API_CLIENT_SECRET=<client_secret>
5+
export EMSI_AUTH_GRANT_TYPE=client_credentials
6+
export EMSI_AUTH_SCOPE=emsi_open
7+
export EMSI_SKILLS_API_VERSION=latest
8+
export EMSI_SKILLS_EXTRACTION_CONFIDENCE_THRESHOLD=0.6
9+
```
10+
11+
2. Run the application from the command line `node sample-app.js`

docs/sample-app/config/default.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* The application configuration file
3+
*/
4+
5+
module.exports = {
6+
EMSI_SKILLS_API: {
7+
AUTH_URL: process.env.EMSI_AUTH_URL || 'https://auth.emsicloud.com/connect/token',
8+
BASE_URL: process.env.EMSI_SKILLS_BASE_URL || 'https://emsiservices.com/skills',
9+
CLIENT_ID: process.env.EMSI_SKILLS_API_CLIENT_ID,
10+
CLIENT_SECRET: process.env.EMSI_SKILLS_API_CLIENT_SECRET,
11+
GRANT_TYPE: process.env.EMSI_AUTH_GRANT_TYPE || 'client_credentials',
12+
SCOPE: process.env.EMSI_AUTH_SCOPE || 'emsi_open',
13+
VERSION: process.env.EMSI_SKILLS_API_VERSION || 'latest',
14+
SKILLS_EXTRACTION_CONFIDENCE_THRESHOLD: process.env.EMSI_SKILLS_EXTRACTION_CONFIDENCE_THRESHOLD || '0.6',
15+
MAXIMUM_RELATED_SKILLS_TO_RETRIEVE_PER_REQUEST: process.env.MAXIMUM_RELATED_SKILLS_TO_RETRIEVE_PER_REQUEST || 5
16+
}
17+
}

docs/sample-app/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "sample-app",
3+
"version": "1.0.0",
4+
"description": "Sample application to demonstrate the usage of the EMSI api wrapper",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Jaouad Jaghrir",
10+
"license": "ISC",
11+
"dependencies": {
12+
"config": "^3.3.8",
13+
"emsi-api-wrapper": "topcoder-platform/emsi-api-wrapper.git#develop",
14+
"lodash": "^4.17.21"
15+
}
16+
}

docs/sample-app/sample-app.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const emsiApiWrapper = require('emsi-api-wrapper')
2+
const config = require('config')
3+
4+
const client = emsiApiWrapper(config);
5+
(async () => {
6+
// Get API token
7+
const token = await client.getApiToken()
8+
9+
const text = 'Java Backend API'
10+
11+
console.log(`Extract skills from text '${text}'`)
12+
const emsiSkills = await client.extractSkillsFromText(text, token)
13+
console.log(`Extracted skills = ${JSON.stringify(emsiSkills, null, 2)}`)
14+
15+
for (const emsiSkill of emsiSkills) {
16+
console.log(`Get the skill details, skillId = ${emsiSkill.skillId} `)
17+
const details = await client.getSkillById(emsiSkill.skillId, token)
18+
console.log(`Skill details = ${JSON.stringify(details, null, 2)}`)
19+
}
20+
21+
console.log('Search all skills with Javascript name, limited to 5 skills')
22+
const searchCriteria = {
23+
q: 'Javascript',
24+
limit: 5
25+
}
26+
27+
const searchSkillsResult = await client.searchSkills(searchCriteria, token)
28+
console.log(`The searched skills are = ${JSON.stringify(searchSkillsResult, null, 2)}`)
29+
})()

index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = (config) => {
2+
// export functions
3+
return {
4+
getApiToken: () => {
5+
return require('./src/services/AuthService').getApiToken(config)
6+
},
7+
getSkillById: (skillId, token) => {
8+
return require('./src/services/EmsiSkillService').getSkillById(config, skillId, token)
9+
},
10+
searchSkills: (criteria, token) => {
11+
return require('./src/services/EmsiSkillService').searchSkills(config, criteria, token)
12+
},
13+
extractSkillsFromText: (text, token) => {
14+
return require('./src/services/EmsiSkillService').extractSkillsFromText(config, text, token)
15+
},
16+
getRelatedSkills: (skillIds, token) => {
17+
return require('./src/services/EmsiSkillService').getRelatedSkills(config, skillIds, token)
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)